Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/EditorFeatures/Test/EditorServicesTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<Compile Include="Diagnostics\GenerateType\TestProjectManagementService.cs" />
<Compile Include="Diagnostics\SuppressMessageAttributeTests.cs" />
<Compile Include="CodeFixes\ExtensionOrderingTests.cs" />
<Compile Include="Extensions\SourceTextContainerExtensionsTests.cs" />
<Compile Include="Preview\TestOnly_CompilerDiagnosticAnalyzerProviderService.cs" />
<Compile Include="DocCommentFormatting\DocCommentFormattingTests.cs" />
<Compile Include="DocumentationComments\AbstractDocumentationCommentTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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>(() => Microsoft.CodeAnalysis.Text.Extensions.GetTextBuffer(containerMock.Object));
}

[Fact]
public void GetBufferTextFromTextContainerDoesNotThrow()
{
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);

Assert.DoesNotThrow(()=> Microsoft.CodeAnalysis.Text.Extensions.GetTextBuffer(textContainer));
}
}
}
2 changes: 1 addition & 1 deletion src/EditorFeatures/Text/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, nameof(textContainer));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch this to use nameof while you're already in there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do


return textBuffer;
Expand Down
17 changes: 4 additions & 13 deletions src/EditorFeatures/Text/TextEditorResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/EditorFeatures/Text/TextEditorResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TextcontainerIsNotAnSource" xml:space="preserve">
<value>textContainer is not an SourceTextContainer that was created from an ITextBuffer.</value>
</data>
<data name="TextIsNotAnSourcetextThat" xml:space="preserve">
<value>text is not an SourceText that was created from an ITextSnapshot.</value>
<data name="TextContainerNotFromTextBuffer" xml:space="preserve">
<value>textContainer is not a SourceTextContainer that was created from an ITextBuffer.</value>
</data>
</root>