@@ -50,7 +50,7 @@ public abstract partial class CodeFixVerifier : DiagnosticVerifier
5050 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
5151 protected Task VerifyCSharpFixAsync ( string oldSource , string newSource , string batchNewSource = null , int ? codeFixIndex = null , bool allowNewCompilerDiagnostics = false , int numberOfIncrementalIterations = DefaultNumberOfIncrementalIterations , int numberOfFixAllIterations = 1 , CancellationToken cancellationToken = default ( CancellationToken ) )
5252 {
53- return this . VerifyCSharpFixAsync ( new [ ] { oldSource } , new [ ] { newSource } , batchNewSource == null ? null : new [ ] { batchNewSource } , codeFixIndex , allowNewCompilerDiagnostics , numberOfIncrementalIterations , numberOfFixAllIterations , cancellationToken ) ;
53+ return this . VerifyCSharpFixAsync ( new [ ] { oldSource } , new [ ] { newSource } , batchNewSource == null ? null : new [ ] { batchNewSource } , null , codeFixIndex , allowNewCompilerDiagnostics , numberOfIncrementalIterations , numberOfFixAllIterations , cancellationToken ) ;
5454 }
5555
5656 /// <summary>
@@ -59,6 +59,7 @@ public abstract partial class CodeFixVerifier : DiagnosticVerifier
5959 /// <param name="oldSources">An array of sources in the form of strings before the code fix was applied to them.</param>
6060 /// <param name="newSources">An array of sources in the form of strings after the code fix was applied to them.</param>
6161 /// <param name="batchNewSources">An array of sources in the form of a strings after the batch fixer was applied to them.</param>
62+ /// <param name="newFileNames">An array of file names in the project after the code fix was applied.</param>
6263 /// <param name="codeFixIndex">Index determining which code fix to apply if there are multiple.</param>
6364 /// <param name="allowNewCompilerDiagnostics">A value indicating whether or not the test will fail if the code fix introduces other warnings after being applied.</param>
6465 /// <param name="numberOfIncrementalIterations">The number of iterations the incremental fixer will be called.
@@ -68,9 +69,9 @@ public abstract partial class CodeFixVerifier : DiagnosticVerifier
6869 /// value is less than 0, the negated value is treated as an upper limit as opposed to an exact value.</param>
6970 /// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param>
7071 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
71- protected async Task VerifyCSharpFixAsync ( string [ ] oldSources , string [ ] newSources , string [ ] batchNewSources = null , int ? codeFixIndex = null , bool allowNewCompilerDiagnostics = false , int numberOfIncrementalIterations = DefaultNumberOfIncrementalIterations , int numberOfFixAllIterations = 1 , CancellationToken cancellationToken = default ( CancellationToken ) )
72+ protected async Task VerifyCSharpFixAsync ( string [ ] oldSources , string [ ] newSources , string [ ] batchNewSources = null , string [ ] newFileNames = null , int ? codeFixIndex = null , bool allowNewCompilerDiagnostics = false , int numberOfIncrementalIterations = DefaultNumberOfIncrementalIterations , int numberOfFixAllIterations = 1 , CancellationToken cancellationToken = default ( CancellationToken ) )
7273 {
73- var t1 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , newSources , codeFixIndex , allowNewCompilerDiagnostics , numberOfIncrementalIterations , FixEachAnalyzerDiagnosticAsync , cancellationToken ) . ConfigureAwait ( false ) ;
74+ var t1 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , newSources , newFileNames , codeFixIndex , allowNewCompilerDiagnostics , numberOfIncrementalIterations , FixEachAnalyzerDiagnosticAsync , cancellationToken ) . ConfigureAwait ( false ) ;
7475
7576 var fixAllProvider = this . GetCSharpCodeFixProvider ( ) . GetFixAllProvider ( ) ;
7677 Assert . NotEqual ( WellKnownFixAllProviders . BatchFixer , fixAllProvider ) ;
@@ -86,19 +87,19 @@ public abstract partial class CodeFixVerifier : DiagnosticVerifier
8687 await t1 ;
8788 }
8889
89- var t2 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInDocumentAsync , cancellationToken ) . ConfigureAwait ( false ) ;
90+ var t2 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , newFileNames , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInDocumentAsync , cancellationToken ) . ConfigureAwait ( false ) ;
9091 if ( Debugger . IsAttached )
9192 {
9293 await t2 ;
9394 }
9495
95- var t3 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInProjectAsync , cancellationToken ) . ConfigureAwait ( false ) ;
96+ var t3 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , newFileNames , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInProjectAsync , cancellationToken ) . ConfigureAwait ( false ) ;
9697 if ( Debugger . IsAttached )
9798 {
9899 await t3 ;
99100 }
100101
101- var t4 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInSolutionAsync , cancellationToken ) . ConfigureAwait ( false ) ;
102+ var t4 = this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , oldSources , batchNewSources ?? newSources , newFileNames , codeFixIndex , allowNewCompilerDiagnostics , numberOfFixAllIterations , FixAllAnalyzerDiagnosticsInSolutionAsync , cancellationToken ) . ConfigureAwait ( false ) ;
102103 if ( Debugger . IsAttached )
103104 {
104105 await t4 ;
@@ -128,7 +129,7 @@ public abstract partial class CodeFixVerifier : DiagnosticVerifier
128129 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
129130 protected async Task VerifyCSharpFixAllFixAsync ( string oldSource , string newSource , int ? codeFixIndex = null , bool allowNewCompilerDiagnostics = false , int numberOfIterations = 1 , CancellationToken cancellationToken = default ( CancellationToken ) )
130131 {
131- await this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , new [ ] { oldSource } , new [ ] { newSource } , codeFixIndex , allowNewCompilerDiagnostics , numberOfIterations , FixAllAnalyzerDiagnosticsInDocumentAsync , cancellationToken ) . ConfigureAwait ( false ) ;
132+ await this . VerifyFixInternalAsync ( LanguageNames . CSharp , this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) , this . GetCSharpCodeFixProvider ( ) , new [ ] { oldSource } , new [ ] { newSource } , null , codeFixIndex , allowNewCompilerDiagnostics , numberOfIterations , FixAllAnalyzerDiagnosticsInDocumentAsync , cancellationToken ) . ConfigureAwait ( false ) ;
132133 }
133134
134135 /// <summary>
@@ -348,12 +349,19 @@ private async Task VerifyFixInternalAsync(
348349 CodeFixProvider codeFixProvider ,
349350 string [ ] oldSources ,
350351 string [ ] newSources ,
352+ string [ ] newFileNames ,
351353 int ? codeFixIndex ,
352354 bool allowNewCompilerDiagnostics ,
353355 int numberOfIterations ,
354356 Func < ImmutableArray < DiagnosticAnalyzer > , CodeFixProvider , int ? , Project , int , CancellationToken , Task < Project > > getFixedProject ,
355357 CancellationToken cancellationToken )
356358 {
359+ if ( newFileNames != null )
360+ {
361+ // Make sure the test case is consistent regarding the number of expected sources and file names
362+ Assert . Equal ( $ "{ newSources . Length } file names", $ "{ newFileNames . Length } file names") ;
363+ }
364+
357365 var project = this . CreateProject ( oldSources , language ) ;
358366 var compilerDiagnostics = await GetCompilerDiagnosticsAsync ( project , cancellationToken ) . ConfigureAwait ( false ) ;
359367
@@ -390,6 +398,11 @@ private async Task VerifyFixInternalAsync(
390398 {
391399 var actual = await GetStringFromDocumentAsync ( updatedDocuments [ i ] , cancellationToken ) . ConfigureAwait ( false ) ;
392400 Assert . Equal ( newSources [ i ] , actual ) ;
401+
402+ if ( newFileNames != null )
403+ {
404+ Assert . Equal ( newFileNames [ i ] , updatedDocuments [ i ] . Name ) ;
405+ }
393406 }
394407 }
395408
0 commit comments