@@ -81,7 +81,39 @@ public async Task VerifyWrongFileNameAsync(string typeKeyword)
8181 var expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "WrongFileName.cs" , 3 , 13 + typeKeyword . Length ) ;
8282 await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "WrongFileName.cs" ) . ConfigureAwait ( false ) ;
8383 await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None , "TestType.cs" ) . ConfigureAwait ( false ) ;
84- await this . VerifyRenameAsync ( testCode , "TestType.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
84+ await this . VerifyRenameAsync ( testCode , "WrongFileName.cs" , "TestType.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
85+ }
86+
87+ /// <summary>
88+ /// Verifies that a wrong file name with multiple extensions is correctly reported and fixed. This is a
89+ /// regression test for DotNetAnalyzers/StyleCopAnalyzers#1829.
90+ /// </summary>
91+ /// <param name="typeKeyword">The type keyword to use during the test.</param>
92+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
93+ [ Theory ]
94+ [ MemberData ( nameof ( TypeKeywords ) ) ]
95+ public async Task VerifyWrongFileNameMultipleExtensionsAsync ( string typeKeyword )
96+ {
97+ var testCode = $@ "namespace TestNameSpace
98+ {{
99+ public { typeKeyword } TestType
100+ {{
101+ }}
102+ }}
103+ " ;
104+
105+ var fixedCode = $@ "namespace TestNamespace
106+ {{
107+ public { typeKeyword } TestType
108+ {{
109+ }}
110+ }}
111+ " ;
112+
113+ var expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "WrongFileName.svc.cs" , 3 , 13 + typeKeyword . Length ) ;
114+ await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "WrongFileName.svc.cs" ) . ConfigureAwait ( false ) ;
115+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None , "TestType.svc.cs" ) . ConfigureAwait ( false ) ;
116+ await this . VerifyRenameAsync ( testCode , "WrongFileName.svc.cs" , "TestType.svc.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
85117 }
86118
87119 /// <summary>
@@ -171,7 +203,7 @@ public async Task VerifyStyleCopNamingConventionForGenericTypeAsync(string typeK
171203 await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "TestType`3.cs" ) . ConfigureAwait ( false ) ;
172204 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None , "TestType.cs" ) . ConfigureAwait ( false ) ;
173205 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None , "TestType{T1,T2,T3}.cs" ) . ConfigureAwait ( false ) ;
174- await this . VerifyRenameAsync ( testCode , "TestType{T1,T2,T3}.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
206+ await this . VerifyRenameAsync ( testCode , "TestType`3.cs" , "TestType {T1,T2,T3}.cs", CancellationToken . None ) . ConfigureAwait ( false ) ;
175207 }
176208
177209 /// <summary>
@@ -199,7 +231,7 @@ public async Task VerifyMetadataNamingConventionForGenericTypeAsync(string typeK
199231 expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "TestType.cs" , 3 , 13 + typeKeyword . Length ) ;
200232 await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "TestType.cs" ) . ConfigureAwait ( false ) ;
201233 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None , "TestType`3.cs" ) . ConfigureAwait ( false ) ;
202- await this . VerifyRenameAsync ( testCode , "TestType`3.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
234+ await this . VerifyRenameAsync ( testCode , "TestType.cs" , "TestType `3.cs", CancellationToken . None ) . ConfigureAwait ( false ) ;
203235 }
204236
205237 /// <summary>
@@ -235,10 +267,10 @@ protected override string GetSettings()
235267 return this . useMetadataSettings ? MetadataSettings : StyleCopSettings ;
236268 }
237269
238- private async Task VerifyRenameAsync ( string source , string expectedFileName , CancellationToken cancellationToken )
270+ private async Task VerifyRenameAsync ( string source , string sourceFileName , string expectedFileName , CancellationToken cancellationToken )
239271 {
240272 var analyzers = this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) ;
241- var document = this . CreateDocument ( source , LanguageNames . CSharp ) ;
273+ var document = this . CreateDocument ( source , LanguageNames . CSharp , sourceFileName ) ;
242274 var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync ( analyzers , new [ ] { document } , cancellationToken ) . ConfigureAwait ( false ) ;
243275
244276 Assert . Equal ( 1 , analyzerDiagnostics . Length ) ;
0 commit comments