Repository navigation
Fixes Grammar in SourceTextContainer exception message #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d15260d
3138765
e095caa
82fd617
9a974fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using Microsoft.CodeAnalysis.Text; | ||
| using Moq; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.UnitTests.Extensions | ||
| { | ||
| public class SourceTextContainerExtensionsTests | ||
| { | ||
| [Fact] | ||
| public void GetBufferTextFromNonTextContainerThrows() | ||
| { | ||
| var containerMock = new Mock<SourceTextContainer>(); | ||
| Assert.Throws<ArgumentException>(containerMock.Object.GetTextBuffer); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetBufferTextFromTextContainerReturnsTextBuffer() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this actually testing? Is it trying to test that the creation of the text buffer container does not mutate the text buffer, or just that the GetTextBuffer method works at all?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had set out to test that the GetTextBuffer method works and returns the buffer that was supplied to the TextBufferContainer. I suppose that although at present the text buffer container does not mutate the buffer it may be a valid scenario for a future revision or even for a derived type. In which case, I will alter the test to assert only that GetTextBuffer does not throw. |
||
| { | ||
| var textSnapshotMock = new Mock<VisualStudio.Text.ITextSnapshot>(); | ||
| var bufferMock = new Mock<VisualStudio.Text.ITextBuffer>(); | ||
| bufferMock.SetupGet(x => x.CurrentSnapshot).Returns(textSnapshotMock.Object); | ||
| bufferMock.SetupGet(x => x.Properties).Returns(new VisualStudio.Utilities.PropertyCollection()); | ||
|
|
||
| var textContainer = Microsoft.CodeAnalysis.Text.Extensions.TextBufferContainer.From(bufferMock.Object); | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a StyleCop violation to have two blank lines in a row. StyleCop must not be running on this file given that the build passed, right? Either way, please remove the blank line. |
||
| var textBuffer = textContainer.GetTextBuffer(); | ||
|
|
||
| Assert.Equal(bufferMock.Object, textBuffer); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ public static ITextBuffer GetTextBuffer(this SourceTextContainer textContainer) | |
| var textBuffer = TryGetTextBuffer(textContainer); | ||
| if (textBuffer == null) | ||
| { | ||
| throw new ArgumentException(TextEditorResources.TextcontainerIsNotAnSource, "textContainer"); | ||
| throw new ArgumentException(TextEditorResources.TextContainerNotFromTextBuffer, "textContainer"); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you switch this to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
|
|
||
| return textBuffer; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just testing the behavior of the mocking framework?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention was to test that the GetTextBuffer extension method threw an argument exception when provided with a SourceTextContainer that was not a TextBufferContainer or derived type. Would it have been better to have written it as
Assert.Throws<ArgumentException>(() => Microsoft.CodeAnalysis.Text.Extensions.GetTextBuffer(containerMock.Object));Or something similar?
I did also look at asserting on the ArgumentException message to make sure that the update resource text was returned however as this also returns the parameter name as part of the message I wasn't confident that this wouldn't make the test too brittle because someone could easily break the test just by changing the parameter name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, both @rchande and I were tricked by the extension method, so switching to the more obvious invocation would probably prevent others from being confused as well.