diff --git a/src/EditorFeatures/CSharpTest/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionTests.cs b/src/EditorFeatures/CSharpTest/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionTests.cs index 4ee5d4d8d6c0c0be123ef9297f86ee101ed2b247..a87c78d96230fb3dd915117dfbdacc1957e03204 100644 --- a/src/EditorFeatures/CSharpTest/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionTests.cs +++ b/src/EditorFeatures/CSharpTest/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionTests.cs @@ -1,12 +1,17 @@ // 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 System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CodeStyle; +using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; +using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Test.Utilities; +using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertSwitchStatementToExpression @@ -624,5 +629,36 @@ int M(int i) } }"); } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)] + [WorkItemAttribute(36086, "https://github.com/dotnet/roslyn/issues/36086")] + public async Task TestSeverity() + { + var source = +@"class Program +{ + int M(int i) + { + [||]switch (i) + { + case 1: + return 4; + case 2: + return 5; + case 3: + return 6; + default: + return 7; + } + } +}"; + var warningOption = new CodeStyleOption(true, NotificationOption.Warning); + var options = Option(CSharpCodeStyleOptions.PreferSwitchExpression, warningOption); + var testParameters = new TestParameters(options: options, parseOptions: TestOptions.Regular8); + using var workspace = CreateWorkspaceFromOptions(source, testParameters); + var diags = await GetDiagnosticsAsync(workspace, testParameters); + Assert.Single(diags); + Assert.Equal(DiagnosticSeverity.Warning, diags.First().Severity); + } } } diff --git a/src/Features/CSharp/Portable/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs b/src/Features/CSharp/Portable/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs index 74fd2618627d3e61ba50cdf84c91d50a55ceaa48..c73b14cd6e9863003a248a237c497bf9ce820381 100644 --- a/src/Features/CSharp/Portable/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs +++ b/src/Features/CSharp/Portable/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.cs @@ -61,9 +61,10 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context) return; } - context.ReportDiagnostic(Diagnostic.Create(Descriptor, + context.ReportDiagnostic(DiagnosticHelper.Create(Descriptor, // Report the diagnostic on the "switch" keyword. location: switchStatement.GetFirstToken().GetLocation(), + effectiveSeverity: styleOption.Notification.Severity, additionalLocations: new[] { switchStatement.GetLocation() }, properties: ImmutableDictionary.Empty .Add(Constants.NodeToGenerateKey, ((int)nodeToGenerate).ToString(CultureInfo.InvariantCulture))