/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Features/CSharpTest/UseExpressionBody/Refactoring/UseExpressionBodyForLocalFunctionsRefactoringTests.cs
214 строк
6 KB
Cyrus Najmabadi
Renames
23 июл 2025, 10:53
23 июл 2025, 10:53
a167ea9
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.UseExpressionBody; using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseExpressionBody; [Trait(Traits.Feature, Traits.Features.CodeActionsUseExpressionBody)] public sealed class UseExpressionBodyForLocalFunctionsRefactoringTests : AbstractCSharpCodeActionTest_NoEditor { protected override CodeRefactoringProvider CreateCodeRefactoringProvider(TestWorkspace workspace, TestParameters parameters) => new UseExpressionBodyCodeRefactoringProvider(); private OptionsCollection UseExpressionBody => Option(CSharpCodeStyleOptions.PreferExpressionBodiedLocalFunctions, CSharpCodeStyleOptions.WhenPossibleWithSilentEnforcement); private OptionsCollection UseExpressionBodyDisabledDiagnostic => Option(CSharpCodeStyleOptions.PreferExpressionBodiedLocalFunctions, new CodeStyleOption2<ExpressionBodyPreference>(ExpressionBodyPreference.WhenPossible, NotificationOption2.None)); private OptionsCollection UseBlockBody => Option(CSharpCodeStyleOptions.PreferExpressionBodiedLocalFunctions, CSharpCodeStyleOptions.NeverWithSilentEnforcement); private OptionsCollection UseBlockBodyDisabledDiagnostic => Option(CSharpCodeStyleOptions.PreferExpressionBodiedLocalFunctions, new CodeStyleOption2<ExpressionBodyPreference>(ExpressionBodyPreference.Never, NotificationOption2.None)); [Fact] public Task TestNotOfferedIfUserPrefersExpressionBodiesAndInBlockBody() => TestMissingAsync( """ class C { void Goo() { void Bar() { [||]Test(); } } } """, parameters: new TestParameters(options: UseExpressionBody)); [Fact] public Task TestOfferedIfUserPrefersExpressionBodiesWithoutDiagnosticAndInBlockBody() => TestInRegularAndScriptAsync( """ class C { void Goo() { void Bar() { [||]Test(); } } } """, """ class C { void Goo() { void Bar() => Test(); } } """, parameters: new TestParameters(options: UseExpressionBodyDisabledDiagnostic)); [Fact] public Task TestOfferedIfUserPrefersBlockBodiesAndInBlockBody() => TestInRegularAndScriptAsync( """ class C { void Goo() { void Bar() { [||]Test(); } } } """, """ class C { void Goo() { void Bar() => Test(); } } """, parameters: new TestParameters(options: UseBlockBody)); [Fact] public Task TestNotOfferedIfUserPrefersBlockBodiesAndInExpressionBody() => TestMissingAsync( """ class C { void Goo() { void Bar() => [||]Test(); } } """, parameters: new TestParameters(options: UseBlockBody)); [Fact] public Task TestOfferedIfUserPrefersBlockBodiesWithoutDiagnosticAndInExpressionBody() => TestInRegularAndScriptAsync( """ class C { void Goo() { void Bar() => [||]Test(); } } """, """ class C { void Goo() { void Bar() { Test(); } } } """, parameters: new TestParameters(options: UseBlockBodyDisabledDiagnostic)); [Fact] public Task TestOfferedIfUserPrefersExpressionBodiesAndInExpressionBody() => TestInRegularAndScriptAsync( """ class C { void Goo() { void Bar() => [||]Test(); } } """, """ class C { void Goo() { void Bar() { Test(); } } } """, parameters: new TestParameters(options: UseExpressionBody)); [Fact] public Task TestOfferedWithSelectionInsideBlockBody() => TestInRegularAndScriptAsync( """ class C { void Goo() { void Bar() { [|Test()|]; } } } """, """ class C { void Goo() { void Bar() => Test(); } } """, parameters: new TestParameters(options: UseBlockBody)); [Fact] public Task TestNotOfferedWithSelectionOutsideBlockBody() => TestMissingAsync( """ class C { void Goo() { void Bar() { [|Test(); } }|] } """, parameters: new TestParameters(options: UseBlockBody)); }