diff --git a/src/EditorFeatures/Test/EditorServicesTest.csproj b/src/EditorFeatures/Test/EditorServicesTest.csproj index 6152d08e9ed37..cb9d2bc1cd951 100644 --- a/src/EditorFeatures/Test/EditorServicesTest.csproj +++ b/src/EditorFeatures/Test/EditorServicesTest.csproj @@ -242,6 +242,7 @@ + diff --git a/src/EditorFeatures/Test/Extensions/SourceTextContainerExtensionsTests.cs b/src/EditorFeatures/Test/Extensions/SourceTextContainerExtensionsTests.cs new file mode 100644 index 0000000000000..c15d34d83d079 --- /dev/null +++ b/src/EditorFeatures/Test/Extensions/SourceTextContainerExtensionsTests.cs @@ -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(); + Assert.Throws(() => Microsoft.CodeAnalysis.Text.Extensions.GetTextBuffer(containerMock.Object)); + } + + [Fact] + public void GetBufferTextFromTextContainerDoesNotThrow() + { + var textSnapshotMock = new Mock(); + var bufferMock = new Mock(); + 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)); + } + } +} diff --git a/src/EditorFeatures/Text/Extensions.cs b/src/EditorFeatures/Text/Extensions.cs index 6de7380cfb3ba..91b0b038bf9e8 100644 --- a/src/EditorFeatures/Text/Extensions.cs +++ b/src/EditorFeatures/Text/Extensions.cs @@ -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)); } return textBuffer; diff --git a/src/EditorFeatures/Text/TextEditorResources.Designer.cs b/src/EditorFeatures/Text/TextEditorResources.Designer.cs index d4e95957d2146..dcd1d20ebc1f0 100644 --- a/src/EditorFeatures/Text/TextEditorResources.Designer.cs +++ b/src/EditorFeatures/Text/TextEditorResources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18210 +// Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -61,20 +61,11 @@ internal TextEditorResources() { } /// - /// Looks up a localized string similar to textContainer is not an SourceTextContainer that was created from an ITextBuffer.. + /// Looks up a localized string similar to textContainer is not a SourceTextContainer that was created from an ITextBuffer.. /// - internal static string TextcontainerIsNotAnSource { + internal static string TextContainerNotFromTextBuffer { get { - return ResourceManager.GetString("TextcontainerIsNotAnSource", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to text is not an SourceText that was created from an ITextSnapshot.. - /// - internal static string TextIsNotAnSourcetextThat { - get { - return ResourceManager.GetString("TextIsNotAnSourcetextThat", resourceCulture); + return ResourceManager.GetString("TextContainerNotFromTextBuffer", resourceCulture); } } } diff --git a/src/EditorFeatures/Text/TextEditorResources.resx b/src/EditorFeatures/Text/TextEditorResources.resx index f82e3eee34ead..4fc852044cc74 100644 --- a/src/EditorFeatures/Text/TextEditorResources.resx +++ b/src/EditorFeatures/Text/TextEditorResources.resx @@ -117,10 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - textContainer is not an SourceTextContainer that was created from an ITextBuffer. - - - text is not an SourceText that was created from an ITextSnapshot. + + textContainer is not a SourceTextContainer that was created from an ITextBuffer. \ No newline at end of file