提交 d95e0e6d 编写于 作者: S Sam Harwell

Fix the message for Make Field Readonly

Fixes #26219
上级 034065c5
......@@ -36,6 +36,102 @@ internal virtual (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderA
: CreateDiagnosticProviderAndFixer(workspace, parameters);
}
[Fact]
public void TestSupportedDiagnosticsMessageTitle()
{
using (var workspace = new AdhocWorkspace())
{
DiagnosticAnalyzer diagnosticAnalyzer;
try
{
diagnosticAnalyzer = CreateDiagnosticProviderAndFixer(workspace).Item1;
}
catch (NotSupportedException)
{
return;
}
if (diagnosticAnalyzer == null)
{
return;
}
foreach (var descriptor in diagnosticAnalyzer.SupportedDiagnostics)
{
if (descriptor.CustomTags.Contains(WellKnownDiagnosticTags.NotConfigurable))
{
// The title only displayed for rule configuration
continue;
}
Assert.NotEqual("", descriptor.Title?.ToString() ?? "");
}
}
}
[Fact]
public void TestSupportedDiagnosticsMessageDescription()
{
using (var workspace = new AdhocWorkspace())
{
DiagnosticAnalyzer diagnosticAnalyzer;
try
{
diagnosticAnalyzer = CreateDiagnosticProviderAndFixer(workspace).Item1;
}
catch (NotSupportedException)
{
return;
}
if (diagnosticAnalyzer == null)
{
return;
}
foreach (var descriptor in diagnosticAnalyzer.SupportedDiagnostics)
{
if (descriptor.CustomTags.Contains(WellKnownDiagnosticTags.NotConfigurable))
{
if (!descriptor.IsEnabledByDefault || descriptor.DefaultSeverity == DiagnosticSeverity.Hidden)
{
// The message only displayed if either enabled and not hidden, or configurable
continue;
}
}
Assert.NotEqual("", descriptor.MessageFormat?.ToString() ?? "");
}
}
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/26717")]
public void TestSupportedDiagnosticsMessageHelpLinkUri()
{
using (var workspace = new AdhocWorkspace())
{
DiagnosticAnalyzer diagnosticAnalyzer;
try
{
diagnosticAnalyzer = CreateDiagnosticProviderAndFixer(workspace).Item1;
}
catch (NotSupportedException)
{
return;
}
if (diagnosticAnalyzer == null)
{
return;
}
foreach (var descriptor in diagnosticAnalyzer.SupportedDiagnostics)
{
Assert.NotEqual("", descriptor.HelpLinkUri ?? "");
}
}
}
internal async override Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(
TestWorkspace workspace, TestParameters parameters)
{
......
......@@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeActions.AddImp
End Function
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As (DiagnosticAnalyzer, CodeFixProvider)
Throw New NotImplementedException()
Throw New NotSupportedException()
End Function
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace, parameters As TestParameters) As (DiagnosticAnalyzer, CodeFixProvider)
......
......@@ -17,7 +17,7 @@ protected AbstractMakeFieldReadonlyDiagnosticAnalyzer()
: base(
IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.Add_readonly_modifier), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Make_field_readonly), WorkspacesResources.ResourceManager, typeof(WorkspacesResources)))
new LocalizableResourceString(nameof(FeaturesResources.Make_field_readonly), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
}
......
......@@ -14,7 +14,8 @@ public static class DescriptorFactory
/// </summary>
/// <remarks>
/// Returned <see cref="DiagnosticDescriptor"/> has
/// - empty <see cref="DiagnosticDescriptor.Title"/>, <see cref="DiagnosticDescriptor.MessageFormat"/> and <see cref="DiagnosticDescriptor.Category"/>
/// - empty <see cref="DiagnosticDescriptor.Title"/> and <see cref="DiagnosticDescriptor.Category"/>
/// - <see cref="DiagnosticDescriptor.MessageFormat"/> set to <paramref name="id"/>
/// - <see cref="DiagnosticDescriptor.DefaultSeverity"/> set to <see cref="DiagnosticSeverity.Hidden"/>
/// - <see cref="WellKnownDiagnosticTags.NotConfigurable"/> custom tag added in <see cref="DiagnosticDescriptor.CustomTags"/>.
/// </remarks>
......@@ -22,7 +23,7 @@ public static class DescriptorFactory
/// <returns>A <see cref="DiagnosticDescriptor"/> with specified <see cref="DiagnosticDescriptor.Id"/>.</returns>
public static DiagnosticDescriptor CreateSimpleDescriptor(string id)
{
return new DiagnosticDescriptor(id, title: "", messageFormat: "", category: "",
return new DiagnosticDescriptor(id, title: "", messageFormat: id, category: "",
defaultSeverity: DiagnosticSeverity.Hidden, isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.NotConfigurable);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册