From 09434786d86d4a794e0b29737e1532101c060fb0 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Mon, 12 Sep 2022 12:17:17 -0700 Subject: [PATCH] Add a CreateCodeRefactoringContext overload This allows the derived unit test to provide custom internal options, similar to what we do in 275a14bd98850f6aca253dcf7b1e89a74ebcf2ea. --- .../CodeRefactoringTest`1.cs | 13 ++++++++++++- .../PublicAPI.Unshipped.txt | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs index 3f98aa8b..038a283f 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs @@ -65,6 +65,17 @@ namespace Microsoft.CodeAnalysis.Testing /// The to be used. protected abstract IEnumerable GetCodeRefactoringProviders(); + /// + /// Creates a code refactoring context to be used for testing. + /// + /// Document to refactor. + /// Text span within the to refactor. + /// Delegate to register a for the refactoring. + /// Cancellation token. + /// New . + protected virtual CodeRefactoringContext CreateCodeRefactoringContext(Document document, TextSpan span, Action registerRefactoring, CancellationToken cancellationToken) + => new CodeRefactoringContext(document, span, registerRefactoring, cancellationToken); + protected override async Task RunImplAsync(CancellationToken cancellationToken) { Verify.NotEmpty($"{nameof(TestState)}.{nameof(SolutionState.Sources)}", TestState.Sources); @@ -258,7 +269,7 @@ namespace Microsoft.CodeAnalysis.Testing foreach (var codeRefactoringProvider in codeRefactoringProviders) { - var context = new CodeRefactoringContext(triggerDocument, location.SourceSpan, actions.Add, cancellationToken); + var context = CreateCodeRefactoringContext(triggerDocument, location.SourceSpan, actions.Add, cancellationToken); await codeRefactoringProvider.ComputeRefactoringsAsync(context).ConfigureAwait(false); } diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/PublicAPI.Unshipped.txt b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/PublicAPI.Unshipped.txt index f2aaec42..73fddc86 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/PublicAPI.Unshipped.txt +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/PublicAPI.Unshipped.txt @@ -18,3 +18,4 @@ static Microsoft.CodeAnalysis.Testing.CodeRefactoringTest.TriggerSpan static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier.VerifyRefactoringAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult expected, string fixedSource) -> System.Threading.Tasks.Task static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier.VerifyRefactoringAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, string fixedSource) -> System.Threading.Tasks.Task static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier.VerifyRefactoringAsync(string source, string fixedSource) -> System.Threading.Tasks.Task +virtual Microsoft.CodeAnalysis.Testing.CodeRefactoringTest.CreateCodeRefactoringContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Action registerRefactoring, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext