From fdc3fbc4b081b0950a6774134c7634c59de35446 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 22 Jun 2021 14:57:33 -0700 Subject: [PATCH 1/3] Convert ImplementInterfaceTests_FixAllTests to the new test library --- .../ImplementExplicitlyTests.cs | 2 +- .../ImplementImplicitlyTests.cs | 2 +- .../ImplementInterfaceTests.cs | 2 +- .../ImplementInterfaceTests_FixAllTests.cs | 540 +++++++++++------- 4 files changed, 330 insertions(+), 216 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementExplicitlyTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementExplicitlyTests.cs index 7e7b0806bdaea..511f26564b02e 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementExplicitlyTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementExplicitlyTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ImplementInterface { - public partial class ImplementExplicitlyTests : AbstractCSharpCodeActionTest + public class ImplementExplicitlyTests : AbstractCSharpCodeActionTest { private const int SingleMember = 0; private const int SameInterface = 1; diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementImplicitlyTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementImplicitlyTests.cs index 9e5cf1cf288a1..d46a05aa7684a 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementImplicitlyTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementImplicitlyTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ImplementInterface { - public partial class ImplementImplicitlyTests : AbstractCSharpCodeActionTest + public class ImplementImplicitlyTests : AbstractCSharpCodeActionTest { private const int SingleMember = 0; private const int SameInterface = 1; diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index f7214906858db..ccea4d3eddd81 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ImplementInterface { - public partial class ImplementInterfaceTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest + public class ImplementInterfaceTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest { private readonly NamingStylesTestOptionSets _options = new NamingStylesTestOptionSets(LanguageNames.CSharp); diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests_FixAllTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests_FixAllTests.cs index 7bdfffaf01dbd..71951cbf5097b 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests_FixAllTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests_FixAllTests.cs @@ -2,16 +2,17 @@ // 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.Test.Utilities; +using Microsoft.CodeAnalysis.Testing; using Xunit; -using ImplementInterfaceCodeAction = Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService.ImplementInterfaceCodeAction; +using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier< + Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer, + Microsoft.CodeAnalysis.CSharp.ImplementInterface.CSharpImplementInterfaceCodeFixProvider>; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ImplementInterface { - public partial class ImplementInterfaceTests + public class ImplementInterfaceTests_FixAllTests { #region "Fix all occurrences tests" @@ -20,11 +21,13 @@ public partial class ImplementInterfaceTests [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInDocument() { - var input = @" - - - -public interface I1 + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -34,40 +37,75 @@ public interface I2 void F1(); } -class B1 : {|FixAllInDocument:I1|}, I2 +class B1 : {|CS0535:I1|}, {|CS0535:I2|} { - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} { - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - - - Assembly1 - -class B3 : I1, I2 +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"class B3 : {|CS0535:I1|}, {|CS0535:I2|} { - class C3 : I1, I2 + class C3 : {|CS0535:I1|}, {|CS0535:I2|} { } +}", + }, + AdditionalProjectReferences = { "TestProject" }, + }, + }, + }, + FixedState = + { + Sources = + { + @"public interface I1 +{ + void F1(); } - - -"; - var expected = @" - - - -public interface I1 +public interface I2 +{ + void F1(); +} + +class B1 : I1, I2 +{ + public void F1() + { + throw new System.NotImplementedException(); + } + + class C1 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} +{ + class C2 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + BatchFixedState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -91,31 +129,20 @@ public void F1() throw new System.NotImplementedException(); } } -} - - -class B2 : I1, I2 -{ - class C2 : I1, I2 - { - } -} - - - - Assembly1 - -class B3 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} { - class C3 : I1, I2 + class C2 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - -"; - - await TestInRegularAndScriptAsync(input, expected); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne | CodeFixTestBehaviors.SkipFixAllInProjectCheck | CodeFixTestBehaviors.SkipFixAllInSolutionCheck, + CodeActionEquivalenceKey = "False;False;True:global::I1;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [Fact] @@ -123,11 +150,13 @@ class C3 : I1, I2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInProject() { - var input = @" - - - -public interface I1 + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -137,40 +166,75 @@ public interface I2 void F1(); } -class B1 : {|FixAllInProject:I1|}, I2 +class B1 : {|CS0535:I1|}, {|CS0535:I2|} { - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} { - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - - - Assembly1 - -class B3 : I1, I2 +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"class B3 : {|CS0535:I1|}, {|CS0535:I2|} { - class C3 : I1, I2 + class C3 : {|CS0535:I1|}, {|CS0535:I2|} { } +}", + }, + AdditionalProjectReferences = { "TestProject" }, + }, + }, + }, + FixedState = + { + Sources = + { + @"public interface I1 +{ + void F1(); } - - -"; - var expected = @" - - - -public interface I1 +public interface I2 +{ + void F1(); +} + +class B1 : I1, I2 +{ + public void F1() + { + throw new System.NotImplementedException(); + } + + class C1 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} +{ + class C2 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + BatchFixedState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -194,10 +258,8 @@ public void F1() throw new System.NotImplementedException(); } } -} - - -class B2 : I1, I2 +}", + @"class B2 : I1, I2 { public void F1() { @@ -211,23 +273,14 @@ public void F1() throw new System.NotImplementedException(); } } -} - - - - Assembly1 - -class B3 : I1, I2 -{ - class C3 : I1, I2 - { - } -} - - -"; - - await TestInRegularAndScriptAsync(input, expected); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne | CodeFixTestBehaviors.SkipFixAllInDocumentCheck | CodeFixTestBehaviors.SkipFixAllInSolutionCheck, + CodeActionEquivalenceKey = "False;False;True:global::I1;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [Fact] @@ -235,11 +288,13 @@ class C3 : I1, I2 [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInSolution() { - var input = @" - - - -public interface I1 + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -249,40 +304,75 @@ public interface I2 void F1(); } -class B1 : I1, {|FixAllInSolution:I2|} +class B1 : {|CS0535:I1|}, {|CS0535:I2|} { - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} { - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - - - Assembly1 - -class B3 : I1, I2 +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"class B3 : {|CS0535:I1|}, {|CS0535:I2|} { - class C3 : I1, I2 + class C3 : {|CS0535:I1|}, {|CS0535:I2|} { } +}", + }, + AdditionalProjectReferences = { "TestProject" }, + }, + }, + }, + FixedState = + { + Sources = + { + @"public interface I1 +{ + void F1(); } - - -"; - var expected = @" - - - -public interface I1 +public interface I2 +{ + void F1(); +} + +class B1 : {|CS0535:I1|}, I2 +{ + void I2.F1() + { + throw new System.NotImplementedException(); + } + + class C1 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} +{ + class C2 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + BatchFixedState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -292,63 +382,69 @@ public interface I2 void F1(); } -class B1 : I1, I2 +class B1 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } } -} - - - - Assembly1 - -class B3 : I1, I2 +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"class B3 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } - class C3 : I1, I2 + class C3 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } } -} - - -"; - - await TestInRegularAndScriptAsync(input, expected, index: 1); +}", + }, + AdditionalProjectReferences = { "TestProject" }, + }, + }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne | CodeFixTestBehaviors.SkipFixAllInDocumentCheck | CodeFixTestBehaviors.SkipFixAllInProjectCheck, + DiagnosticSelector = diagnostics => diagnostics[1], + CodeActionEquivalenceKey = "True;False;False:global::I2;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact] @@ -356,11 +452,13 @@ void I2.F1() [Trait(Traits.Feature, Traits.Features.CodeActionsFixAllOccurrences)] public async Task TestFixAllInSolution_DifferentAssemblyWithSameTypeName() { - var input = @" - - - -public interface I1 + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -370,25 +468,26 @@ public interface I2 void F1(); } -class B1 : I1, {|FixAllInSolution:I2|} +class B1 : {|CS0535:I1|}, {|CS0535:I2|} { - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} { - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, {|CS0535:I2|} { } -} - - - - -public interface I1 +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -398,21 +497,55 @@ public interface I2 void F1(); } -class B3 : I1, I2 +class B3 : {|CS0535:I1|}, {|CS0535:I2|} { - class C3 : I1, I2 + class C3 : {|CS0535:I1|}, {|CS0535:I2|} { } +}", + }, + }, + }, + }, + FixedState = + { + Sources = + { + @"public interface I1 +{ + void F1(); +} + +public interface I2 +{ + void F1(); } - - -"; - var expected = @" - - - -public interface I1 +class B1 : {|CS0535:I1|}, I2 +{ + void I2.F1() + { + throw new System.NotImplementedException(); + } + + class C1 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + @"class B2 : {|CS0535:I1|}, {|CS0535:I2|} +{ + class C2 : {|CS0535:I1|}, {|CS0535:I2|} + { + } +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + BatchFixedState = + { + Sources = + { + @"public interface I1 { void F1(); } @@ -422,63 +555,44 @@ public interface I2 void F1(); } -class B1 : I1, I2 +class B1 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } - class C1 : I1, I2 + class C1 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } } -} - - -class B2 : I1, I2 +}", + @"class B2 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } - class C2 : I1, I2 + class C2 : {|CS0535:I1|}, I2 { void I2.F1() { throw new System.NotImplementedException(); } } -} - - - - -public interface I1 -{ - void F1(); -} - -public interface I2 -{ - void F1(); -} - -class B3 : I1, I2 -{ - class C3 : I1, I2 - { - } -} - - -"; - - await TestInRegularAndScriptAsync(input, expected, index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne | CodeFixTestBehaviors.SkipFixAllInDocumentCheck | CodeFixTestBehaviors.SkipFixAllInProjectCheck, + DiagnosticSelector = diagnostics => diagnostics[1], + CodeActionEquivalenceKey = "True;False;False:global::I2;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } #endregion From fda7249ffffb20e9b35c854c390e0993e4849f5c Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 22 Jun 2021 16:04:47 -0700 Subject: [PATCH 2/3] Convert ImplementInterfaceTests to the new test library --- .../ImplementInterfaceTests.cs | 2789 ++++++++++------- .../CSharpCodeFixVerifier`2+Test.cs | 11 + 2 files changed, 1708 insertions(+), 1092 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index ccea4d3eddd81..c898894ffb159 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -3,37 +3,28 @@ // See the LICENSE file in the project root for more information. using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.CodeStyle; -using Microsoft.CodeAnalysis.CSharp.ImplementInterface; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles; using Microsoft.CodeAnalysis.ImplementType; using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.Testing; using Roslyn.Test.Utilities; using Xunit; -using Xunit.Abstractions; +using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier< + Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer, + Microsoft.CodeAnalysis.CSharp.ImplementInterface.CSharpImplementInterfaceCodeFixProvider>; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ImplementInterface { - public class ImplementInterfaceTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest + public class ImplementInterfaceTests { private readonly NamingStylesTestOptionSets _options = new NamingStylesTestOptionSets(LanguageNames.CSharp); - public ImplementInterfaceTests(ITestOutputHelper logger) - : base(logger) - { - } - - internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) - => (null, new CSharpImplementInterfaceCodeFixProvider()); - - private OptionsCollection AllOptionsOff - => new OptionsCollection(GetLanguage()) + private static OptionsCollection AllOptionsOff + => new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, { CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, @@ -43,8 +34,8 @@ private OptionsCollection AllOptionsOff { CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, }; - private OptionsCollection AllOptionsOn - => new OptionsCollection(GetLanguage()) + private static OptionsCollection AllOptionsOn + => new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CSharpCodeStyleOptions.WhenPossibleWithSilentEnforcement }, { CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.WhenPossibleWithSilentEnforcement }, @@ -54,8 +45,8 @@ private OptionsCollection AllOptionsOn { CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, CSharpCodeStyleOptions.WhenPossibleWithSilentEnforcement }, }; - private OptionsCollection AccessorOptionsOn - => new OptionsCollection(GetLanguage()) + private static OptionsCollection AccessorOptionsOn + => new OptionsCollection(LanguageNames.CSharp) { { CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, { CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, @@ -65,8 +56,6 @@ private OptionsCollection AccessorOptionsOn { CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, }; - private static readonly ParseOptions CSharp7_1 = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1); - private const string NullableAttributesCode = @" namespace System.Diagnostics.CodeAnalysis { @@ -114,28 +103,121 @@ internal sealed class DoesNotReturnIfAttribute : Attribute } }"; - internal async Task TestWithAllCodeStyleOptionsOffAsync( + internal static async Task TestWithAllCodeStyleOptionsOffAsync( string initialMarkup, string expectedMarkup, - int index = 0, ParseOptions? parseOptions = null) + (string equivalenceKey, int index)? codeAction = null, ParseOptions? parseOptions = null) { - await TestAsync(initialMarkup, expectedMarkup, parseOptions, null, - index, options: AllOptionsOff); + var test = new VerifyCS.Test + { + TestCode = initialMarkup, + FixedCode = expectedMarkup, + SolutionTransforms = + { + (solution, projectId) => + { + if (parseOptions is not null) + { + solution = solution.WithProjectParseOptions(projectId, parseOptions); + } + + return solution; + }, + }, + }; + + if (codeAction is var (equivalenceKey, index)) + { + test.CodeActionEquivalenceKey = equivalenceKey; + test.CodeActionIndex = index; + } + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } - internal async Task TestWithAllCodeStyleOptionsOnAsync( + internal static async Task TestWithAllCodeStyleOptionsOnAsync( string initialMarkup, string expectedMarkup, - int index = 0, ParseOptions? parseOptions = null) + (string equivalenceKey, int index)? codeAction = null, ParseOptions? parseOptions = null) { - await TestAsync(initialMarkup, expectedMarkup, parseOptions, null, - index, options: AllOptionsOn); + var test = new VerifyCS.Test + { + TestCode = initialMarkup, + FixedCode = expectedMarkup, + SolutionTransforms = + { + (solution, projectId) => + { + if (parseOptions is not null) + { + solution = solution.WithProjectParseOptions(projectId, parseOptions); + } + + return solution; + }, + }, + }; + + if (codeAction is var (equivalenceKey, index)) + { + test.CodeActionEquivalenceKey = equivalenceKey; + test.CodeActionIndex = index; + } + + test.Options.AddRange(AllOptionsOn); + await test.RunAsync(); } - internal async Task TestWithAccessorCodeStyleOptionsOnAsync( + internal static async Task TestWithAccessorCodeStyleOptionsOnAsync( string initialMarkup, string expectedMarkup, - int index = 0, ParseOptions? parseOptions = null) + (string equivalenceKey, int index)? codeAction = null) + { + var test = new VerifyCS.Test + { + TestCode = initialMarkup, + FixedCode = expectedMarkup, + }; + + if (codeAction is var (equivalenceKey, index)) + { + test.CodeActionEquivalenceKey = equivalenceKey; + test.CodeActionIndex = index; + } + + test.Options.AddRange(AccessorOptionsOn); + await test.RunAsync(); + } + + private static async Task TestInRegularAndScriptAsync( + string initialMarkup, + string expectedMarkup, + (string equivalenceKey, int index)? codeAction = null, + ParseOptions? parseOptions = null) { - await TestAsync(initialMarkup, expectedMarkup, parseOptions, null, - index, options: AccessorOptionsOn); + var test = new VerifyCS.Test + { + TestCode = initialMarkup, + FixedCode = expectedMarkup, + SolutionTransforms = + { + (solution, projectId) => + { + if (parseOptions is not null) + { + solution = solution.WithProjectParseOptions(projectId, parseOptions); + } + + return solution; + }, + }, + }; + + if (codeAction is var (equivalenceKey, index)) + { + test.CodeActionEquivalenceKey = equivalenceKey; + test.CodeActionIndex = index; + } + + await test.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -147,7 +229,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface @@ -173,7 +255,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -record Record : [|IInterface|] +record Record : {|CS0535:IInterface|} { }", @"interface IInterface @@ -210,19 +292,21 @@ public NativeIntegerAttribute(bool[] flags) }"; // Note: we're putting the attribute by hand to simulate metadata - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @"interface IInterface { - [return: System.Runtime.CompilerServices.NativeInteger(new[] { true, true })] + [return: {|CS8335:System.Runtime.CompilerServices.NativeInteger(new[] { true, true })|}] (nint, nuint) Method(nint x, nuint x2); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }" + nativeIntegerAttributeDefinition, - @"interface IInterface + FixedCode = @"interface IInterface { - [return: System.Runtime.CompilerServices.NativeInteger(new[] { true, true })] + [return: {|CS8335:System.Runtime.CompilerServices.NativeInteger(new[] { true, true })|}] (nint, nuint) Method(nint x, nuint x2); } @@ -232,7 +316,9 @@ class Class : IInterface { throw new System.NotImplementedException(); } -}" + nativeIntegerAttributeDefinition); +}" + nativeIntegerAttributeDefinition, + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -244,7 +330,7 @@ await TestWithAllCodeStyleOptionsOffAsync( (int, int) Method((string, string) x); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface @@ -272,7 +358,7 @@ interface I { ValueTuple F(); } -class C : [|I|] +class C : {|CS0535:I|} { }", @" @@ -299,7 +385,7 @@ await TestWithAllCodeStyleOptionsOnAsync( void Method1(); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface @@ -313,14 +399,6 @@ class Class : IInterface }"); } - private const string s_tupleElementNamesAttribute = -@"namespace System.Runtime.CompilerServices -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Event )] - public sealed class TupleElementNamesAttribute : Attribute { } -} -"; - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface), CompilerTrait(CompilerFeature.Tuples)] public async Task TupleWithNamesInMethod() { @@ -328,16 +406,16 @@ public async Task TupleWithNamesInMethod() await TestWithAllCodeStyleOptionsOffAsync( @"interface IInterface { - [return: System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] + [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] (int a, int b)[] Method1((int c, string) x); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { -}" + s_tupleElementNamesAttribute, +}", @"interface IInterface { - [return: System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] + [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] (int a, int b)[] Method1((int c, string) x); } @@ -347,8 +425,7 @@ class Class : IInterface { throw new System.NotImplementedException(); } -} -" + s_tupleElementNamesAttribute); +}"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface), CompilerTrait(CompilerFeature.Tuples)] @@ -357,16 +434,16 @@ public async Task TupleWithNamesInMethod_Explicitly() await TestWithAllCodeStyleOptionsOffAsync( @"interface IInterface { - [return: System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] + [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] (int a, int b)[] Method1((int c, string) x); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { -}" + s_tupleElementNamesAttribute, +}", @"interface IInterface { - [return: System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] + [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] (int a, int b)[] Method1((int c, string) x); } @@ -376,9 +453,8 @@ class Class : IInterface { throw new System.NotImplementedException(); } -} -" + s_tupleElementNamesAttribute, -index: 1); +}", +codeAction: ("True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface), CompilerTrait(CompilerFeature.Tuples)] @@ -387,17 +463,17 @@ public async Task TupleWithNamesInProperty() await TestWithAllCodeStyleOptionsOffAsync( @"interface IInterface { - [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] - (int a, int b)[] Property1 { [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] get; [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] set; } + [{|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] + (int a, int b)[] Property1 { [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] get; [param: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] set; } } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { -}" + s_tupleElementNamesAttribute, +}", @"interface IInterface { - [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] - (int a, int b)[] Property1 { [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] get; [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] set; } + [{|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] + (int a, int b)[] Property1 { [return: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] get; [param: {|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] set; } } class Class : IInterface @@ -414,34 +490,37 @@ class Class : IInterface throw new System.NotImplementedException(); } } -} -" + s_tupleElementNamesAttribute); +}"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface), CompilerTrait(CompilerFeature.Tuples)] public async Task TupleWithNamesInEvent() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + TestCode = @"interface IInterface { - [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] - event Func<(int a, int b)> Event1; + [{|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] + event System.Func<(int a, int b)> Event1; } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { -}" + s_tupleElementNamesAttribute, -@"interface IInterface +}", + FixedCode = @"using System; + +interface IInterface { - [System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })] - event Func<(int a, int b)> Event1; + [{|CS8138:System.Runtime.CompilerServices.TupleElementNames(new[] { ""a"", ""b"" })|}] + event System.Func<(int a, int b)> Event1; } class Class : IInterface { public event Func<(int a, int b)> Event1; -} -" + s_tupleElementNamesAttribute); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -450,16 +529,16 @@ public async Task NoDynamicAttributeInMethod() await TestWithAllCodeStyleOptionsOffAsync( @"interface IInterface { - [return: System.Runtime.CompilerServices.DynamicAttribute()] + [return: {|CS1970:System.Runtime.CompilerServices.DynamicAttribute()|}] object Method1(); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface { - [return: System.Runtime.CompilerServices.DynamicAttribute()] + [return: {|CS1970:System.Runtime.CompilerServices.DynamicAttribute()|}] object Method1(); } @@ -475,32 +554,48 @@ public object Method1() [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task NoNullableAttributesInMethodFromMetadata() { - var initial = @" - - - - -#nullable enable - -public interface IInterface -{ - void M(string? s1, string s2); - string this[string? s1, string s2] { get; set; } -} - - - + var test = new VerifyCS.Test + { + TestState = + { + Sources = + { + @" #nullable enable using System; -class C : [|IInterface|] +class C : {|CS0535:{|CS0535:IInterface|}|} { -} - -"; +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @" +#nullable enable - var expected = @" +public interface IInterface +{ + void M(string? s1, string s2); + string this[string? s1, string s2] { get; set; } +}" + }, + }, + }, + AdditionalProjectReferences = + { + "Assembly1", + }, + }, + FixedState = + { + Sources = + { + @" #nullable enable using System; @@ -524,9 +619,15 @@ public void M(string? s1, string s2) { throw new NotImplementedException(); } -}"; +}", + }, + }, + CodeActionEquivalenceKey = "False;False;True:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }; - await TestWithAllCodeStyleOptionsOffAsync(initial, expected, index: 0); + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -538,7 +639,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class Class : [|IInterface|]", +class Class : {|CS0535:IInterface|}{|CS1513:|}{|CS1514:|}", @"interface IInterface { void Method1(); @@ -567,7 +668,7 @@ interface IInterface2 : IInterface1 { } -class Class : [|IInterface2|] +class Class : {|CS0535:IInterface2|} { }", @"interface IInterface1 @@ -601,7 +702,7 @@ interface IInterface2 : IInterface1 void Method1(); } -class Class : [|IInterface2|] +class Class : {|CS0535:IInterface2|} { }", @"interface IInterface1 @@ -636,7 +737,7 @@ interface IInterface2 : IInterface1 void Method2(); } -class Class : [|IInterface2|] +class Class : {|CS0535:{|CS0535:IInterface2|}|} { }", @"interface IInterface1 @@ -677,7 +778,7 @@ interface IInterface2 : IInterface1 void Method1(); } -class Class : [|IInterface2|] +class Class : {|CS0535:{|CS0535:IInterface2|}|} { }", @"interface IInterface1 @@ -708,7 +809,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class Class : [|IInterface1|] +class Class : {|CS0738:IInterface1|} { public int Method1() { @@ -743,7 +844,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(int i); } -class Class : [|IInterface1|] +class Class : {|CS0535:IInterface1|} { public void Method1(string i) { @@ -776,7 +877,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(T t); } -class Class : [|IInterface1|] +class Class : {|CS0535:IInterface1|} { }", @"interface IInterface1 @@ -802,7 +903,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(T t, U u); } -class Class : [|IInterface1|] +class Class : {|CS0535:IInterface1|} { }", @"interface IInterface1 @@ -823,15 +924,17 @@ public void Method1(int t, U u) public async Task TestImplementGenericTypeWithGenericMethodWithNaturalConstraint() { await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface1 +@"using System.Collections.Generic; +interface IInterface1 { void Method1(T t, U u) where U : IList; } -class Class : [|IInterface1|] +class Class : {|CS0535:IInterface1|} { }", -@"interface IInterface1 +@"using System.Collections.Generic; +interface IInterface1 { void Method1(T t, U u) where U : IList; } @@ -854,7 +957,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(T t, U u) where U : T; } -class Class : [|IInterface1|] +class Class : {|CS0535:IInterface1|} { }", @"interface IInterface1 @@ -880,7 +983,7 @@ await TestWithAllCodeStyleOptionsOffAsync( string[] M(); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -906,7 +1009,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class C : [|I|] +class C : {|CS0535:I|} { I i; }", @@ -924,7 +1027,7 @@ public void Method1() i.Method1(); } }", -index: 1); +codeAction: ("False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;i", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -936,12 +1039,12 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class C : {|FixAllInDocument:I|} +class C : {|CS0535:I|} { I i; } -class D : I +class D : {|CS0535:I|} { I i; }", @@ -969,7 +1072,7 @@ public void Method1() i.Method1(); } }", -index: 1); +codeAction: ("False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;i", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -981,12 +1084,12 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -class C : {|FixAllInDocument:I|} +class C : {|CS0535:I|} { I i; } -class D : I +class D : {|CS0535:I|} { I i { get; } }", @@ -1014,28 +1117,33 @@ public void Method1() i.Method1(); } }", -index: 1); +codeAction: ("False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;i", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementThroughFieldMember_FixAll_FieldInOneNonViableInAnother() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + var test = new VerifyCS.Test + { + TestCode = @"interface I { void Method1(); } -class C : {|FixAllInDocument:I|} +class C : {|CS0535:I|} { I i; } -class D : I +class D : {|CS0535:I|} { int i; }", -@"interface I + FixedState = + { + Sources = + { + @"interface I { void Method1(); } @@ -1050,11 +1158,20 @@ public void Method1() } } -class D : I +class D : {|CS0535:I|} { int i; }", -index: 1); + }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;i", + CodeActionIndex = 1, + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -1066,7 +1183,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int this[int x] { get; set; } } -class Goo : [|IGoo|] +class Goo : {|CS0535:IGoo|} { IGoo f; }", @@ -1092,7 +1209,7 @@ public int this[int x] } } }", -index: 1); +codeAction: ("False;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;f", 1)); } [WorkItem(472, "https://github.com/dotnet/roslyn/issues/472")] @@ -1102,7 +1219,7 @@ public async Task TestImplementThroughFieldMemberRemoveUnnecessaryCast() await TestWithAllCodeStyleOptionsOffAsync( @"using System.Collections; -sealed class X : [|IComparer|] +sealed class X : {|CS0535:IComparer|} { X x; }", @@ -1117,7 +1234,7 @@ public int Compare(object x, object y) return ((IComparer)this.x).Compare(x, y); } }", -index: 1); +codeAction: ("False;False;False:global::System.Collections.IComparer;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;x", 1)); } [WorkItem(472, "https://github.com/dotnet/roslyn/issues/472")] @@ -1127,7 +1244,7 @@ public async Task TestImplementThroughFieldMemberRemoveUnnecessaryCastAndThis() await TestWithAllCodeStyleOptionsOffAsync( @"using System.Collections; -sealed class X : [|IComparer|] +sealed class X : {|CS0535:IComparer|} { X a; }", @@ -1142,7 +1259,7 @@ public int Compare(object x, object y) return ((IComparer)a).Compare(x, y); } }", -index: 1); +codeAction: ("False;False;False:global::System.Collections.IComparer;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -1154,7 +1271,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Method1(); } -abstract class C : [|I|] +abstract class C : {|CS0535:I|} { }", @"interface I @@ -1166,14 +1283,14 @@ abstract class C : I { public abstract void Method1(); }", -index: 1); +codeAction: ("False;True;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceWithRefOutParameters() { await TestWithAllCodeStyleOptionsOffAsync( -@"class C : [|I|] +@"class C : {|CS0535:{|CS0535:I|}|} { I goo; } @@ -1203,7 +1320,7 @@ interface I void Method1(ref int x, out int y, int z); int Method2(); }", -index: 1); +codeAction: ("False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;goo", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -1214,10 +1331,11 @@ await TestWithAllCodeStyleOptionsOffAsync( { public int Method1() { + return 0; } } -class C : B, [|I|] +class C : B, {|CS0738:I|} { } @@ -1229,6 +1347,7 @@ interface I { public int Method1() { + return 0; } } @@ -1250,7 +1369,7 @@ interface I public async Task TestConflictingProperties() { await TestWithAllCodeStyleOptionsOffAsync( -@"class Test : [|I1|] +@"class Test : {|CS0737:I1|} { int Prop { get; set; } } @@ -1287,13 +1406,13 @@ interface I1 [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestExplicitProperties() { - await TestMissingInRegularAndScriptAsync( + var code = @"interface I2 { decimal Calc { get; } } -class C : [|I2|] +class C : I2 { protected decimal pay; @@ -1304,7 +1423,9 @@ decimal I2.Calc return pay; } } -}"); +}"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [WorkItem(539489, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539489")] @@ -1317,7 +1438,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void @M(); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface @@ -1344,7 +1465,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void @int(); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", @"interface IInterface @@ -1371,9 +1492,9 @@ await TestWithAllCodeStyleOptionsOffAsync( void M(); } -class Class : [|@IInterface|] +class Class : {|CS0737:@IInterface|} { - string M(); + string M() => """"; }", @"interface @IInterface { @@ -1382,7 +1503,7 @@ class Class : [|@IInterface|] class Class : @IInterface { - string M(); + string M() => """"; void IInterface.M() { @@ -1401,9 +1522,9 @@ await TestWithAllCodeStyleOptionsOffAsync( void @M(); } -class Class : [|@IInterface|] +class Class : {|CS0737:@IInterface|} { - string M(); + string M() => """"; }", @"interface @IInterface { @@ -1412,7 +1533,7 @@ class Class : [|@IInterface|] class Class : @IInterface { - string M(); + string M() => """"; void IInterface.M() { @@ -1431,9 +1552,9 @@ await TestWithAllCodeStyleOptionsOffAsync( void M(); } -class Class : [|@int|] +class Class : {|CS0737:@int|} { - string M(); + string M() => """"; }", @"interface @int { @@ -1442,7 +1563,7 @@ class Class : [|@int|] class Class : @int { - string M(); + string M() => """"; void @int.M() { @@ -1461,9 +1582,9 @@ await TestWithAllCodeStyleOptionsOffAsync( void @bool(); } -class Class : [|@int|] +class Class : {|CS0737:@int|} { - string @bool(); + string @bool() => """"; }", @"interface @int { @@ -1472,7 +1593,7 @@ class Class : [|@int|] class Class : @int { - string @bool(); + string @bool() => """"; void @int.@bool() { @@ -1490,7 +1611,7 @@ await TestWithAllCodeStyleOptionsOffAsync( { int Prop { get; set; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1523,7 +1644,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int Prop { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1546,7 +1667,7 @@ await TestWithAccessorCodeStyleOptionsOnAsync( int Prop { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1569,7 +1690,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int this[int i] { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1592,7 +1713,7 @@ await TestWithAccessorCodeStyleOptionsOnAsync( int this[int i] { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1615,7 +1736,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int M(); } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1638,7 +1759,7 @@ await TestWithAllCodeStyleOptionsOnAsync( { int Prop { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1661,7 +1782,7 @@ await TestWithAccessorCodeStyleOptionsOnAsync( int Prop { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1685,7 +1806,7 @@ await TestWithAccessorCodeStyleOptionsOnAsync( int Prop { get; set; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1709,7 +1830,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int Prop { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1738,7 +1859,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int this[int i] { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1761,7 +1882,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int this[int i] { get; set; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1784,7 +1905,7 @@ await TestWithAccessorCodeStyleOptionsOnAsync( int this[int i] { get; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1807,7 +1928,7 @@ await TestWithAllCodeStyleOptionsOnAsync( int this[int i] { get; set; } } -public class A : [|DD|] +public class A : {|CS0535:DD|} { }", @"public interface DD @@ -1829,7 +1950,7 @@ await TestWithAllCodeStyleOptionsOffAsync( { void Goo(); } -public class A : [|DD|] +public class A : {|CS0535:DD|} { //comments }", @@ -1853,7 +1974,7 @@ public async Task TestBracePlacement() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|]", +class C : {|CS0535:IServiceProvider|}{|CS1513:|}{|CS1514:|}", @"using System; class C : IServiceProvider { @@ -1869,19 +1990,21 @@ public object GetService(Type serviceType) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestMissingWithIncompleteMember() { - await TestMissingInRegularAndScriptAsync( + var code = @"interface ITest { void Method(); } -class Test : [|ITest|] +class Test : ITest { - p public void Method() + p {|CS1585:public|} void Method() { - throw new NotImplementedException(); + throw new System.NotImplementedException(); } -}"); +}"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [WorkItem(541380, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541380")] @@ -1894,7 +2017,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int p { get; set; } } -class c1 : [|i1|] +class c1 : {|CS0535:i1|} { }", @"interface i1 @@ -1917,35 +2040,28 @@ int i1.p } } }", -index: 1); +codeAction: ("True;False;False:global::i1;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(541981, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541981")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNoDelegateThroughField1() { - await TestActionCountAsync( + var code = @"interface I { void Method1(); } -class C : [|I|] +class C : {|CS0535:I|} { I i { get; set; } -}", -count: 3); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I -{ - void Method1(); -} +}"; -class C : [|I|] -{ - I i { get; set; } -}", -@"interface I + await new VerifyCS.Test + { + TestCode = code, + FixedCode = @"interface I { void Method1(); } @@ -1959,18 +2075,16 @@ public void Method1() throw new System.NotImplementedException(); } }", -index: 0); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I -{ - void Method1(); -} + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + CodeActionEquivalenceKey = "False;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); -class C : [|I|] -{ - I i { get; set; } -}", -@"interface I + await new VerifyCS.Test + { + TestCode = code, + FixedCode = @"interface I { void Method1(); } @@ -1984,18 +2098,16 @@ public void Method1() i.Method1(); } }", -index: 1); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I -{ - void Method1(); -} + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;i", + CodeActionIndex = 1, + }.RunAsync(); -class C : [|I|] -{ - I i { get; set; } -}", -@"interface I + await new VerifyCS.Test + { + TestCode = code, + FixedCode = @"interface I { void Method1(); } @@ -2009,7 +2121,11 @@ void I.Method1() throw new System.NotImplementedException(); } }", -index: 2); + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + CodeActionEquivalenceKey = "True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 2, + }.RunAsync(); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] @@ -2019,7 +2135,7 @@ public async Task TestImplementIReadOnlyListThroughField() await TestWithAllCodeStyleOptionsOffAsync( @"using System.Collections.Generic; -class A : [|IReadOnlyList|] +class A : {|CS0535:{|CS0535:{|CS0535:{|CS0535:IReadOnlyList|}|}|}|} { int[] field; }", @@ -2056,7 +2172,7 @@ IEnumerator IEnumerable.GetEnumerator() return field.GetEnumerator(); } }", -index: 1); +codeAction: ("False;False;False:global::System.Collections.Generic.IReadOnlyList;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;field", 1)); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] @@ -2066,7 +2182,7 @@ public async Task TestImplementIReadOnlyListThroughProperty() await TestWithAllCodeStyleOptionsOffAsync( @"using System.Collections.Generic; -class A : [|IReadOnlyList|] +class A : {|CS0535:{|CS0535:{|CS0535:{|CS0535:IReadOnlyList|}|}|}|} { int[] field { get; set; } }", @@ -2103,7 +2219,7 @@ IEnumerator IEnumerable.GetEnumerator() return field.GetEnumerator(); } }", -index: 1); +codeAction: ("False;False;False:global::System.Collections.Generic.IReadOnlyList;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;field", 1)); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] @@ -2124,7 +2240,7 @@ int I.M() } } -class B : [|I|] +class B : {|CS0535:I|} { A a; }", @@ -2150,51 +2266,25 @@ public int M() return ((I)a).M(); } }", -index: 1); +codeAction: ("False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", 1)); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceThroughField_FieldImplementsMultipleInterfaces() { - await TestActionCountAsync( -@"interface I + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } interface I2 { - int M2() } - -class A : I, I2 -{ - int I.M() - { - return 0; - } - - int I2.M2() - { - return 0; - } -} - -class B : [|I|], I2 -{ - A a; -}", -count: 3); - await TestActionCountAsync( -@"interface I -{ - int M(); + int M2(); } -interface I2 -{ - int M2() } - class A : I, I2 { int I.M() @@ -2208,47 +2298,24 @@ int I2.M2() } } -class B : I, [|I2|] +class B : {|CS0535:I|}, {|CS0535:I2|} { A a; }", -count: 3); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } interface I2 { - int M2() } - -class A : I, I2 -{ - int I.M() - { - return 0; - } - - int I2.M2() - { - return 0; - } -} - -class B : [|I|], I2 -{ - A a; -}", -@"interface I -{ - int M(); + int M2(); } -interface I2 -{ - int M2() } - class A : I, I2 { int I.M() @@ -2262,7 +2329,7 @@ int I2.M2() } } -class B : I, I2 +class B : I, {|CS0535:I2|} { A a; @@ -2271,16 +2338,28 @@ public int M() return ((I)a).M(); } }", -index: 1); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + DiagnosticSelector = diagnostics => diagnostics[0], + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", + CodeActionIndex = 1, + }.RunAsync(); + + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I, I2 { @@ -2295,18 +2374,23 @@ int I2.M2() } } -class B : I, [|I2|] +class B : {|CS0535:I|}, {|CS0535:I2|} { A a; }", -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I, I2 { @@ -2321,7 +2405,7 @@ int I2.M2() } } -class B : I, I2 +class B : {|CS0535:I|}, I2 { A a; @@ -2330,35 +2414,25 @@ public int M2() return ((I2)a).M2(); } }", -index: 1); + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + DiagnosticSelector = diagnostics => diagnostics[1], + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "False;False;False:global::I2;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", + CodeActionIndex = 1, + }.RunAsync(); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceThroughField_MultipleFieldsCanImplementInterface() { - await TestActionCountAsync( -@"interface I -{ - int M(); -} - -class A : I -{ - int I.M() - { - return 0; - } -} - -class B : [|I|] -{ - A a; - A aa; -}", -count: 4); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } @@ -2371,12 +2445,16 @@ int I.M() } } -class B : [|I|] +class B : {|CS0535:I|} { A a; A aa; }", -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } @@ -2399,9 +2477,18 @@ public int M() return ((I)a).M(); } }", -index: 1); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(4, codeActions.Length), + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", + CodeActionIndex = 1, + }.RunAsync(); + + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } @@ -2414,12 +2501,16 @@ int I.M() } } -class B : [|I|] +class B : {|CS0535:I|} { A a; A aa; }", -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } @@ -2442,22 +2533,31 @@ public int M() return ((I)aa).M(); } }", -index: 2); + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(4, codeActions.Length), + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;aa", + CodeActionIndex = 2, + }.RunAsync(); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceThroughField_MultipleFieldsForMultipleInterfaces() { - await TestActionCountAsync( -@"interface I + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I { @@ -2475,21 +2575,24 @@ int I2.M2() } } -class C : [|I|], I2 +class C : {|CS0535:I|}, {|CS0535:I2|} { A a; B b; }", -count: 3); - await TestActionCountAsync( -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I { @@ -2507,21 +2610,38 @@ int I2.M2() } } -class C : I, [|I2|] +class C : I, {|CS0535:I2|} { A a; B b; + + public int M() + { + return ((I)a).M(); + } }", -count: 3); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + DiagnosticSelector = diagnostics => diagnostics[0], + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "False;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;a", + CodeActionIndex = 1, + }.RunAsync(); + + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I { @@ -2539,19 +2659,24 @@ int I2.M2() } } -class C : [|I|], I2 +class C : {|CS0535:I|}, {|CS0535:I2|} { A a; B b; }", -@"interface I + FixedState = + { + Sources = + { + @"interface I { int M(); } interface I2 { - int M2() } + int M2(); +} class A : I { @@ -2569,57 +2694,81 @@ int I2.M2() } } -class C : I, I2 +class C : {|CS0535:I|}, I2 { A a; B b; - public int M() + public int M2() { - return ((I)a).M(); + return ((I2)b).M2(); } }", -index: 1); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + DiagnosticSelector = diagnostics => diagnostics[1], + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "False;False;False:global::I2;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;b", + CodeActionIndex = 1, + }.RunAsync(); + } + + [WorkItem(18556, "https://github.com/dotnet/roslyn/issues/18556")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] + public async Task TestImplementInterfaceThroughExplicitProperty() + { + await new VerifyCS.Test + { + TestCode = @"interface IA +{ + IB B { get; } +} +interface IB { int M(); } - -interface I2 +class AB : IA, {|CS0535:IB|} { - int M2() } - -class A : I + IB IA.B => null; +}", + FixedCode = @"interface IA { - int I.M() - { - return 0; - } + IB B { get; } } - -class B : I2 +interface IB { - int I2.M2() - { - return 0; - } + int M(); } - -class C : I, [|I2|] +class AB : IA, IB { - A a; - B b; + IB IA.B => null; + + public int M() + { + return ((IA)this).B.M(); + } }", -@"interface I + Options = { AllOptionsOff }, + CodeActionsVerifier = codeActions => Assert.Equal(3, codeActions.Length), + CodeActionEquivalenceKey = "False;False;False:global::IB;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;IA.B", + CodeActionIndex = 1, + }.RunAsync(); + } + + [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] + public async Task TestNoImplementThroughIndexer() + { + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } -interface I2 -{ - int M2() } - class A : I { int I.M() @@ -2628,83 +2777,55 @@ int I.M() } } -class B : I2 +class B : {|CS0535:I|} { - int I2.M2() - { - return 0; - } -} - -class C : I, I2 -{ - A a; - B b; - - public int M2() + A this[int index] { - return ((I2)b).M2(); - } -}", -index: 1); - } - - [WorkItem(18556, "https://github.com/dotnet/roslyn/issues/18556")] - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] - public async Task TestImplementInterfaceThroughExplicitProperty() + get { - await TestActionCountAsync( -@"interface IA -{ - IB B { get; } -} -interface IB -{ - int M(); -} -class AB : IA, [|IB|] -{ - IB IA.B => null; + return null; + } + } }", -count: 3); - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IA -{ - IB B { get; } -} -interface IB + FixedCode = @"interface I { int M(); } -class AB : IA, [|IB|] -{ - IB IA.B => null; -}", -@"interface IA -{ - IB B { get; } -} -interface IB + +class A : I { - int M(); + int I.M() + { + return 0; + } } -class AB : IA, [|IB|] + +class B : I { - IB IA.B => null; + A this[int index] + { + get + { + return null; + } + } public int M() { - return ((IA)this).B.M(); + throw new System.NotImplementedException(); } -}", index: 1); +}", + CodeActionsVerifier = codeActions => Assert.Equal(2, codeActions.Length), + }.RunAsync(); } [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] - public async Task TestNoImplementThroughIndexer() + public async Task TestNoImplementThroughWriteOnlyProperty() { - await TestActionCountAsync( -@"interface I + await new VerifyCS.Test + { + TestCode = @"interface I { int M(); } @@ -2717,25 +2838,16 @@ int I.M() } } -class B : [|I|] +class B : {|CS0535:I|} { - A this[int index] + A a { - get + set { - return null; } - }; + } }", -count: 2); - } - - [WorkItem(768799, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768799")] - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] - public async Task TestNoImplementThroughWriteOnlyProperty() - { - await TestActionCountAsync( -@"interface I + FixedCode = @"interface I { int M(); } @@ -2748,7 +2860,7 @@ int I.M() } } -class B : [|I|] +class B : {|CS0535:I|} { A a { @@ -2756,8 +2868,14 @@ A a { } } + + public int M() + { + throw new System.NotImplementedException(); + } }", -count: 2); + CodeActionsVerifier = codeActions => Assert.Equal(2, codeActions.Length), + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -2771,10 +2889,10 @@ interface IGoo class CanGoo : IGoo { - public event EventHandler E; + public event System.EventHandler E; } -class HasCanGoo : [|IGoo|] +class HasCanGoo : {|CS0535:IGoo|} { CanGoo canGoo; }", @@ -2788,7 +2906,7 @@ interface IGoo class CanGoo : IGoo { - public event EventHandler E; + public event System.EventHandler E; } class HasCanGoo : IGoo @@ -2807,17 +2925,17 @@ public event EventHandler E ((IGoo)canGoo).E -= value; } } -}", index: 1); +}", codeAction: ("False;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;canGoo", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementEventThroughExplicitMember() { await TestInRegularAndScriptAsync( -@"interface IGoo { event System . EventHandler E ; } class CanGoo : IGoo { event IGoo.EventHandler E; } class HasCanGoo : [|IGoo|] { CanGoo canGoo; } ", +@"interface IGoo { event System . EventHandler E ; } class CanGoo : IGoo { event System.EventHandler IGoo.E { add { } remove { } } } class HasCanGoo : {|CS0535:IGoo|} { CanGoo canGoo; } ", @"using System; -interface IGoo { event System . EventHandler E ; } class CanGoo : IGoo { event IGoo.EventHandler E; } class HasCanGoo : IGoo { CanGoo canGoo; +interface IGoo { event System . EventHandler E ; } class CanGoo : IGoo { event System.EventHandler IGoo.E { add { } remove { } } } class HasCanGoo : IGoo { CanGoo canGoo; public event EventHandler E { @@ -2832,7 +2950,7 @@ public event EventHandler E } } } ", -index: 1); +codeAction: ("False;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;canGoo", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -2844,7 +2962,7 @@ await TestWithAllCodeStyleOptionsOffAsync( event System.EventHandler E; } -abstract class Goo : [|IGoo|] +abstract class Goo : {|CS0535:IGoo|} { }", @"using System; @@ -2858,7 +2976,7 @@ abstract class Goo : IGoo { public event EventHandler E; }", -index: 0); +codeAction: ("False;False;True:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 0)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -2870,7 +2988,7 @@ await TestWithAllCodeStyleOptionsOffAsync( event System.EventHandler E; } -abstract class Goo : [|IGoo|] +abstract class Goo : {|CS0535:IGoo|} { }", @"using System; @@ -2884,7 +3002,7 @@ abstract class Goo : IGoo { public abstract event EventHandler E; }", -index: 1); +codeAction: ("False;True;True:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -2896,7 +3014,7 @@ await TestWithAllCodeStyleOptionsOffAsync( event System.EventHandler E; } -abstract class Goo : [|IGoo|] +abstract class Goo : {|CS0535:IGoo|} { }", @"using System; @@ -2921,44 +3039,49 @@ event EventHandler IGoo.E } } }", -index: 2); +codeAction: ("True;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 2)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestFaultToleranceInStaticMembers_01() { - await TestMissingAsync( -@"interface IFoo + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IFoo { static string Name { set; get; } - static int Foo(string s); + static int {|CS0501:Foo|}(string s); } -class Program : [|IFoo|] +class Program : IFoo { -}"); +}", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestFaultToleranceInStaticMembers_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IFoo + var test = new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IFoo { string Name { set; get; } - static int Foo(string s); + static int {|CS0501:Foo|}(string s); } -class Program : [|IFoo|] +class Program : {|CS0535:IFoo|} { }", -@"interface IFoo + FixedCode = @"interface IFoo { string Name { set; get; } - static int Foo(string s); + static int {|CS0501:Foo|}(string s); } class Program : IFoo @@ -2975,24 +3098,30 @@ public string Name throw new System.NotImplementedException(); } } -}"); +}", + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestFaultToleranceInStaticMembers_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IGoo + var test = new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IGoo { static string Name { set; get; } int Goo(string s); } -class Program : [|IGoo|] +class Program : {|CS0535:IGoo|} { }", -@"interface IGoo + FixedCode = @"interface IGoo { static string Name { set; get; } @@ -3005,7 +3134,11 @@ public int Goo(string s) { throw new System.NotImplementedException(); } -}"); +}", + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -3017,7 +3150,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int this[int index] { get; set; } } -class IndexerClass : [|ISomeInterface|] +class IndexerClass : {|CS0535:ISomeInterface|} { }", @"public interface ISomeInterface @@ -3051,7 +3184,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int this[int index] { get; set; } } -class IndexerClass : [|ISomeInterface|] +class IndexerClass : {|CS0535:ISomeInterface|} { }", @"public interface ISomeInterface @@ -3074,7 +3207,7 @@ int ISomeInterface.this[int index] } } }", -index: 1); +codeAction: ("True;False;False:global::ISomeInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -3086,7 +3219,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int this[int index] { get; } } -class IndexerClass : [|ISomeInterface|] +class IndexerClass : {|CS0535:ISomeInterface|} { }", @"public interface ISomeInterface @@ -3116,7 +3249,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : class; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"interface I @@ -3143,7 +3276,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : class; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"interface I @@ -3158,7 +3291,7 @@ void I.Goo() throw new System.NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(542357, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542357")] @@ -3171,7 +3304,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : System.Attribute; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3200,7 +3333,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int this[int x] { get; set; } } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -3237,7 +3370,7 @@ interface I void Goo() where T : IComparable; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3268,7 +3401,7 @@ interface I void Goo() where T : IComparable; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3285,7 +3418,7 @@ void I.Goo() throw new NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(542587, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542587")] @@ -3298,7 +3431,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"interface I @@ -3325,7 +3458,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"interface I @@ -3352,7 +3485,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"interface I @@ -3367,7 +3500,7 @@ void I.Goo() throw new System.NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(542587, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542587")] @@ -3382,7 +3515,7 @@ interface I void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3413,7 +3546,7 @@ interface I void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3446,7 +3579,7 @@ interface I delegate void Bar(); -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3479,7 +3612,7 @@ interface I void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3510,7 +3643,7 @@ interface I void Goo() where T : class, S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3545,7 +3678,7 @@ enum E { } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3561,7 +3694,7 @@ enum E class A : I { - void I.Goo() + void I.Goo<{|CS0455:T|}>() { throw new NotImplementedException(); } @@ -3580,7 +3713,7 @@ interface I void Goo() where T : S; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3611,7 +3744,7 @@ interface I void Goo() where T : S; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3642,7 +3775,7 @@ interface I void Goo() where T : Exception, S; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3654,7 +3787,7 @@ interface I class C : I { - void I.Goo() + void I.Goo<{|CS0455:T|}>() { throw new NotImplementedException(); } @@ -3673,7 +3806,7 @@ interface I void Goo() where T : class, S; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3705,7 +3838,7 @@ interface I void Goo(T x, IList list) where S : T; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3738,7 +3871,7 @@ interface I void Goo(T x, IList list) where S : T; } -class A : [|I|] +class A : {|CS0535:I|} { }", @"using System; @@ -3756,7 +3889,7 @@ void I.Goo(S x, IList list) throw new NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(542505, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542505")] @@ -3774,7 +3907,7 @@ void Goo(X x, Y y, IList list1, IList list2) where B : IList; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3813,7 +3946,7 @@ void Goo(X x, Y y, IList list1, IList list2) where B : IList; } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -3833,7 +3966,7 @@ void I.Goo(A x, B y, IList list1, IList list2) throw new NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(542506, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542506")] @@ -3854,7 +3987,7 @@ interface I void Goo(B x); } - class C : [|I|] + class C : {|CS0535:I|} { } }", @@ -3897,7 +4030,7 @@ interface I void Goo(B[] x); } - class C : [|I|] + class C : {|CS0535:I|} { } }", @@ -3938,7 +4071,7 @@ interface I void Goo(B[][,][,,][,,,] x); } - class C : [|I|] + class C : {|CS0535:I|} { } }", @@ -3973,7 +4106,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int Gibberish { get; set; } } -abstract class Goo : [|IGoo|] +abstract class Goo : {|CS0535:IGoo|} { }", @"interface IGoo @@ -3985,22 +4118,24 @@ abstract class Goo : IGoo { public abstract int Gibberish { get; set; } }", -index: 1); +codeAction: ("False;True;True:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(544210, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544210")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestMissingOnWrongArity() { - await TestMissingInRegularAndScriptAsync( + var code = @"interface I1 { int X { get; set; } } -class C : [|I1|] +class C : {|CS0305:I1|} { -}"); +}"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [WorkItem(544281, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544281")] @@ -4013,7 +4148,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int Goo(int g = 0); } -class Opt : [|IOptional|] +class Opt : {|CS0535:IOptional|} { }", @"interface IOptional @@ -4040,7 +4175,7 @@ await TestWithAllCodeStyleOptionsOffAsync( int Goo(int g = 0); } -class Opt : [|IOptional|] +class Opt : {|CS0535:IOptional|} { }", @"interface IOptional @@ -4055,20 +4190,22 @@ int IOptional.Goo(int g) throw new System.NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::IOptional;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestMissingInHiddenType() { - await TestMissingInRegularAndScriptAsync( + var code = @"using System; -class Program : [|IComparable|] +class Program : {|CS0535:IComparable|} { #line hidden } -#line default"); +#line default"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -4078,7 +4215,7 @@ await TestWithAllCodeStyleOptionsOffAsync( @"#line default using System; -partial class Program : [|IComparable|] +partial class Program : {|CS0535:IComparable|} { void Goo() { @@ -4110,7 +4247,7 @@ public async Task TestGenerateIfAvailableRegionExists() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -partial class Program : [|IComparable|] +partial class Program : {|CS0535:IComparable|} { #line hidden } @@ -4140,23 +4277,26 @@ public int CompareTo(object obj) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNoGenerateInVenusCase1() { - await TestMissingInRegularAndScriptAsync( + var code = @"using System; #line 1 ""Bar"" -class Goo : [|IComparable|] +class Goo : {|CS0535:IComparable|}{|CS1513:|}{|CS1514:|} #line default #line hidden -// stuff"); +// stuff"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [WorkItem(545476, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545476")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestOptionalDateTime1() { - await TestWithAllCodeStyleOptionsOffAsync( -@"using System; + await new VerifyCS.Test + { + TestCode = @"using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -4165,10 +4305,10 @@ interface IGoo void Goo([Optional][DateTimeConstant(100)] DateTime x); } -public class C : [|IGoo|] +public class C : {|CS0535:IGoo|} { }", -@"using System; + FixedCode = @"using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -4183,7 +4323,12 @@ public void Goo([DateTimeConstant(100), Optional] DateTime x) { throw new NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + + // 🐛 one value is generated with 0L instead of 0 + CodeActionValidationMode = CodeActionValidationMode.None, + }.RunAsync(); } [WorkItem(545476, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545476")] @@ -4200,7 +4345,7 @@ interface IGoo void Goo([Optional][DateTimeConstant(100)] DateTime x); } -public class C : [|IGoo|] +public class C : {|CS0535:IGoo|} { }", @"using System; @@ -4219,7 +4364,7 @@ void IGoo.Goo(DateTime x) throw new NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(545477, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545477")] @@ -4236,7 +4381,7 @@ interface IGoo void Goo2([Optional][IDispatchConstant] object x); } -public class C : [|IGoo|] +public class C : {|CS0535:{|CS0535:IGoo|}|} { }", @"using System.Runtime.CompilerServices; @@ -4276,7 +4421,7 @@ interface IGoo void Goo2([Optional][IDispatchConstant] object x); } -public class C : [|IGoo|] +public class C : {|CS0535:{|CS0535:IGoo|}|} { }", @"using System.Runtime.CompilerServices; @@ -4300,7 +4445,7 @@ void IGoo.Goo2(object x) throw new System.NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::IGoo;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(545464, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545464")] @@ -4313,7 +4458,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(); } -public class Goo : [|IGoo|] +public class Goo : {|CS0535:IGoo|} { }", @"interface IGoo @@ -4334,7 +4479,7 @@ void IGoo.Goo() public async Task TestStringLiteral() { await TestWithAllCodeStyleOptionsOffAsync( -@"interface IGoo { void Goo ( string s = ""\"""" ) ; } class B : [|IGoo|] { } ", +@"interface IGoo { void Goo ( string s = ""\"""" ) ; } class B : {|CS0535:IGoo|} { } ", @"interface IGoo { void Goo ( string s = ""\"""" ) ; } class B : IGoo { @@ -4359,7 +4504,7 @@ interface d void m(b? x = null, b? y = default(b?)); } -class c : [|d|] +class c : {|CS0535:d|} { }", @"struct b @@ -4394,7 +4539,7 @@ interface d void m(b? x = null, b? y = default(b?)); } -class c : [|d|] +class c : {|CS0535:d|} { }", @"struct b @@ -4412,7 +4557,7 @@ void d.m(b? x, b? y) { throw new System.NotImplementedException(); } -}", 1); +}", codeAction: ("True;False;False:global::d;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(916114, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/916114")] @@ -4425,7 +4570,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void m(int? x = 5, int? y = null); } -class c : [|d|] +class c : {|CS0535:d|} { }", @"interface d @@ -4454,7 +4599,7 @@ interface I void Goo([Optional] I o); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -4476,8 +4621,9 @@ public void Goo([Optional] I o) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestIntegralAndFloatLiterals() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface I + await new VerifyCS.Test + { + TestCode = @"interface I { void M01(short s = short.MinValue); void M02(short s = -1); @@ -4505,10 +4651,10 @@ await TestWithAllCodeStyleOptionsOffAsync( void M24(double s = double.MaxValue); } -class C : [|I|] +class C : {|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:I|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|}|} { }", -@"interface I + FixedCode = @"interface I { void M01(short s = short.MinValue); void M02(short s = -1); @@ -4657,7 +4803,12 @@ public void M24(double s = double.MaxValue) { throw new System.NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + + // 🐛 one value is generated with 0U instead of 0 + CodeActionValidationMode = CodeActionValidationMode.None, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -4685,7 +4836,7 @@ interface I void M2(FlagE e = FlagE.A | FlagE.B); } -class C : [|I|] +class C : {|CS0535:{|CS0535:I|}|} { }", @"using System; @@ -4744,7 +4895,7 @@ interface I void M11(char c = '\u2029'); } -class C : [|I|] +class C : {|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:I|}|}|}|}|}|}|}|}|}|}|} { }", @"using System; @@ -4835,7 +4986,7 @@ interface I void Goo(DayOfWeek x = DayOfWeek.Friday); } -class C : [|I|] +class C : {|CS0535:I|} { DayOfWeek DayOfWeek { get; set; } }", @@ -4867,7 +5018,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(decimal x = decimal.MaxValue); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -4894,7 +5045,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(decimal? x = decimal.MaxValue); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -4923,7 +5074,7 @@ interface I void Goo(DayOfWeek? x = DayOfWeek.Friday); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -4952,7 +5103,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(byte x = 1); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -4980,7 +5131,7 @@ interface I void Goo(ConsoleColor x = (ConsoleColor)(-1)); } -class C : [|I|] +class C : {|CS0535:I|} { }"; @@ -5014,7 +5165,7 @@ interface I void Goo(ConsoleColor x = (ConsoleColor)int.MaxValue); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System; @@ -5048,7 +5199,7 @@ interface I void Goo(E x = 0); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"enum E @@ -5082,7 +5233,7 @@ interface I void Goo([Optional][DefaultParameterValue(1)] int x, int[,] y); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -5094,7 +5245,7 @@ interface I class C : I { - public void Goo([DefaultParameterValue(1), Optional] int x = 1, int[,] y = null) + public void Goo([{|CS1745:DefaultParameterValue|}(1), {|CS1745:Optional|}] int x = {|CS8017:1|}, int[,] y = null) { throw new System.NotImplementedException(); } @@ -5113,7 +5264,7 @@ interface I void Goo([Optional, DefaultParameterValue(1)] int x, int[] y, int[] z); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -5125,7 +5276,7 @@ interface I class C : I { - public void Goo([DefaultParameterValue(1), Optional] int x = 1, int[] y = null, int[] z = null) + public void Goo([{|CS1745:DefaultParameterValue|}(1), {|CS1745:Optional|}] int x = {|CS8017:1|}, int[] y = null, int[] z = null) { throw new System.NotImplementedException(); } @@ -5136,7 +5287,9 @@ public void Goo([DefaultParameterValue(1), Optional] int x = 1, int[] y = null, [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestAttributeInParameter() { - await TestWithAllCodeStyleOptionsOffAsync( + var test = new VerifyCS.Test + { + TestCode = @"using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -5145,10 +5298,11 @@ interface I { void Goo([Optional][DateTimeConstant(100)] DateTime d1, [Optional][IUnknownConstant] object d2); } -class C : [|I|] +class C : {|CS0535:I|} { } ", + FixedCode = @"using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -5164,7 +5318,13 @@ public void Goo([DateTimeConstant(100), Optional] DateTime d1, [IUnknownConstant throw new NotImplementedException(); } } -"); +", + // 🐛 the DateTimeConstant attribute is generated with 100L instead of 100 + CodeActionValidationMode = CodeActionValidationMode.None, + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [WorkItem(545897, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545897")] @@ -5177,7 +5337,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void T1(S x, T y); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -5206,7 +5366,7 @@ interface I void Goo(S y, List.Enumerator x); } -class D : [|I|] +class D : {|CS0535:I|} { }", @"using System.Collections.Generic; @@ -5235,7 +5395,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(float x = 1E10F); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -5262,7 +5422,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo<@class>(); } -class C : [|I|]", +class C : {|CS0535:I|}{|CS1513:|}{|CS1514:|}", @"interface I { void Goo<@class>(); @@ -5289,7 +5449,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo2(decimal x = -1E28M); } -class C : [|I|] +class C : {|CS0535:{|CS0535:I|}|} { }", @"interface I @@ -5322,7 +5482,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(decimal x = 0.1M); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -5347,8 +5507,8 @@ await TestWithAllCodeStyleOptionsOffAsync( @"using System; // Implement interface -class C : [|IServiceProvider|] /* -", +class C : {|CS0535:IServiceProvider|} {|CS1035:|}/* +{|CS1513:|}{|CS1514:|}", @"using System; // Implement interface @@ -5371,7 +5531,7 @@ await TestWithAllCodeStyleOptionsOffAsync( @"using System; // Implement interface -class C : [|IServiceProvider|] +class C : {|CS0535:IServiceProvider|}{|CS1513:|}{|CS1514:|} #pragma warning disable ", @"using System; @@ -5395,7 +5555,7 @@ public async Task TestCommentAfterInterfaceList1() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] // Implement interface +class C : {|CS0535:IServiceProvider|}{|CS1513:|}{|CS1514:|} // Implement interface ", @"using System; @@ -5416,7 +5576,7 @@ public async Task TestCommentAfterInterfaceList2() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] +class C : {|CS0535:IServiceProvider|}{|CS1513:|}{|CS1514:|} // Implement interface ", @"using System; @@ -5439,7 +5599,7 @@ public async Task TestImplementIDisposable_NoDisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IDisposable|]", +class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", @"using System; class C : IDisposable { @@ -5448,7 +5608,7 @@ public void Dispose() throw new NotImplementedException(); } } -", index: 0); +", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 0)); } [WorkItem(994456, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")] @@ -5458,7 +5618,7 @@ public async Task TestImplementIDisposable_DisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IDisposable|]", +class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", $@"using System; class C : IDisposable {{ @@ -5466,7 +5626,7 @@ class C : IDisposable {DisposePattern("protected virtual ", "C", "public void ")} }} -", index: 1); +", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 1)); } [WorkItem(994456, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")] @@ -5476,7 +5636,7 @@ public async Task TestImplementIDisposableExplicitly_NoDisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IDisposable|]", +class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", @"using System; class C : IDisposable { @@ -5485,7 +5645,7 @@ void IDisposable.Dispose() throw new NotImplementedException(); } } -", index: 2); +", codeAction: ("True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 2)); } [WorkItem(994456, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")] @@ -5495,7 +5655,7 @@ public async Task TestImplementIDisposableExplicitly_DisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|System.IDisposable|] +class C : {|CS0535:System.IDisposable|} { class IDisposable { @@ -5511,7 +5671,7 @@ class IDisposable }} {DisposePattern("protected virtual ", "C", "void System.IDisposable.")} -}}", index: 3); +}}", codeAction: ("True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 3)); } [WorkItem(994456, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")] @@ -5521,13 +5681,13 @@ public async Task TestImplementIDisposableAbstractly_NoDisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -abstract class C : [|IDisposable|]", +abstract class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", @"using System; abstract class C : IDisposable { public abstract void Dispose(); } -", index: 2); +", codeAction: ("False;True;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 2)); } [WorkItem(994456, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")] @@ -5537,7 +5697,7 @@ public async Task TestImplementIDisposableThroughMember_NoDisposePattern() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IDisposable|] +class C : {|CS0535:IDisposable|} { private IDisposable goo; }", @@ -5550,22 +5710,29 @@ public void Dispose() { goo.Dispose(); } -}", index: 2); +}", codeAction: ("False;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;goo", 2)); } [WorkItem(941469, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/941469")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementIDisposableExplicitly_NoNamespaceImportForSystem() { - await TestWithAllCodeStyleOptionsOffAsync( -@"class C : [|System.IDisposable|]", -$@"class C : System.IDisposable + await new VerifyCS.Test + { + TestCode = @"class C : {|CS0535:System.IDisposable|}{|CS1513:|}{|CS1514:|}", + FixedCode = $@"class C : System.IDisposable {{ private bool disposedValue; {DisposePattern("protected virtual ", "C", "void System.IDisposable.", gcPrefix: "System.")} }} -", index: 3); +", + CodeActionEquivalenceKey = "True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", + CodeActionIndex = 3, + + // 🐛 generated QualifiedName where SimpleMemberAccessExpression was expected + CodeActionValidationMode = CodeActionValidationMode.None, + }.RunAsync(); } [WorkItem(951968, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/951968")] @@ -5578,7 +5745,7 @@ interface I : IDisposable { void F(); } -class C : [|I|] +class C : {|CS0535:{|CS0535:I|}|} { }", @"using System; @@ -5597,7 +5764,7 @@ public void F() { throw new NotImplementedException(); } -}", index: 0); +}", codeAction: ("False;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 0)); } [WorkItem(951968, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/951968")] @@ -5610,7 +5777,7 @@ interface I : IDisposable { void F(); } -class C : [|I|] +class C : {|CS0535:{|CS0535:I|}|} { }", $@"using System; @@ -5628,7 +5795,7 @@ public void F() }} {DisposePattern("protected virtual ", "C", "public void ")} -}}", index: 1); +}}", codeAction: ("False;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 1)); } [WorkItem(951968, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/951968")] @@ -5641,7 +5808,7 @@ interface I : IDisposable { void F(); } -class C : [|I|] +class C : {|CS0535:{|CS0535:I|}|} { }", $@"using System; @@ -5659,7 +5826,7 @@ void I.F() }} {DisposePattern("protected virtual ", "C", "void IDisposable.")} -}}", index: 3); +}}", codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 3)); } [WorkItem(941469, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/941469")] @@ -5674,7 +5841,7 @@ interface IDisposable void Dispose(); } - class C : [|IDisposable|] + class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|} }", @"namespace System { @@ -5690,7 +5857,7 @@ void IDisposable.Dispose() throw new NotImplementedException(); } } -}", index: 1); +}", codeAction: ("True;False;False:global::System.IDisposable;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -5698,7 +5865,7 @@ public async Task TestDontImplementDisposePatternForStructures1() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -struct S : [|IDisposable|]", +struct S : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", @"using System; struct S : IDisposable { @@ -5715,7 +5882,7 @@ public async Task TestDontImplementDisposePatternForStructures2() { await TestWithAllCodeStyleOptionsOffAsync( @"using System; -struct S : [|IDisposable|]", +struct S : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}", @"using System; struct S : IDisposable { @@ -5724,15 +5891,16 @@ void IDisposable.Dispose() throw new NotImplementedException(); } } -", index: 1); +", codeAction: ("True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(545924, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545924")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestEnumNestedInGeneric() { - await TestWithAllCodeStyleOptionsOffAsync( -@"class C + var test = new VerifyCS.Test() + { + TestCode = @"class C { public enum E { @@ -5745,10 +5913,10 @@ interface I void Goo(C.E x = C.E.X); } -class D : [|I|] +class D : {|CS0535:I|} { }", -@"class C + FixedCode = @"class C { public enum E { @@ -5767,7 +5935,13 @@ public void Goo(C.E x = C.E.X) { throw new System.NotImplementedException(); } -}"); +}", + // 🐛 generated QualifiedName where SimpleMemberAccessExpression was expected + CodeActionValidationMode = CodeActionValidationMode.None, + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [WorkItem(545939, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")] @@ -5777,10 +5951,10 @@ public async Task TestUnterminatedString1() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] @""", +class C : {|CS0535:IServiceProvider|} {|CS1039:|}@""{|CS1513:|}{|CS1514:|}", @"using System; -class C : IServiceProvider @""""{ +class C : IServiceProvider {|CS1003:@""""|}{ public object GetService(Type serviceType) { throw new NotImplementedException(); @@ -5796,10 +5970,10 @@ public async Task TestUnterminatedString2() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] """, +class C : {|CS0535:IServiceProvider|} {|CS1010:|}""{|CS1513:|}{|CS1514:|}", @"using System; -class C : IServiceProvider """"{ +class C : IServiceProvider {|CS1003:""""|}{ public object GetService(Type serviceType) { throw new NotImplementedException(); @@ -5815,10 +5989,10 @@ public async Task TestUnterminatedString3() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] @""", +class C : {|CS0535:IServiceProvider|} {|CS1039:|}@""{|CS1513:|}{|CS1514:|}", @"using System; -class C : IServiceProvider @""""{ +class C : IServiceProvider {|CS1003:@""""|}{ public object GetService(Type serviceType) { throw new NotImplementedException(); @@ -5834,10 +6008,10 @@ public async Task TestUnterminatedString4() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class C : [|IServiceProvider|] """, +class C : {|CS0535:IServiceProvider|} {|CS1010:|}""{|CS1513:|}{|CS1514:|}", @"using System; -class C : IServiceProvider """"{ +class C : IServiceProvider {|CS1003:""""|}{ public object GetService(Type serviceType) { throw new NotImplementedException(); @@ -5859,7 +6033,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo4(decimal x = -1E-24M); } -class C : [|I|] +class C : {|CS0535:{|CS0535:{|CS0535:{|CS0535:I|}|}|}|} { }", @"interface I @@ -5898,8 +6072,9 @@ public void Goo4(decimal x = -0.000000000000000000000001M) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestGenericEnumWithRenamedTypeParameters() { - await TestWithAllCodeStyleOptionsOffAsync( -@"class C + var test = new VerifyCS.Test + { + TestCode = @"class C { public enum E { @@ -5912,10 +6087,10 @@ interface I void Goo(S y, C.E x = C.E.X); } -class D : [|I|] +class D : {|CS0535:I|} { }", -@"class C + FixedCode = @"class C { public enum E { @@ -5934,7 +6109,13 @@ public void Goo(T y, C.E x = C.E.X) { throw new System.NotImplementedException(); } -}"); +}", + // 🐛 generated QualifiedName where SimpleMemberAccessExpression was expected + CodeActionValidationMode = CodeActionValidationMode.None, + }; + + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [WorkItem(545919, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545919")] @@ -5947,7 +6128,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(S T1); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -5977,7 +6158,7 @@ interface I bool Goo([MarshalAs(UnmanagedType.U1)] bool x); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -6011,7 +6192,7 @@ interface I bool Goo([MarshalAs(UnmanagedType.U1)] bool x); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -6029,7 +6210,7 @@ bool I.Goo(bool x) throw new System.NotImplementedException(); } }", -index: 1); +codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(546443, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546443")] @@ -6044,7 +6225,7 @@ interface IGoo void Bar(DateTime DateTime); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { }", @"using System; @@ -6077,7 +6258,7 @@ interface I void Goo(); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Collections.Generic; @@ -6112,7 +6293,7 @@ public interface I } } -class C : [|N.I|] +class C : {|CS0535:N.I|} { }", @"namespace N @@ -6145,7 +6326,7 @@ public interface I } } -class C : [|N.I|] +class C : {|CS0535:N.I|} { }", @"using N; @@ -6164,7 +6345,7 @@ void I.M() { throw new System.NotImplementedException(); } -}", index: 1); +}", codeAction: ("True;False;False:global::N.I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(847464, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/847464")] @@ -6181,7 +6362,7 @@ partial class C { } -partial class C : [|I|] +partial class C : {|CS0535:I|} { }", @"public interface I @@ -6199,7 +6380,7 @@ void I.Goo() { throw new System.NotImplementedException(); } -}", index: 1); +}", codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(847464, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/847464")] @@ -6212,7 +6393,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void Goo(); } -partial class C : [|I|] +partial class C : {|CS0535:I|} { } @@ -6234,15 +6415,16 @@ void I.Goo() partial class C { -}", index: 1); +}", codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(847464, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/847464")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceForPartialType3() { - await TestWithAllCodeStyleOptionsOffAsync( -@"public interface I + await new VerifyCS.Test + { + TestCode = @"public interface I { void Goo(); } @@ -6252,14 +6434,18 @@ public interface I2 void Goo2(); } -partial class C : [|I|] +partial class C : {|CS0535:I|} { } -partial class C : I2 +partial class C : {|CS0535:I2|} { }", -@"public interface I + FixedState = + { + Sources = + { + @"public interface I { void Goo(); } @@ -6277,35 +6463,57 @@ void I.Goo() } } -partial class C : I2 +partial class C : {|CS0535:I2|} { -}", index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [WorkItem(752447, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/752447")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestExplicitImplOfIndexedProperty() { - var initial = @" - - - + var test = new VerifyCS.Test + { + TestState = + { + Sources = + { + @" +public class Test : {|CS0535:{|CS0535:IGoo|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1", LanguageNames.VisualBasic] = + { + Sources = + { + @" Public Interface IGoo Property IndexProp(ByVal p1 As Integer) As String -End Interface - - - - Assembly1 - -public class Test : [|IGoo|] -{ -} - - -"; - - var expected = @" +End Interface", + }, + }, + }, + AdditionalProjectReferences = + { + "Assembly1", + }, + }, + FixedState = + { + Sources = + { + @" public class Test : IGoo { string IGoo.get_IndexProp(int p1) @@ -6317,39 +6525,52 @@ void IGoo.set_IndexProp(int p1, string Value) { throw new System.NotImplementedException(); } -} - "; +}", + }, + }, + CodeActionEquivalenceKey = "True;False;False:global::IGoo;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }; - await TestWithAllCodeStyleOptionsOffAsync(initial, expected, index: 1); + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } [WorkItem(602475, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/602475")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplicitImplOfIndexedProperty() { - var initial = @" - - - -Public Interface I + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"using System; + +class C : {|CS0535:{|CS0535:I|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1", LanguageNames.VisualBasic] = + { + Sources = + { + @"Public Interface I Property P(x As Integer) -End Interface - - - - Assembly1 - -using System; - -class C : [|I|] -{ -} - - -"; - - var expected = @" -using System; +End Interface", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"using System; class C : I { @@ -6362,40 +6583,56 @@ public void set_P(int x, object Value) { throw new NotImplementedException(); } -} - "; - - await TestWithAllCodeStyleOptionsOffAsync(initial, expected, index: 0); +}", + }, + }, + CodeActionEquivalenceKey = "False;False;True:global::I;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementationOfIndexerWithInaccessibleAttributes() { - var initial = @" - - - + var test = new VerifyCS.Test + { + TestState = + { + Sources = + { + @" +using System; + +class C : {|CS0535:I|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @" using System; internal class ShouldBeRemovedAttribute : Attribute { } public interface I { string this[[ShouldBeRemovedAttribute] int i] { get; set; } -} - - - - Assembly1 - -using System; - -class C : [|I|] -{ -} - - -"; - - var expected = @" +}" + }, + }, + }, + AdditionalProjectReferences = + { + "Assembly1", + }, + }, + FixedState = + { + Sources = + { + @" using System; class C : I @@ -6412,10 +6649,15 @@ public string this[int i] throw new NotImplementedException(); } } -} - "; +}", + }, + }, + CodeActionEquivalenceKey = "False;False;True:global::I;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }; - await TestWithAllCodeStyleOptionsOffAsync(initial, expected, index: 0); + test.Options.AddRange(AllOptionsOff); + await test.RunAsync(); } #if false @@ -6438,7 +6680,7 @@ public async Task TestImplementInterfaceForImplicitIDisposable() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { }", $@"using System; @@ -6448,7 +6690,7 @@ class Program : IDisposable private bool disposedValue; {DisposePattern("protected virtual ", "Program", "public void ")} -}}", index: 1); +}}", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -6457,7 +6699,7 @@ public async Task TestImplementInterfaceForExplicitIDisposable() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { private bool DisposedValue; }", @@ -6469,7 +6711,7 @@ class Program : IDisposable private bool disposedValue; {DisposePattern("protected virtual ", "Program", "void IDisposable.")} -}}", index: 3); +}}", codeAction: ("True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 3)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -6478,7 +6720,7 @@ public async Task TestImplementInterfaceForIDisposableNonApplicable1() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { private bool disposedValue; }", @@ -6492,7 +6734,7 @@ public void Dispose() { throw new NotImplementedException(); } -}", index: 0); +}", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 0)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -6501,7 +6743,7 @@ public async Task TestImplementInterfaceForIDisposableNonApplicable2() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { public void Dispose(bool flag) { @@ -6519,7 +6761,7 @@ public void Dispose() { throw new NotImplementedException(); } -}", index: 0); +}", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 0)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -6528,7 +6770,7 @@ public async Task TestImplementInterfaceForExplicitIDisposableWithSealedClass() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -sealed class Program : [|IDisposable|] +sealed class Program : {|CS0535:IDisposable|} { }", $@"using System; @@ -6538,7 +6780,7 @@ sealed class Program : IDisposable private bool disposedValue; {DisposePattern("private ", "Program", "void IDisposable.")} -}}", index: 3); +}}", codeAction: ("True;False;False:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 3)); } [WorkItem(9760, "https://github.com/dotnet/roslyn/issues/9760")] @@ -6548,7 +6790,7 @@ public async Task TestImplementInterfaceForExplicitIDisposableWithExistingField( await TestWithAllCodeStyleOptionsOffAsync( @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { private bool disposedValue; }", @@ -6560,27 +6802,35 @@ class Program : IDisposable private bool disposedValue1; {DisposePattern("protected virtual ", "Program", "public void ", disposeField: "disposedValue1")} -}}", index: 1); +}}", codeAction: ("False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 1)); } [WorkItem(9760, "https://github.com/dotnet/roslyn/issues/9760")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementInterfaceUnderscoreNameForFields() { - await TestInRegularAndScriptAsync( -@"using System; + await new VerifyCS.Test + { + TestCode = @"using System; -class Program : [|IDisposable|] +class Program : {|CS0535:IDisposable|} { }", -$@"using System; + FixedCode = $@"using System; class Program : IDisposable {{ private bool _disposedValue; {DisposePattern("protected virtual ", "Program", "public void ", disposeField: "_disposedValue")} -}}", index: 1, options: _options.FieldNamesAreCamelCaseWithUnderscorePrefix); +}}", + Options = + { + _options.FieldNamesAreCamelCaseWithUnderscorePrefix, + }, + CodeActionEquivalenceKey = "False;False;True:global::System.IDisposable;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [WorkItem(939123, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/939123")] @@ -6593,7 +6843,7 @@ await TestWithAllCodeStyleOptionsOffAsync( void M([System.Runtime.InteropServices.ComAliasName(""pAlias"")] int p); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -6623,7 +6873,7 @@ interface I long M([ComAliasName(""pAlias2"")] int p); } -class C : [|I|] +class C : {|CS0535:I|} { }", @"using System.Runtime.InteropServices; @@ -6653,7 +6903,7 @@ await TestWithAllCodeStyleOptionsOffAsync( long this[[System.Runtime.InteropServices.ComAliasName(""pAlias"")] int p] { get; } } -class C : [|I|] +class C : {|CS0535:I|} { }", @"interface I @@ -6685,7 +6935,7 @@ public interface TestInterface void M1(); } - struct TestStruct1 : [|TestInterface|] + struct TestStruct1 : {|CS0535:TestInterface|}{|CS1513:|}{|CS1514:|} // Comment @@ -6726,7 +6976,7 @@ partial class C { } -partial class C : [|I|], System.IDisposable +partial class C : {|CS0535:{|CS0535:{|CS0535:I|}|}|}, {|CS0535:System.IDisposable|} { }", $@"using System; @@ -6762,7 +7012,7 @@ public List M(Dictionary> a, TT b, UU c) where UU : TT }} {DisposePattern("protected virtual ", "C", "public void ")} -}}", index: 1); +}}", codeAction: ("False;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 1)); } [WorkItem(994328, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994328")] @@ -6776,7 +7026,7 @@ await TestWithAllCodeStyleOptionsOffAsync( System.Collections.Generic.List M(System.Collections.Generic.Dictionary> a, TT b, UU c) where UU : TT; } -partial class C : [|I|], System.IDisposable +partial class C : {|CS0535:{|CS0535:{|CS0535:I|}|}|}, {|CS0535:System.IDisposable|} { } @@ -6816,7 +7066,7 @@ List I.M(Dictionary> a, partial class C {{ -}}", index: 3); +}}", codeAction: ("True;False;False:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceWithDisposePatternCodeAction;", 3)); } private static string DisposePattern( @@ -6863,7 +7113,7 @@ public async Task TestInaccessibleAttributes() await TestWithAllCodeStyleOptionsOffAsync( @"using System; -public class Goo : [|Holder.SomeInterface|] +public class Goo : {|CS0535:Holder.SomeInterface|} { } @@ -6911,7 +7161,7 @@ await TestWithAllCodeStyleOptionsOffAsync( using System.Linq; using System.Threading.Tasks; -class Issue2785 : [|IList|] +class Issue2785 : {|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:{|CS0535:IList|}|}|}|}|}|}|}|}|}|}|}|}|} { private static List innerList = new List(); }", @@ -7004,7 +7254,7 @@ IEnumerator IEnumerable.GetEnumerator() return ((IEnumerable)innerList).GetEnumerator(); } }", -index: 1); +codeAction: ("False;False;False:global::System.Collections.Generic.IList;mscorlib;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;innerList", 1)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface), CompilerTrait(CompilerFeature.Tuples)] @@ -7016,7 +7266,7 @@ await TestWithAllCodeStyleOptionsOffAsync( (int, string, int, string, int, string, int, string) Method1((int, string, int, string, int, string, int, string) y); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { (int, string) x; }", @@ -7045,7 +7295,7 @@ await TestWithAllCodeStyleOptionsOffAsync( (int a, string b, int c, string d, int e, string f, int g, string h) Method1((int a, string b, int c, string d, int e, string f, int g, string h) y); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { (int, string) x; }", @@ -7074,7 +7324,7 @@ await TestWithAllCodeStyleOptionsOffAsync( (TA, TB) Method1((TA, TB) y); } -class Class : [|IInterface<(int, string), int>|] +class Class : {|CS0535:IInterface<(int, string), int>|} { (int, string) x; }", @@ -7103,7 +7353,7 @@ await TestWithAllCodeStyleOptionsOffAsync( (TA a, TB b) Method1((TA a, TB b) y); } -class Class : [|IInterface<(int, string), int>|] +class Class : {|CS0535:IInterface<(int, string), int>|} { (int, string) x; }", @@ -7127,17 +7377,18 @@ class Class : IInterface<(int, string), int> [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestWithGroupingOff1() { - await TestInRegularAndScriptAsync( -@"interface IInterface + await new VerifyCS.Test + { + TestCode = @"interface IInterface { int Prop { get; } } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { void M() { } }", -@"interface IInterface + FixedCode = @"interface IInterface { int Prop { get; } } @@ -7147,7 +7398,12 @@ class Class : IInterface void M() { } public int Prop => throw new System.NotImplementedException(); -}", options: Option(ImplementTypeOptions.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd)); +}", + Options = + { + { ImplementTypeOptions.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd }, + }, + }.RunAsync(); } [WorkItem(15387, "https://github.com/dotnet/roslyn/issues/15387")] @@ -7159,6 +7415,7 @@ await TestInRegularAndScriptAsync( using System.Runtime.InteropServices; [ComImport] +[Guid(""00000000-0000-0000-0000-000000000000"")] interface IComInterface { void MOverload(); @@ -7167,13 +7424,14 @@ interface IComInterface int Prop { get; } } -class Class : [|IComInterface|] +class Class : {|CS0535:{|CS0535:{|CS0535:{|CS0535:IComInterface|}|}|}|} { }", @" using System.Runtime.InteropServices; [ComImport] +[Guid(""00000000-0000-0000-0000-000000000000"")] interface IComInterface { void MOverload(); @@ -7207,11 +7465,15 @@ public void MOverload(int i) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestDoNotReorderComImportMembers_02() { - await TestInRegularAndScriptAsync( + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @" using System.Runtime.InteropServices; [ComImport] +[Guid(""00000000-0000-0000-0000-000000000000"")] interface IComInterface { void MOverload() { } @@ -7220,13 +7482,15 @@ void MOverload(int i) { } int Prop { get; } } -class Class : [|IComInterface|] +class Class : {|CS0535:IComInterface|} { }", + FixedCode = @" using System.Runtime.InteropServices; [ComImport] +[Guid(""00000000-0000-0000-0000-000000000000"")] interface IComInterface { void MOverload() { } @@ -7238,7 +7502,8 @@ void MOverload(int i) { } class Class : IComInterface { public int Prop => throw new System.NotImplementedException(); -}"); +}", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -7254,7 +7519,7 @@ interface I { ref int this[int i] { get; } } -class C : [|I|] +class C : {|CS0535:{|CS0535:{|CS0535:I|}|}|} { }", @" @@ -7284,18 +7549,19 @@ public ref int IGoo() [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestAutoProperties() { - await TestInRegularAndScript1Async( -@"interface IInterface + await new VerifyCS.Test() + { + TestCode = @"interface IInterface { int ReadOnlyProp { get; } int ReadWriteProp { get; set; } int WriteOnlyProp { set; } } -class Class : [|IInterface|] +class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { int ReadOnlyProp { get; } int ReadWriteProp { get; set; } @@ -7307,16 +7573,21 @@ class Class : IInterface public int ReadOnlyProp { get; } public int ReadWriteProp { get; set; } public int WriteOnlyProp { set => throw new System.NotImplementedException(); } -}", parameters: new TestParameters(options: Option( - ImplementTypeOptions.PropertyGenerationBehavior, - ImplementTypePropertyGenerationBehavior.PreferAutoProperties))); +}", + Options = + { + { ImplementTypeOptions.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties }, + }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestOptionalParameterWithDefaultLiteral() { - await TestWithAllCodeStyleOptionsOffAsync( -@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp7_1, + TestCode = @" using System.Threading; interface IInterface @@ -7324,10 +7595,10 @@ interface IInterface void Method1(CancellationToken cancellationToken = default(CancellationToken)); } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@" + FixedCode = @" using System.Threading; interface IInterface @@ -7341,7 +7612,9 @@ public void Method1(CancellationToken cancellationToken = default) { throw new System.NotImplementedException(); } -}", parseOptions: CSharp7_1); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -7352,7 +7625,7 @@ await TestInRegularAndScriptAsync( { void Method(in int p); } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"interface ITest @@ -7376,7 +7649,7 @@ await TestInRegularAndScriptAsync( { ref readonly int Method(); } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"interface ITest @@ -7400,7 +7673,7 @@ await TestInRegularAndScriptAsync( { ref readonly int Property { get; } } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"interface ITest @@ -7421,7 +7694,7 @@ await TestInRegularAndScriptAsync( { int this[in int p] { set; } } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"interface ITest @@ -7442,7 +7715,7 @@ await TestInRegularAndScriptAsync( { ref readonly int this[int p] { get; } } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"interface ITest @@ -7463,7 +7736,7 @@ await TestInRegularAndScriptAsync( { void M() where T : unmanaged; } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"public interface ITest @@ -7482,8 +7755,10 @@ public void M() where T : unmanaged [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestSealedMember_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7491,10 +7766,10 @@ sealed void M1() {} sealed int P1 => 1; } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7508,14 +7783,18 @@ public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestSealedMember_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7523,10 +7802,10 @@ sealed void M1() {} sealed int P1 => 1; } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7541,14 +7820,19 @@ void IInterface.Method1() throw new System.NotImplementedException(); } }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestSealedMember_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7556,10 +7840,10 @@ sealed void M1() {} sealed int P1 => 1; } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7571,14 +7855,19 @@ abstract class Class : IInterface { public abstract void Method1(); }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicMember_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7586,10 +7875,14 @@ await TestWithAllCodeStyleOptionsOffAsync( protected int P1 {get;} } -class Class : [|IInterface|] +class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { void Method1(); @@ -7597,29 +7890,41 @@ class Class : [|IInterface|] protected int P1 {get;} } -class Class : IInterface +class Class : {|CS0535:{|CS0535:IInterface|}|} { public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;False;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicMember_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { protected void M1(); protected int P1 {get;} } -class Class : [|IInterface|] +class Class : {|CS0535:{|CS0535:IInterface|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { protected void M1(); protected int P1 {get;} @@ -7640,14 +7945,24 @@ void IInterface.M1() throw new System.NotImplementedException(); } }", -index: 1); + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + DiagnosticSelector = diagnostics => diagnostics[1], + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicMember_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7655,10 +7970,14 @@ await TestWithAllCodeStyleOptionsOffAsync( protected int P1 {get;} } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { void Method1(); @@ -7666,18 +7985,25 @@ abstract class Class : [|IInterface|] protected int P1 {get;} } -abstract class Class : IInterface +abstract class Class : {|CS0535:{|CS0535:IInterface|}|} { public abstract void Method1(); }", -index: 1); + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicAccessor_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7685,10 +8011,14 @@ await TestWithAllCodeStyleOptionsOffAsync( int P2 {protected get; set;} } -class Class : [|IInterface|] +class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { void Method1(); @@ -7696,29 +8026,41 @@ class Class : [|IInterface|] int P2 {protected get; set;} } -class Class : IInterface +class Class : {|CS0535:{|CS0535:IInterface|}|} { public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;False;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicAccessor_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { int P1 {get; protected set;} int P2 {protected get; set;} } -class Class : [|IInterface|] +class Class : {|CS0535:{|CS0535:IInterface|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { int P1 {get; protected set;} int P2 {protected get; set;} @@ -7751,14 +8093,23 @@ int IInterface.P2 throw new System.NotImplementedException(); } } -}"); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNonPublicAccessor_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7766,10 +8117,14 @@ await TestWithAllCodeStyleOptionsOffAsync( int P2 {protected get; set;} } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} { }", -@"interface IInterface + FixedState = + { + Sources = + { + @"interface IInterface { void Method1(); @@ -7777,18 +8132,25 @@ abstract class Class : [|IInterface|] int P2 {protected get; set;} } -abstract class Class : IInterface +abstract class Class : {|CS0535:{|CS0535:IInterface|}|} { public abstract void Method1(); }", -index: 1); + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestPrivateAccessor_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7796,10 +8158,10 @@ await TestWithAllCodeStyleOptionsOffAsync( int P2 {private get => 0; set {}} } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7813,14 +8175,18 @@ public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestPrivateAccessor_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7828,10 +8194,10 @@ await TestWithAllCodeStyleOptionsOffAsync( int P2 {private get => 0; set {}} } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7846,14 +8212,19 @@ void IInterface.Method1() throw new System.NotImplementedException(); } }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestPrivateAccessor_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -7861,10 +8232,10 @@ await TestWithAllCodeStyleOptionsOffAsync( int P2 {private get => 0; set {}} } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -7876,234 +8247,323 @@ abstract class Class : IInterface { public abstract void Method1(); }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleMember_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); internal void M1(); internal int P1 {get;} -} - - - - Assembly1 - -class Class : [|IInterface|] -{ -} - - -", -@" -class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:IInterface|}|} { public void Method1() { throw new System.NotImplementedException(); } -} - "); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + + // Specify the code action by equivalence key only to avoid trying to implement the interface explicitly with a second code fix pass. + CodeActionEquivalenceKey = "False;False;True:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleMember_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); internal void M1(); internal int P1 {get;} -} - - - - Assembly1 - -class Class : [|IInterface|] -{ -} - - -", -@" -class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:IInterface|}|} { void IInterface.Method1() { throw new System.NotImplementedException(); } -} - ", -index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleMember_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"abstract class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); internal void M1(); internal int P1 {get;} -} - - - - Assembly1 - -abstract class Class : [|IInterface|] -{ -} - - -", -@" -abstract class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"abstract class Class : {|CS0535:{|CS0535:IInterface|}|} { public abstract void Method1(); -} - ", -index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + + // Specify the code action by equivalence key only to avoid trying to execute a second code fix pass with a different action + CodeActionEquivalenceKey = "False;True;True:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleAccessor_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); int P1 {get; internal set;} int P2 {internal get; set;} -} - - - - Assembly1 - -class Class : [|IInterface|] -{ -} - - -", -@" -class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:IInterface|}|} { public void Method1() { throw new System.NotImplementedException(); } -} - "); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + + // Specify the code action by equivalence key only to avoid trying to implement the interface explicitly with a second code fix pass. + CodeActionEquivalenceKey = "False;False;True:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleAccessor_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); int P1 {get; internal set;} int P2 {internal get; set;} -} - - - - Assembly1 - -class Class : [|IInterface|] -{ -} - - -", -@" -class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"class Class : {|CS0535:{|CS0535:IInterface|}|} { void IInterface.Method1() { throw new System.NotImplementedException(); } -} - ", -index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestInaccessibleAccessor_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@" - - - -public interface IInterface + await new VerifyCS.Test + { + TestState = + { + Sources = + { + @"abstract class Class : {|CS0535:{|CS0535:{|CS0535:IInterface|}|}|} +{ +}", + }, + AdditionalProjects = + { + ["Assembly1"] = + { + Sources = + { + @"public interface IInterface { void Method1(); int P1 {get; internal set;} int P2 {internal get; set;} -} - - - - Assembly1 - -abstract class Class : [|IInterface|] -{ -} - - -", -@" -abstract class Class : IInterface +}", + }, + }, + }, + AdditionalProjectReferences = { "Assembly1" }, + }, + FixedState = + { + Sources = + { + @"abstract class Class : {|CS0535:{|CS0535:IInterface|}|} { public abstract void Method1(); -} - ", -index: 1); +}", + }, + MarkupHandling = MarkupMode.Allow, + }, + Options = { AllOptionsOff }, + + // Specify the code action by equivalence key only to avoid trying to execute a second code fix pass with a different action + CodeActionEquivalenceKey = "False;True;True:global::IInterface;Assembly1;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestVirtualMember_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8111,10 +8571,10 @@ virtual void M1() {} virtual int P1 => 1; } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8128,14 +8588,18 @@ public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestVirtualMember_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8143,10 +8607,10 @@ virtual void M1() {} virtual int P1 => 1; } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8161,14 +8625,19 @@ void IInterface.Method1() throw new System.NotImplementedException(); } }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestVirtualMember_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8176,10 +8645,10 @@ virtual void M1() {} virtual int P1 => 1; } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8191,14 +8660,19 @@ abstract class Class : IInterface { public abstract void Method1(); }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticMember_01() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8208,10 +8682,10 @@ static void M1() {} public abstract class C {} } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8227,14 +8701,18 @@ public void Method1() { throw new System.NotImplementedException(); } -}"); +}", + Options = { AllOptionsOff }, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticMember_02() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8244,10 +8722,10 @@ static void M1() {} public abstract class C {} } -class Class : [|IInterface|] +class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8264,14 +8742,19 @@ void IInterface.Method1() throw new System.NotImplementedException(); } }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "True;False;False:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticMember_03() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"interface IInterface { void Method1(); @@ -8281,10 +8764,10 @@ static void M1() {} public abstract class C {} } -abstract class Class : [|IInterface|] +abstract class Class : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); @@ -8298,7 +8781,10 @@ abstract class Class : IInterface { public abstract void Method1(); }", -index: 1); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = "False;True;True:global::IInterface;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -8309,7 +8795,7 @@ await TestInRegularAndScriptAsync( { void M() where T : notnull; } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"public interface ITest @@ -8335,7 +8821,7 @@ public interface ITest { string? P { get; } } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"#nullable enable @@ -8353,17 +8839,18 @@ public class Test : ITest [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestWithNullablePropertyAlreadyImplemented() { - await TestMissingAsync( + var code = @"#nullable enable public interface ITest { string? P { get; } } -public class Test : [|ITest|] +public class Test : ITest { public string? P => throw new System.NotImplementedException(); -}"); +}"; + await VerifyCS.VerifyCodeFixAsync(code, code); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -8376,7 +8863,7 @@ public interface ITest { string? P(); } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"#nullable enable @@ -8408,7 +8895,7 @@ public interface ITest { event EventHandler? SomeEvent; } -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"#nullable enable @@ -8438,7 +8925,7 @@ public interface ITest #nullable disable -public class Test : [|ITest|] +public class Test : {|CS0535:ITest|} { }", @"#nullable enable @@ -8475,7 +8962,7 @@ interface IFoo T Baz([AllowNull] T bar); }} -class A : [|IFoo|] +class A : {{|CS0535:{{|CS0535:IFoo|}}|}} {{ }}", @$"#nullable enable @@ -8493,7 +8980,7 @@ interface IFoo T Baz([AllowNull] T bar); }} -class A : [|IFoo|] +class A : IFoo {{ [return: NotNull] public int Bar([DisallowNull] int bar) @@ -8524,7 +9011,7 @@ interface I void M(); } -class D : B, [|I|] +class D : B, {|CS0535:I|} { }", @"class B @@ -8556,7 +9043,7 @@ interface I void M2(); } -class C : [|I|] +class C : {|CS0535:I|} { public void M1(){} }", @@ -8567,7 +9054,7 @@ interface I void M2(); } -class C : [|I|] +class C : {|CS0535:I|} { public void M1(){} @@ -8575,64 +9062,94 @@ void I.M2() { throw new System.NotImplementedException(); } -}", index: 2); +}", codeAction: ("True;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 2)); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task ImplementInitOnlyProperty() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @" interface I { int Property { get; init; } } -class C : [|I|] +class C : {|CS0535:I|} { }", -@" + FixedCode = @" interface I { int Property { get; init; } } -class C : [|I|] +class C : I { public int Property { get => throw new System.NotImplementedException(); init => throw new System.NotImplementedException(); } -}"); +}", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task ImplementRemainingExplicitlyMissingWhenAllImplemented() { - await TestActionCountAsync(@" + var code = @" interface I { void M1(); void M2(); } -class C : [|I|] +class C : I { public void M1(){} public void M2(){} -}", 0); +}"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task ImplementRemainingExplicitlyMissingWhenAllImplementedAreExplicit() { - await TestActionCountAsync(@" + var code = @" interface I { void M1(); void M2(); } -class C : [|I|] +class C : {|CS0535:I|} { void I.M1(){} -}", 2); +}"; + var fixedCode = @" +interface I +{ + void M1(); + void M2(); +} + +class C : I +{ + public void M2() + { + throw new System.NotImplementedException(); + } + + void I.M1(){} +}"; + + await new VerifyCS.Test + { + TestCode = code, + FixedCode = fixedCode, + CodeActionsVerifier = codeActions => Assert.Equal(2, codeActions.Length), + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -8645,7 +9162,7 @@ interface I internal void M2(); } -class C : [|I|] +class C : {|CS0535:I|} { public void M1(){} }", @@ -8656,7 +9173,7 @@ interface I internal void M2(); } -class C : [|I|] +class C : {|CS0535:I|} { public void M1(){} @@ -8664,63 +9181,73 @@ void I.M2() { throw new System.NotImplementedException(); } -}", index: 1); +}", codeAction: ("True;False;True:global::I;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", 1)); } [WorkItem(48295, "https://github.com/dotnet/roslyn/issues/48295")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementOnRecord_WithSemiColon() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = @" interface I { void M1(); } -record C : [|I|]; +record C : {|CS0535:I|}; ", -@" + FixedCode = @" interface I { void M1(); } -record C : [|I|] +record C : {|CS0535:I|} { public void M1() { throw new System.NotImplementedException(); } } -"); +", + }.RunAsync(); } [WorkItem(48295, "https://github.com/dotnet/roslyn/issues/48295")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementOnRecord_WithBracesAndTrivia() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = @" interface I { void M1(); } -record C : [|I|] { } // hello +record C : {|CS0535:I|} { } // hello ", -@" + FixedCode = @" interface I { void M1(); } -record C : [|I|] +record C : {|CS0535:I|} { public void M1() { throw new System.NotImplementedException(); } } // hello -"); +", + }.RunAsync(); } [WorkItem(48295, "https://github.com/dotnet/roslyn/issues/48295")] @@ -8730,45 +9257,53 @@ public void M1() [InlineData("record struct")] public async Task TestImplementOnRecord_WithSemiColonAndTrivia(string record) { - await TestInRegularAndScriptAsync($@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = $@" interface I {{ void M1(); }} -{record} C : [|I|]; // hello +{record} C : {{|CS0535:I|}}; // hello ", -$@" + FixedCode = $@" interface I {{ void M1(); }} -{record} C : [|I|] // hello +{record} C : {{|CS0535:I|}} // hello {{ public void M1() {{ throw new System.NotImplementedException(); }} }} -"); +", + }.RunAsync(); } [WorkItem(49019, "https://github.com/dotnet/roslyn/issues/49019")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestUnconstrainedGenericInstantiatedWithValueType() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @"#nullable enable interface IGoo { void Bar(T? x); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", -@" + FixedCode = @"#nullable enable interface IGoo { void Bar(T? x); @@ -8781,7 +9316,8 @@ public void Bar(int x) throw new System.NotImplementedException(); } } -"); +", + }.RunAsync(); } [WorkItem(49019, "https://github.com/dotnet/roslyn/issues/49019")] @@ -8794,7 +9330,7 @@ interface IGoo where T : struct void Bar(T? x); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", @@ -8818,20 +9354,27 @@ public void Bar(int? x) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestUnconstrainedGenericInstantiatedWithReferenceType() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @" interface IGoo { +#nullable enable void Bar(T? x); +#nullable restore } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", -@" + FixedCode = @" interface IGoo { +#nullable enable void Bar(T? x); +#nullable restore } class C : IGoo @@ -8841,14 +9384,18 @@ public void Bar(string x) throw new System.NotImplementedException(); } } -"); +", + }.RunAsync(); } [WorkItem(49019, "https://github.com/dotnet/roslyn/issues/49019")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestUnconstrainedGenericInstantiatedWithReferenceType_NullableEnable() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @" #nullable enable interface IGoo @@ -8856,11 +9403,11 @@ interface IGoo void Bar(T? x); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", -@" + FixedCode = @" #nullable enable interface IGoo @@ -8875,24 +9422,30 @@ public void Bar(string? x) throw new System.NotImplementedException(); } } -"); +", + }.RunAsync(); } [WorkItem(49019, "https://github.com/dotnet/roslyn/issues/49019")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestConstrainedGenericInstantiatedWithReferenceType() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp9, + TestCode = @" +#nullable enable interface IGoo where T : class { void Bar(T? x); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", -@" + FixedCode = @" +#nullable enable interface IGoo where T : class { void Bar(T? x); @@ -8900,12 +9453,13 @@ interface IGoo where T : class class C : IGoo { - public void Bar(string x) + public void Bar(string? x) { throw new System.NotImplementedException(); } } -"); +", + }.RunAsync(); } [WorkItem(49019, "https://github.com/dotnet/roslyn/issues/49019")] @@ -8920,7 +9474,7 @@ interface IGoo where T : class void Bar(T? x); } -class C : [|IGoo|] +class C : {|CS0535:IGoo|} { } ", @@ -8953,7 +9507,7 @@ interface ITest int Foo { get; } } -class Program : [|ITest|] +class Program : {|CS0535:{|CS0535:ITest|}|} { } ", @@ -8989,17 +9543,21 @@ public int Foo [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticAbstractInterfaceMember() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = @" interface ITest { static abstract void M1(); } -class C : [|ITest|] +class C : {|CS0535:ITest|} { } ", -@" + FixedCode = @" interface ITest { static abstract void M1(); @@ -9012,54 +9570,90 @@ public static void M1() throw new System.NotImplementedException(); } } -", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), index: 0, title: FeaturesResources.Implement_interface); +", + CodeActionVerifier = (codeAction, verifier) => verifier.Equal(FeaturesResources.Implement_interface, codeAction.Title), + CodeActionEquivalenceKey = "False;False;True:global::ITest;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 0, + }.RunAsync(); } [WorkItem(53925, "https://github.com/dotnet/roslyn/issues/53925")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticAbstractInterfaceMemberExplicitly() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = @" interface ITest { static abstract void M1(); } -class C : [|ITest|] +class C : {|CS0535:ITest|} { } ", -@" + FixedState = + { + Sources = + { + @" interface ITest { static abstract void M1(); } -class C : ITest +class C : {|#0:ITest|} { - void ITest.M1() + void ITest.{|#1:M1|}() { throw new System.NotImplementedException(); } } -", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), index: 1, title: FeaturesResources.Implement_all_members_explicitly); +", + }, + ExpectedDiagnostics = + { + // /0/Test0.cs(7,11): error CS0535: 'C' does not implement interface member 'ITest.M1()' + DiagnosticResult.CompilerError("CS0535").WithLocation(0).WithArguments("C", "ITest.M1()"), + // /0/Test0.cs(9,16): error CS0539: 'C.M1()' in explicit interface declaration is not found among members of the interface that can be implemented + DiagnosticResult.CompilerError("CS0539").WithLocation(1).WithArguments("C.M1()"), + }, + }, + CodeActionVerifier = (codeAction, verifier) => verifier.Equal(FeaturesResources.Implement_all_members_explicitly, codeAction.Title), + CodeActionEquivalenceKey = "True;False;False:global::ITest;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + + // 🐛 This code fix is broken due to a missing 'static' keyword + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + }.RunAsync(); } [WorkItem(53925, "https://github.com/dotnet/roslyn/issues/53925")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestStaticAbstractInterfaceMember_ImplementAbstractly() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + LanguageVersion = LanguageVersion.Preview, + TestCode = @" interface ITest { static abstract void M1(); } -abstract class C : [|ITest|] +abstract class C : {|CS0535:ITest|} { } ", -@" + FixedState = + { + Sources = + { + @" interface ITest { static abstract void M1(); @@ -9067,9 +9661,20 @@ interface ITest abstract class C : ITest { - public abstract static void M1(); + public abstract static void {|#0:M1|}(); } -", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), index: 1, title: FeaturesResources.Implement_interface_abstractly); +", + }, + ExpectedDiagnostics = + { + // /0/Test0.cs(9,33): error CS0112: A static member cannot be marked as 'abstract' + DiagnosticResult.CompilerError("CS0112").WithLocation(0).WithArguments("abstract"), + }, + }, + CodeActionVerifier = (codeAction, verifier) => verifier.Equal(FeaturesResources.Implement_interface_abstractly, codeAction.Title), + CodeActionEquivalenceKey = "False;True;True:global::ITest;TestProject;Microsoft.CodeAnalysis.ImplementInterface.AbstractImplementInterfaceService+ImplementInterfaceCodeAction;", + CodeActionIndex = 1, + }.RunAsync(); } } } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs index e74b55a591ad4..7332558acaa67 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs @@ -13,6 +13,9 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing.Verifiers; using Xunit; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.Text; #if !CODE_STYLE using Roslyn.Utilities; @@ -91,6 +94,8 @@ public Test() public Func, Diagnostic?>? DiagnosticSelector { get; set; } + public Action>? CodeActionsVerifier { get; set; } + protected override async Task RunImplAsync(CancellationToken cancellationToken = default) { if (DiagnosticSelector is object) @@ -130,6 +135,12 @@ protected override AnalyzerOptions GetAnalyzerOptions(Project project) return DiagnosticSelector?.Invoke(fixableDiagnostics) ?? base.TrySelectDiagnosticToFix(fixableDiagnostics); } + + protected override ImmutableArray FilterCodeActions(ImmutableArray actions) + { + CodeActionsVerifier?.Invoke(actions); + return base.FilterCodeActions(actions); + } } } } From 23fc558cf15d5e63e0af2054cf082053b71e7119 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 22 Jun 2021 16:10:19 -0700 Subject: [PATCH 3/3] Simplify tests --- .../ImplementInterfaceTests.cs | 214 +++++------------- 1 file changed, 52 insertions(+), 162 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index c898894ffb159..49d8f5d8ec531 100644 --- a/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -56,168 +56,52 @@ private static OptionsCollection AccessorOptionsOn { CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, CSharpCodeStyleOptions.NeverWithSilentEnforcement }, }; - private const string NullableAttributesCode = @" -namespace System.Diagnostics.CodeAnalysis -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] - internal sealed class AllowNullAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] - internal sealed class DisallowNullAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] - internal sealed class MaybeNullAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] - internal sealed class NotNullAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class MaybeNullWhenAttribute : Attribute - { - public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - public bool ReturnValue { get; } - } - - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class NotNullWhenAttribute : Attribute - { - public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - public bool ReturnValue { get; } - } - - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] - internal sealed class NotNullIfNotNullAttribute : Attribute - { - public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; - public string ParameterName { get; } - } - - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - internal sealed class DoesNotReturnAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class DoesNotReturnIfAttribute : Attribute - { - public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; - public bool ParameterValue { get; } - } -}"; - internal static async Task TestWithAllCodeStyleOptionsOffAsync( string initialMarkup, string expectedMarkup, - (string equivalenceKey, int index)? codeAction = null, ParseOptions? parseOptions = null) + (string equivalenceKey, int index)? codeAction = null) { - var test = new VerifyCS.Test + await new VerifyCS.Test { TestCode = initialMarkup, FixedCode = expectedMarkup, - SolutionTransforms = - { - (solution, projectId) => - { - if (parseOptions is not null) - { - solution = solution.WithProjectParseOptions(projectId, parseOptions); - } - - return solution; - }, - }, - }; - - if (codeAction is var (equivalenceKey, index)) - { - test.CodeActionEquivalenceKey = equivalenceKey; - test.CodeActionIndex = index; - } - - test.Options.AddRange(AllOptionsOff); - await test.RunAsync(); + Options = { AllOptionsOff }, + CodeActionEquivalenceKey = codeAction?.equivalenceKey, + CodeActionIndex = codeAction?.index, + }.RunAsync(); } - internal static async Task TestWithAllCodeStyleOptionsOnAsync( - string initialMarkup, string expectedMarkup, - (string equivalenceKey, int index)? codeAction = null, ParseOptions? parseOptions = null) + internal static async Task TestWithAllCodeStyleOptionsOnAsync(string initialMarkup, string expectedMarkup) { - var test = new VerifyCS.Test + await new VerifyCS.Test { TestCode = initialMarkup, FixedCode = expectedMarkup, - SolutionTransforms = - { - (solution, projectId) => - { - if (parseOptions is not null) - { - solution = solution.WithProjectParseOptions(projectId, parseOptions); - } - - return solution; - }, - }, - }; - - if (codeAction is var (equivalenceKey, index)) - { - test.CodeActionEquivalenceKey = equivalenceKey; - test.CodeActionIndex = index; - } - - test.Options.AddRange(AllOptionsOn); - await test.RunAsync(); + Options = { AllOptionsOn }, + }.RunAsync(); } - internal static async Task TestWithAccessorCodeStyleOptionsOnAsync( - string initialMarkup, string expectedMarkup, - (string equivalenceKey, int index)? codeAction = null) + internal static async Task TestWithAccessorCodeStyleOptionsOnAsync(string initialMarkup, string expectedMarkup) { - var test = new VerifyCS.Test + await new VerifyCS.Test { TestCode = initialMarkup, FixedCode = expectedMarkup, - }; - - if (codeAction is var (equivalenceKey, index)) - { - test.CodeActionEquivalenceKey = equivalenceKey; - test.CodeActionIndex = index; - } - - test.Options.AddRange(AccessorOptionsOn); - await test.RunAsync(); + Options = { AccessorOptionsOn }, + }.RunAsync(); } private static async Task TestInRegularAndScriptAsync( string initialMarkup, string expectedMarkup, - (string equivalenceKey, int index)? codeAction = null, - ParseOptions? parseOptions = null) + (string equivalenceKey, int index)? codeAction = null) { - var test = new VerifyCS.Test + await new VerifyCS.Test { TestCode = initialMarkup, FixedCode = expectedMarkup, - SolutionTransforms = - { - (solution, projectId) => - { - if (parseOptions is not null) - { - solution = solution.WithProjectParseOptions(projectId, parseOptions); - } - - return solution; - }, - }, - }; - - if (codeAction is var (equivalenceKey, index)) - { - test.CodeActionEquivalenceKey = equivalenceKey; - test.CodeActionIndex = index; - } - - await test.RunAsync(); + CodeActionEquivalenceKey = codeAction?.equivalenceKey, + CodeActionIndex = codeAction?.index, + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -249,8 +133,10 @@ public void Method1() [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestMethodInRecord() { - await TestWithAllCodeStyleOptionsOffAsync( -@"interface IInterface + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.Preview, + TestCode = @"interface IInterface { void Method1(); } @@ -258,7 +144,7 @@ await TestWithAllCodeStyleOptionsOffAsync( record Record : {|CS0535:IInterface|} { }", -@"interface IInterface + FixedCode = @"interface IInterface { void Method1(); } @@ -269,7 +155,8 @@ public void Method1() { throw new System.NotImplementedException(); } -}", parseOptions: TestOptions.RegularPreview); +}", + }.RunAsync(); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] @@ -8946,54 +8833,53 @@ public class Test : ITest [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task GenericInterfaceNotNull1() { - await TestInRegularAndScriptAsync( -@$"#nullable enable + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = @"#nullable enable using System.Diagnostics.CodeAnalysis; -{NullableAttributesCode} - interface IFoo -{{ +{ [return: NotNull] T Bar([DisallowNull] T bar); [return: MaybeNull] T Baz([AllowNull] T bar); -}} +} -class A : {{|CS0535:{{|CS0535:IFoo|}}|}} -{{ -}}", -@$"#nullable enable +class A : {|CS0535:{|CS0535:IFoo|}|} +{ +}", + FixedCode = @"#nullable enable using System.Diagnostics.CodeAnalysis; -{NullableAttributesCode} - interface IFoo -{{ +{ [return: NotNull] T Bar([DisallowNull] T bar); [return: MaybeNull] T Baz([AllowNull] T bar); -}} +} class A : IFoo -{{ +{ [return: NotNull] public int Bar([DisallowNull] int bar) - {{ + { throw new System.NotImplementedException(); - }} + } [return: MaybeNull] public int Baz([AllowNull] int bar) - {{ + { throw new System.NotImplementedException(); - }} -}}"); + } +}", + }.RunAsync(); } [WorkItem(13427, "https://github.com/dotnet/roslyn/issues/13427")] @@ -9500,7 +9386,10 @@ public void Bar(string? x) [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestImplementTwoPropertiesOfCSharp5() { - await TestInRegularAndScriptAsync(@" + await new VerifyCS.Test + { + LanguageVersion = LanguageVersion.CSharp5, + TestCode = @" interface ITest { int Bar { get; } @@ -9511,7 +9400,7 @@ class Program : {|CS0535:{|CS0535:ITest|}|} { } ", -@" + FixedCode = @" interface ITest { int Bar { get; } @@ -9536,7 +9425,8 @@ public int Foo } } } -", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5)); +", + }.RunAsync(); } [WorkItem(53925, "https://github.com/dotnet/roslyn/issues/53925")]