diff --git a/eng/Versions.props b/eng/Versions.props
index 67e97534f9b5c..6f93c498e5b0e 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -29,7 +29,7 @@
3.3.3-beta1.21105.3
6.0.0-preview1.21054.10
- 1.0.1-beta1.20623.3
+ 1.1.0-beta1.21322.2
3.10.0
16.10.230
17.0.65-g6c25c21ba5
diff --git a/src/CodeStyle/CSharp/Tests/FormattingAnalyzerTests.cs b/src/CodeStyle/CSharp/Tests/FormattingAnalyzerTests.cs
index 96f2902a56a38..d078794b7f5e8 100644
--- a/src/CodeStyle/CSharp/Tests/FormattingAnalyzerTests.cs
+++ b/src/CodeStyle/CSharp/Tests/FormattingAnalyzerTests.cs
@@ -270,16 +270,15 @@ void MyMethod()
await new CSharpCodeFixTest
{
- TestState = { Sources = { (Path.GetFullPath("Test0.cs"), testCode) } },
- FixedState = { Sources = { (Path.GetFullPath("Test0.cs"), fixedCode) } },
- SolutionTransforms =
+ TestState =
{
- (solution, projectId) =>
+ Sources = { testCode },
+ AnalyzerConfigFiles =
{
- var documentId = DocumentId.CreateNewId(projectId, ".editorconfig");
- return solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", SourceText.From(editorConfig, Encoding.UTF8), filePath: Path.GetFullPath(".editorconfig"));
+ ("/.editorconfig", editorConfig),
},
},
+ FixedState = { Sources = { fixedCode } },
}.RunAsync();
}
}
diff --git a/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
index 9cb5c77e650de..dae2461a112e8 100644
--- a/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
+++ b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj
@@ -16,6 +16,7 @@
+
diff --git a/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs b/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs
index 2116a5ac38b23..16f228209a291 100644
--- a/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs
+++ b/src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs
@@ -48,7 +48,9 @@ private static async Task TestAsync(
if (index != 0)
Assert.NotNull(equivalenceKey);
- var test = new VerifyCS.Test
+ options ??= new OptionsCollection(LanguageNames.CSharp);
+
+ await new VerifyCS.Test
{
TestCode = text,
FixedCode = expected,
@@ -57,11 +59,8 @@ private static async Task TestAsync(
CodeActionIndex = index,
CodeActionEquivalenceKey = equivalenceKey,
ExactActionSetOffered = actions,
- };
-
- if (options != null)
- test.Options.AddRange(options);
- await test.RunAsync();
+ Options = { options },
+ }.RunAsync();
}
#region update containing member tests
@@ -2278,7 +2277,8 @@ public static implicit operator NewStruct((int a, int a) value)
return new NewStruct(value.a, value.a);
}
}";
- var test = new VerifyCS.Test
+
+ await new VerifyCS.Test
{
TestCode = text,
FixedCode = expected,
@@ -2349,11 +2349,9 @@ public static implicit operator NewStruct((int a, int a) value)
// /0/Test0.cs(49,45): error CS0229: Ambiguity between '(int a, int a).a' and '(int a, int a).a'
DiagnosticResult.CompilerError("CS0229").WithSpan(49, 45, 49, 46).WithArguments("(int a, int a).a", "(int a, int a).a"),
}
- }
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ },
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
@@ -3352,7 +3350,7 @@ void Goo()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestState =
{
@@ -3373,10 +3371,8 @@ void Goo()
CodeActionIndex = 1,
CodeActionEquivalenceKey = Scope.ContainingType.ToString(),
TestHost = host,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
#endregion update containing project tests
@@ -3511,7 +3507,7 @@ void Goo()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
CodeActionIndex = 2,
CodeActionEquivalenceKey = Scope.ContainingProject.ToString(),
@@ -3524,10 +3520,8 @@ void Goo()
{
Sources = { expected1, expected2 },
},
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
#endregion
@@ -3638,7 +3632,7 @@ void Goo()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
CodeActionIndex = 3,
CodeActionEquivalenceKey = Scope.DependentProjects.ToString(),
@@ -3667,10 +3661,8 @@ void Goo()
}
},
},
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
@@ -3777,7 +3769,7 @@ void Goo()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
CodeActionIndex = 3,
CodeActionEquivalenceKey = Scope.DependentProjects.ToString(),
@@ -3798,10 +3790,8 @@ void Goo()
["DependencyProject"] = { Sources = { expected2 } }
},
},
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
#endregion
diff --git a/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs b/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
index 792917787cdca..bcb254453e86a 100644
--- a/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
+++ b/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
@@ -35,7 +35,7 @@ private class TestWithDialog : VerifyCS.Test
public ImmutableArray MemberNames;
public Action> OptionsCallback;
- public override AdhocWorkspace CreateWorkspace()
+ protected override Workspace CreateWorkspaceImpl()
{
// If we're a dialog test, then mixin our mock and initialize its values to the ones the test asked for.
var workspace = new AdhocWorkspace(s_composition.GetHostServices());
@@ -98,15 +98,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
@@ -135,15 +133,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferExplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferExplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -179,15 +175,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -229,15 +223,13 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -273,15 +265,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -309,15 +299,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -345,15 +333,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -386,15 +372,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -426,15 +410,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -484,16 +466,14 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 0,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -551,15 +531,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -795,15 +773,13 @@ public override bool Equals(object obj)
}
";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = expected,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -860,16 +836,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -902,16 +876,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -955,16 +927,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1005,17 +975,15 @@ public override int GetHashCode()
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
MemberNames = ImmutableArray.Empty,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1088,16 +1056,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1130,16 +1096,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1180,16 +1144,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1374,16 +1336,14 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 0,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1411,15 +1371,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1447,15 +1405,13 @@ public override bool Equals(object obj)
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1488,16 +1444,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1530,16 +1484,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1580,16 +1532,14 @@ struct Bar
{
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1632,16 +1582,14 @@ struct Bar
public override int GetHashCode() => 0;
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1682,16 +1630,14 @@ struct Bar
{
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1724,16 +1670,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1766,16 +1710,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1816,16 +1758,14 @@ enum Bar
{
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1858,16 +1798,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1899,16 +1837,14 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = ImmutableArray.Create("a", "b"),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1942,16 +1878,14 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = ImmutableArray.Create("c", "b"),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -1983,16 +1917,14 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = ImmutableArray.Empty,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(17643, "https://github.com/dotnet/roslyn/issues/17643")]
@@ -2020,15 +1952,13 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(25690, "https://github.com/dotnet/roslyn/issues/25690")]
@@ -2188,17 +2118,15 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateOperatorsId),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2278,17 +2206,15 @@ public override bool Equals(object obj)
public static bool operator {|CS0216:==|}(Program left, Program right) => true;
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => Assert.Null(options.FirstOrDefault(i => i.Id == GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateOperatorsId)),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2333,17 +2259,15 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateOperatorsId),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2392,16 +2316,14 @@ enum Bar
{
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 0,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2466,16 +2388,14 @@ struct Bar : IEquatable
public static bool operator !=(Bar left, Bar right) => !(left == right);
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 0,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2510,17 +2430,15 @@ public bool Equals(Program other)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.ImplementIEquatableId),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2711,17 +2629,15 @@ public bool Equals(Program other)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.ImplementIEquatableId),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -2844,17 +2760,15 @@ public override bool Equals(object obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => Assert.Null(options.FirstOrDefault(i => i.Id == GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.ImplementIEquatableId)),
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -3063,16 +2977,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -3121,7 +3033,7 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedState =
@@ -3135,10 +3047,8 @@ public override int GetHashCode()
},
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(37297, "https://github.com/dotnet/roslyn/issues/37297")]
@@ -3186,7 +3096,7 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestState =
{
@@ -3211,10 +3121,8 @@ public override int GetHashCode()
},
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(37297, "https://github.com/dotnet/roslyn/issues/37297")]
@@ -3262,7 +3170,7 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestState =
{
@@ -3279,10 +3187,8 @@ public override int GetHashCode()
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -3338,7 +3244,7 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedState =
@@ -3352,10 +3258,8 @@ public override int GetHashCode()
},
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -3422,16 +3326,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
@@ -3499,16 +3401,14 @@ public override int GetHashCode()
}
}";
- var test = new VerifyCS.Test
+ await new VerifyCS.Test
{
TestCode = code,
FixedCode = fixedCode,
CodeActionIndex = 1,
LanguageVersion = LanguageVersion.CSharp6,
- };
-
- test.Options.AddRange(PreferExplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferExplicitTypeWithInfo() },
+ }.RunAsync();
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
@@ -3693,7 +3593,7 @@ public override bool Equals(object? obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedState =
@@ -3710,10 +3610,8 @@ public override bool Equals(object? obj)
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateOperatorsId),
LanguageVersion = LanguageVersion.Default,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(40053, "https://github.com/dotnet/roslyn/issues/40053")]
@@ -3761,17 +3659,15 @@ public override bool Equals(object? obj)
}
}";
- var test = new TestWithDialog
+ await new TestWithDialog
{
TestCode = code,
FixedCode = fixedCode,
MemberNames = default,
OptionsCallback = options => EnableOption(options, GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateOperatorsId),
LanguageVersion = LanguageVersion.Default,
- };
-
- test.Options.AddRange(PreferImplicitTypeWithInfo());
- await test.RunAsync();
+ Options = { PreferImplicitTypeWithInfo() },
+ }.RunAsync();
}
[WorkItem(42574, "https://github.com/dotnet/roslyn/issues/42574")]
diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
index 6ac0276e90786..334ed11df8092 100644
--- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
+++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
@@ -26,6 +26,8 @@ public static partial class CSharpCodeFixVerifier
{
public class Test : CSharpCodeFixTest
{
+ private readonly SharedVerifierState _sharedState;
+
static Test()
{
// If we have outdated defaults from the host unit test application targeting an older .NET Framework, use more
@@ -42,6 +44,8 @@ static Test()
public Test()
{
+ _sharedState = new SharedVerifierState(this, DefaultFileExt);
+
MarkupOptions = Testing.MarkupOptions.UseFirstDescriptor;
SolutionTransforms.Add((solution, projectId) =>
@@ -53,26 +57,6 @@ public Test()
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);
- var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
- if (analyzerConfigSource is object)
- {
- foreach (var id in solution.ProjectIds)
- {
- var documentId = DocumentId.CreateNewId(id, ".editorconfig");
- solution = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
- }
- }
-
-#if !CODE_STYLE
- var options = solution.Options;
- foreach (var (key, value) in remainingOptions)
- {
- options = options.WithChangedOption(key, value);
- }
-
- solution = solution.WithOptions(options);
-#endif
-
return solution;
});
}
@@ -83,24 +67,27 @@ public Test()
///
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.CSharp8;
- ///
- /// Gets a collection of options to apply to for testing. Values may be added
- /// using a collection initializer.
- ///
- internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.CSharp);
+ ///
+ internal OptionsCollection Options => _sharedState.Options;
- public string? EditorConfig { get; set; }
+ ///
+ public string? EditorConfig
+ {
+ get => _sharedState.EditorConfig;
+ set => _sharedState.EditorConfig = value;
+ }
public Func, Diagnostic?>? DiagnosticSelector { get; set; }
- public override async Task RunAsync(CancellationToken cancellationToken = default)
+ protected override async Task RunImplAsync(CancellationToken cancellationToken = default)
{
if (DiagnosticSelector is object)
{
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
}
- await base.RunAsync(cancellationToken);
+ _sharedState.Apply();
+ await base.RunImplAsync(cancellationToken);
}
#if !CODE_STYLE
diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeRefactoringVerifier`1+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeRefactoringVerifier`1+Test.cs
index ac1137fc4802f..8012ac3db1bef 100644
--- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeRefactoringVerifier`1+Test.cs
+++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeRefactoringVerifier`1+Test.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Collections.Generic;
using System.Collections.Immutable;
using System.Net;
using System.Threading;
@@ -28,6 +27,8 @@ public static partial class CSharpCodeRefactoringVerifier
{
public class Test : CSharpCodeRefactoringTest
{
+ private readonly SharedVerifierState _sharedState;
+
static Test()
{
// If we have outdated defaults from the host unit test application targeting an older .NET Framework, use more
@@ -44,6 +45,8 @@ static Test()
public Test()
{
+ _sharedState = new SharedVerifierState(this, DefaultFileExt);
+
SolutionTransforms.Add((solution, projectId) =>
{
var parseOptions = (CSharpParseOptions)solution.GetProject(projectId)!.ParseOptions!;
@@ -53,26 +56,6 @@ public Test()
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);
- var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
- if (analyzerConfigSource is object)
- {
- foreach (var id in solution.ProjectIds)
- {
- var documentId = DocumentId.CreateNewId(id, ".editorconfig");
- solution = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
- }
- }
-
-#if !CODE_STYLE
- var options = solution.Options;
- foreach (var (key, value) in remainingOptions)
- {
- options = options.WithChangedOption(key, value);
- }
-
- solution = solution.WithOptions(options);
-#endif
-
return solution;
});
}
@@ -83,13 +66,15 @@ public Test()
///
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.CSharp8;
- ///
- /// Gets a collection of options to apply to for testing. Values may be added
- /// using a collection initializer.
- ///
- internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.CSharp);
+ ///
+ internal OptionsCollection Options => _sharedState.Options;
- public string? EditorConfig { get; set; }
+ ///
+ public string? EditorConfig
+ {
+ get => _sharedState.EditorConfig;
+ set => _sharedState.EditorConfig = value;
+ }
///
/// The set of code action s offered the user in this exact order.
@@ -97,6 +82,12 @@ public Test()
///
public string[]? ExactActionSetOffered { get; set; }
+ protected override async Task RunImplAsync(CancellationToken cancellationToken)
+ {
+ _sharedState.Apply();
+ await base.RunImplAsync(cancellationToken);
+ }
+
protected override ImmutableArray FilterCodeActions(ImmutableArray actions)
{
var result = base.FilterCodeActions(actions);
@@ -110,8 +101,6 @@ protected override ImmutableArray FilterCodeActions(ImmutableArray _workspaces = new();
-
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
=> new WorkspaceAnalyzerOptions(base.GetAnalyzerOptions(project), project.Solution);
@@ -122,38 +111,15 @@ protected override AnalyzerOptions GetAnalyzerOptions(Project project)
private static readonly TestComposition s_editorFeaturesOOPComposition = EditorTestCompositions.EditorFeatures.WithTestHostParts(TestHost.OutOfProcess);
- public override AdhocWorkspace CreateWorkspace()
+ protected override Workspace CreateWorkspaceImpl()
{
if (TestHost == TestHost.InProcess)
- return base.CreateWorkspace();
+ return base.CreateWorkspaceImpl();
var hostServices = s_editorFeaturesOOPComposition.GetHostServices();
var workspace = new AdhocWorkspace(hostServices);
- lock (_workspaces)
- _workspaces.Add(workspace);
-
return workspace;
}
-
- public override async Task RunAsync(CancellationToken cancellationToken = default)
- {
- try
- {
- await base.RunAsync(cancellationToken).ConfigureAwait(false);
- }
- finally
- {
- var workspaces = new List();
- lock (_workspaces)
- {
- workspaces.AddRange(_workspaces);
- _workspaces.Clear();
- }
-
- foreach (var workspace in workspaces)
- workspace.Dispose();
- }
- }
#endif
}
}
diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs
new file mode 100644
index 0000000000000..c8679afa8e11c
--- /dev/null
+++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/SharedVerifierState.cs
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using Microsoft.CodeAnalysis.Testing;
+using Microsoft.CodeAnalysis.Testing.Verifiers;
+
+#if !CODE_STYLE
+using Roslyn.Utilities;
+#endif
+
+namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
+{
+ internal sealed class SharedVerifierState
+ {
+ private readonly AnalyzerTest _test;
+ private readonly string _defaultFileExt;
+
+ ///
+ /// The index in of the generated
+ /// .editorconfig file for , or if no such
+ /// file has been generated yet.
+ ///
+ private int? _analyzerConfigIndex;
+
+ ///
+ /// The index in of the options transformation for
+ /// remaining , or if no such transfor has been generated yet.
+ ///
+ private Func? _remainingOptionsSolutionTransform;
+
+ public SharedVerifierState(AnalyzerTest test, string defaultFileExt)
+ {
+ _test = test;
+ _defaultFileExt = defaultFileExt;
+ Options = new OptionsCollection(test.Language);
+ }
+
+ public string? EditorConfig { get; set; }
+
+ ///
+ /// Gets a collection of options to apply to for testing. Values may be added
+ /// using a collection initializer.
+ ///
+ internal OptionsCollection Options { get; }
+
+ internal void Apply()
+ {
+ var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(_defaultFileExt, EditorConfig, Options);
+ if (analyzerConfigSource is not null)
+ {
+ if (_analyzerConfigIndex is null)
+ {
+ _analyzerConfigIndex = _test.TestState.AnalyzerConfigFiles.Count;
+ _test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", analyzerConfigSource));
+ }
+ else
+ {
+ _test.TestState.AnalyzerConfigFiles[_analyzerConfigIndex.Value] = ("/.editorconfig", analyzerConfigSource);
+ }
+ }
+ else if (_analyzerConfigIndex is { } index)
+ {
+ _analyzerConfigIndex = null;
+ _test.TestState.AnalyzerConfigFiles.RemoveAt(index);
+ }
+
+ var solutionTransformIndex = _remainingOptionsSolutionTransform is not null ? _test.SolutionTransforms.IndexOf(_remainingOptionsSolutionTransform) : -1;
+ if (remainingOptions is not null)
+ {
+ // Generate a new solution transform
+ _remainingOptionsSolutionTransform = (solution, projectId) =>
+ {
+#if !CODE_STYLE
+ var options = solution.Options;
+ foreach (var (key, value) in remainingOptions)
+ {
+ options = options.WithChangedOption(key, value);
+ }
+
+ solution = solution.WithOptions(options);
+#endif
+
+ return solution;
+ };
+
+ if (solutionTransformIndex < 0)
+ {
+ _test.SolutionTransforms.Add(_remainingOptionsSolutionTransform);
+ }
+ else
+ {
+ _test.SolutionTransforms[solutionTransformIndex] = _remainingOptionsSolutionTransform;
+ }
+ }
+ else if (_remainingOptionsSolutionTransform is not null)
+ {
+ _test.SolutionTransforms.Remove(_remainingOptionsSolutionTransform);
+ _remainingOptionsSolutionTransform = null;
+ }
+ }
+ }
+}
diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
index d63b2636931c9..1ec477ed7b4a6 100644
--- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
+++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
@@ -26,6 +26,8 @@ public static partial class VisualBasicCodeFixVerifier
{
public class Test : VisualBasicCodeFixTest
{
+ private readonly SharedVerifierState _sharedState;
+
static Test()
{
// If we have outdated defaults from the host unit test application targeting an older .NET Framework, use more
@@ -42,6 +44,8 @@ static Test()
public Test()
{
+ _sharedState = new SharedVerifierState(this, DefaultFileExt);
+
MarkupOptions = Testing.MarkupOptions.UseFirstDescriptor;
SolutionTransforms.Add((solution, projectId) =>
@@ -49,26 +53,6 @@ public Test()
var parseOptions = (VisualBasicParseOptions)solution.GetProject(projectId)!.ParseOptions!;
solution = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion));
- var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
- if (analyzerConfigSource is object)
- {
- foreach (var id in solution.ProjectIds)
- {
- var documentId = DocumentId.CreateNewId(id, ".editorconfig");
- solution = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
- }
- }
-
-#if !CODE_STYLE
- var options = solution.Options;
- foreach (var (key, value) in remainingOptions)
- {
- options = options.WithChangedOption(key, value);
- }
-
- solution = solution.WithOptions(options);
-#endif
-
return solution;
});
}
@@ -79,24 +63,27 @@ public Test()
///
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.VisualBasic16;
- ///
- /// Gets a collection of options to apply to for testing. Values may be added
- /// using a collection initializer.
- ///
- internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.VisualBasic);
+ ///
+ internal OptionsCollection Options => _sharedState.Options;
- public string? EditorConfig { get; set; }
+ ///
+ public string? EditorConfig
+ {
+ get => _sharedState.EditorConfig;
+ set => _sharedState.EditorConfig = value;
+ }
public Func, Diagnostic?>? DiagnosticSelector { get; set; }
- public override async Task RunAsync(CancellationToken cancellationToken = default)
+ protected override async Task RunImplAsync(CancellationToken cancellationToken = default)
{
if (DiagnosticSelector is object)
{
Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'");
}
- await base.RunAsync(cancellationToken);
+ _sharedState.Apply();
+ await base.RunImplAsync(cancellationToken);
}
#if !CODE_STYLE
diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeRefactoringVerifier`1+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeRefactoringVerifier`1+Test.cs
index 0a20d8d15b116..727be29d9a845 100644
--- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeRefactoringVerifier`1+Test.cs
+++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeRefactoringVerifier`1+Test.cs
@@ -3,10 +3,12 @@
// See the LICENSE file in the project root for more information.
using System.Net;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis.CodeRefactorings;
+using Microsoft.CodeAnalysis.Testing.Verifiers;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.CodeAnalysis.VisualBasic.Testing;
-using Microsoft.CodeAnalysis.Testing.Verifiers;
-using Microsoft.CodeAnalysis.CodeRefactorings;
#if !CODE_STYLE
using System;
@@ -21,6 +23,8 @@ public static partial class VisualBasicCodeRefactoringVerifier
{
public class Test : VisualBasicCodeRefactoringTest
{
+ private readonly SharedVerifierState _sharedState;
+
static Test()
{
// If we have outdated defaults from the host unit test application targeting an older .NET Framework, use more
@@ -37,31 +41,13 @@ static Test()
public Test()
{
+ _sharedState = new SharedVerifierState(this, DefaultFileExt);
+
SolutionTransforms.Add((solution, projectId) =>
{
var parseOptions = (VisualBasicParseOptions)solution.GetProject(projectId)!.ParseOptions!;
solution = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion));
- var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options);
- if (analyzerConfigSource is object)
- {
- foreach (var id in solution.ProjectIds)
- {
- var documentId = DocumentId.CreateNewId(id, ".editorconfig");
- solution = solution.AddAnalyzerConfigDocument(documentId, ".editorconfig", analyzerConfigSource, filePath: "/.editorconfig");
- }
- }
-
-#if !CODE_STYLE
- var options = solution.Options;
- foreach (var (key, value) in remainingOptions)
- {
- options = options.WithChangedOption(key, value);
- }
-
- solution = solution.WithOptions(options);
-#endif
-
return solution;
});
}
@@ -72,13 +58,21 @@ public Test()
///
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.VisualBasic16;
- ///
- /// Gets a collection of options to apply to for testing. Values may be added
- /// using a collection initializer.
- ///
- internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.VisualBasic);
+ ///
+ internal OptionsCollection Options => _sharedState.Options;
- public string? EditorConfig { get; set; }
+ ///
+ public string? EditorConfig
+ {
+ get => _sharedState.EditorConfig;
+ set => _sharedState.EditorConfig = value;
+ }
+
+ protected override async Task RunImplAsync(CancellationToken cancellationToken)
+ {
+ _sharedState.Apply();
+ await base.RunImplAsync(cancellationToken);
+ }
#if !CODE_STYLE
protected override AnalyzerOptions GetAnalyzerOptions(Project project)
diff --git a/src/Workspaces/CoreTestUtilities/OptionsCollection.cs b/src/Workspaces/CoreTestUtilities/OptionsCollection.cs
index deafef00f9a6b..7ba5994514480 100644
--- a/src/Workspaces/CoreTestUtilities/OptionsCollection.cs
+++ b/src/Workspaces/CoreTestUtilities/OptionsCollection.cs
@@ -49,6 +49,10 @@ public void Add(PerLanguageOption2> option, T value)
public void Add(PerLanguageOption2> option, T value, NotificationOption2 notification)
=> _options.Add(new OptionKey2(option, _languageName), new CodeStyleOption2(value, notification));
+ // 📝 This can be removed if/when collection initializers support AddRange.
+ public void Add(OptionsCollection options)
+ => AddRange(options);
+
public void AddRange(OptionsCollection options)
{
foreach (var (key, value) in options)