提交 73bbd9d5 编写于 作者: B Brett Forsgren

update Roslyn.Services.Editor.UnitTests.dll to use localized resources

上级 4b77f764
using System.Resources;
namespace Microsoft.CodeAnalysis
{
// This class exists as a way to load resources from the Microsoft.CodeAnalysis.CodeAnalysisResources class from
// the Microsoft.CodeAnalysis assembly. Microsoft.CodeAnalysis.CodeAnalysisResources is internal but we can't add
// InternalsVisibleTo(this-assembly) because there are numerous shared (linked) files common to both
// Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.Workspaces and that gives us major issues with duplicate
// internal types that suddenly become visible (e.g., SpecializedCollections) and that leads down a rabbit hole
// of requiring assembly aliasing that would make many tests in this project unreadable. The descision was made to
// manually load the few resources we need from the CodeAnalysis assembly at the cost of Find All References and
// Rename not working as expected.
internal static class CodeAnalysisResources
{
public static string InMemoryAssembly => GetString("InMemoryAssembly");
private static ResourceManager _codeAnalysisResourceManager;
private static string GetString(string resourceName)
{
if (_codeAnalysisResourceManager == null)
{
_codeAnalysisResourceManager = new ResourceManager("Microsoft.CodeAnalysis.CodeAnalysisResources", typeof(Compilation).Assembly);
}
return _codeAnalysisResourceManager.GetString(resourceName);
}
}
}
......@@ -211,6 +211,7 @@
<Compile Include="Classification\ClassificationTestHelper.cs" />
<Compile Include="CodeActions\AbstractCodeActionTest.cs" />
<Compile Include="CodeActions\CodeActionSmartTagProducerTests.cs" />
<Compile Include="CodeAnalysisResources.cs" />
<Compile Include="CodeFixes\CodeFixServiceTests.cs" />
<Compile Include="CodeGeneration\AbstractCodeGenerationTests.cs" />
<Compile Include="CodeGeneration\CodeGenerationTests.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.DocumentationCommentFormatting;
using Microsoft.CodeAnalysis.DocumentationCommentFormatting;
using Microsoft.CodeAnalysis.MetadataAsSource;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic.DocumentationCommentFormatting;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -39,7 +36,7 @@ public void Summary()
var comment = "<summary>This is a summary.</summary>";
var expected =
@"Summary:
$@"{FeaturesResources.Summary}
This is a summary.";
TestFormat(comment, expected);
......@@ -51,7 +48,7 @@ public void Wrapping1()
var comment = "<summary>I am the very model of a modern major general. This is a very long comment. And getting longer by the minute.</summary>";
var expected =
@"Summary:
$@"{FeaturesResources.Summary}
I am the very model of a modern major general. This is a very long comment. And
getting longer by the minute.";
......@@ -63,7 +60,7 @@ public void Wrapping2()
{
var comment = "<summary>I amtheverymodelofamodernmajorgeneral.Thisisaverylongcomment.Andgettinglongerbythe minute.</summary>";
var expected =
@"Summary:
$@"{FeaturesResources.Summary}
I amtheverymodelofamodernmajorgeneral.Thisisaverylongcomment.Andgettinglongerbythe
minute.";
......@@ -76,7 +73,7 @@ public void Exception()
var comment = @"<exception cref=""T:System.NotImplementedException"">throws NotImplementedException</exception>";
var expected =
@"Exceptions:
$@"{FeaturesResources.Exceptions}
T:System.NotImplementedException:
throws NotImplementedException";
......@@ -92,7 +89,7 @@ public void MultipleExceptionTags()
<exception cref=""T:System.InvalidOperationException"">throws InvalidOperationException</exception>";
var expected =
@"Exceptions:
$@"{FeaturesResources.Exceptions}
T:System.NotImplementedException:
throws NotImplementedException
......@@ -112,7 +109,7 @@ public void MultipleExceptionTagsWithSameType()
<exception cref=""T:System.NotImplementedException"">also throws NotImplementedException for reason Y</exception>";
var expected =
@"Exceptions:
$@"{FeaturesResources.Exceptions}
T:System.NotImplementedException:
throws NotImplementedException for reason X
......@@ -131,7 +128,7 @@ public void Returns()
var comment = @"<returns>A string is returned</returns>";
var expected =
@"Returns:
$@"{FeaturesResources.Returns}
A string is returned";
TestFormat(comment, expected);
......@@ -146,10 +143,10 @@ public void SummaryAndParams()
<param name=""b"">The param named 'b'</param>";
var expected =
@"Summary:
$@"{FeaturesResources.Summary}
This is the summary.
Parameters:
{FeaturesResources.Parameters}
a:
The param named 'a'
......@@ -167,7 +164,7 @@ public void TypeParameters()
<typeparam name=""U"">The type param named 'U'</typeparam>";
var expected =
@"Type parameters:
$@"{FeaturesResources.TypeParameters}
T:
The type param named 'T'
......@@ -197,10 +194,10 @@ public void FormatEverything()
<remarks>This doc comment is really not very remarkable.</remarks>";
var expected =
@"Summary:
$@"{FeaturesResources.Summary}
This is a summary of something.
Parameters:
{FeaturesResources.Parameters}
a:
The param named 'a'.
......@@ -209,7 +206,7 @@ public void FormatEverything()
c:
The param named 'c'.
Type parameters:
{FeaturesResources.TypeParameters}
T:
A type parameter.
......@@ -218,10 +215,10 @@ public void FormatEverything()
V:
Another type parameter.
Returns:
{FeaturesResources.Returns}
This returns nothing.
Exceptions:
{FeaturesResources.Exceptions}
System.FooException:
Thrown for an unknown reason
......@@ -230,7 +227,7 @@ public void FormatEverything()
System.BlahException:
Thrown when blah blah blah
Remarks:
{FeaturesResources.Remarks}
This doc comment is really not very remarkable.";
TestFormat(comment, expected);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic.DocumentationCommentFormatting;
using Microsoft.CodeAnalysis.VisualBasic.MetadataAsSource;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -21,9 +18,9 @@ Module M
Public Class D
End Class
End Module";
GenerateAndVerifySource(metadataSource, "M+D", LanguageNames.VisualBasic, @"
#Region ""Assembly ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null""
' <in-memory assembly>
GenerateAndVerifySource(metadataSource, "M+D", LanguageNames.VisualBasic, $@"
#Region ""{FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null""
' {CodeAnalysisResources.InMemoryAssembly}
#End Region
Friend Module M
......@@ -37,7 +34,7 @@ End Class
[Fact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
public void BracketedIdentifierSimplicationTest()
{
var expected = @"#Region ""Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""
var expected = $@"#Region ""{FeaturesResources.Assembly} mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""
' mscorlib.v4_0_30319_17626.dll
#End Region
Imports System.Runtime
......
......@@ -173,8 +173,8 @@ public void AssertTag(string expectedFromName, string expectedToName, bool invok
// There should be two actions
Assert.Equal(2, actions.Count);
Assert.Equal(string.Format("Rename '{0}' to '{1}'", expectedFromName, expectedToName), actions[0].Title);
Assert.Equal(string.Format("Rename '{0}' to '{1}' with preview...", expectedFromName, expectedToName), actions[1].Title);
Assert.Equal(string.Format(EditorFeaturesResources.RenameTo, expectedFromName, expectedToName), actions[0].Title);
Assert.Equal(string.Format(EditorFeaturesResources.RenameToWithPreview, expectedFromName, expectedToName), actions[1].Title);
if (invokeAction)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册