@@ -81,7 +81,71 @@ 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 ) ;
117+ }
118+
119+ /// <summary>
120+ /// Verifies that a wrong file name with no extension is correctly reported and fixed. This is a regression test
121+ /// for DotNetAnalyzers/StyleCopAnalyzers#1829.
122+ /// </summary>
123+ /// <param name="typeKeyword">The type keyword to use during the test.</param>
124+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
125+ [ Theory ]
126+ [ MemberData ( nameof ( TypeKeywords ) ) ]
127+ public async Task VerifyWrongFileNameNoExtensionAsync ( string typeKeyword )
128+ {
129+ var testCode = $@ "namespace TestNameSpace
130+ {{
131+ public { typeKeyword } TestType
132+ {{
133+ }}
134+ }}
135+ " ;
136+
137+ var fixedCode = $@ "namespace TestNamespace
138+ {{
139+ public { typeKeyword } TestType
140+ {{
141+ }}
142+ }}
143+ " ;
144+
145+ var expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "WrongFileName" , 3 , 13 + typeKeyword . Length ) ;
146+ await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "WrongFileName" ) . ConfigureAwait ( false ) ;
147+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None , "TestType" ) . ConfigureAwait ( false ) ;
148+ await this . VerifyRenameAsync ( testCode , "WrongFileName" , "TestType" , CancellationToken . None ) . ConfigureAwait ( false ) ;
85149 }
86150
87151 /// <summary>
@@ -171,7 +235,7 @@ public async Task VerifyStyleCopNamingConventionForGenericTypeAsync(string typeK
171235 await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "TestType`3.cs" ) . ConfigureAwait ( false ) ;
172236 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None , "TestType.cs" ) . ConfigureAwait ( false ) ;
173237 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 ) ;
238+ await this . VerifyRenameAsync ( testCode , "TestType`3.cs" , "TestType {T1,T2,T3}.cs", CancellationToken . None ) . ConfigureAwait ( false ) ;
175239 }
176240
177241 /// <summary>
@@ -199,7 +263,41 @@ public async Task VerifyMetadataNamingConventionForGenericTypeAsync(string typeK
199263 expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "TestType.cs" , 3 , 13 + typeKeyword . Length ) ;
200264 await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "TestType.cs" ) . ConfigureAwait ( false ) ;
201265 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None , "TestType`3.cs" ) . ConfigureAwait ( false ) ;
202- await this . VerifyRenameAsync ( testCode , "TestType`3.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
266+ await this . VerifyRenameAsync ( testCode , "TestType.cs" , "TestType`3.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
267+ }
268+
269+ /// <summary>
270+ /// Verifies that a wrong metadata file name with multiple extensions is correctly reported and fixed. This is a
271+ /// regression test for DotNetAnalyzers/StyleCopAnalyzers#1829.
272+ /// </summary>
273+ /// <param name="typeKeyword">The type keyword to use during the test.</param>
274+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
275+ [ Theory ]
276+ [ MemberData ( nameof ( TypeKeywords ) ) ]
277+ public async Task VerifyMetadataNamingConventionForGenericTypeMultipleExtensionsAsync ( string typeKeyword )
278+ {
279+ this . useMetadataSettings = true ;
280+
281+ var testCode = $@ "namespace TestNameSpace
282+ {{
283+ public { typeKeyword } TestType<T>
284+ {{
285+ }}
286+ }}
287+ " ;
288+
289+ var fixedCode = $@ "namespace TestNamespace
290+ {{
291+ public { typeKeyword } TestType<T>
292+ {{
293+ }}
294+ }}
295+ " ;
296+
297+ var expectedDiagnostic = this . CSharpDiagnostic ( ) . WithLocation ( "TestType.svc.cs" , 3 , 13 + typeKeyword . Length ) ;
298+ await this . VerifyCSharpDiagnosticAsync ( testCode , expectedDiagnostic , CancellationToken . None , "TestType.svc.cs" ) . ConfigureAwait ( false ) ;
299+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None , "TestType`1.svc.cs" ) . ConfigureAwait ( false ) ;
300+ await this . VerifyRenameAsync ( testCode , "TestType.svc.cs" , "TestType`1.svc.cs" , CancellationToken . None ) . ConfigureAwait ( false ) ;
203301 }
204302
205303 /// <summary>
@@ -235,10 +333,10 @@ protected override string GetSettings()
235333 return this . useMetadataSettings ? MetadataSettings : StyleCopSettings ;
236334 }
237335
238- private async Task VerifyRenameAsync ( string source , string expectedFileName , CancellationToken cancellationToken )
336+ private async Task VerifyRenameAsync ( string source , string sourceFileName , string expectedFileName , CancellationToken cancellationToken )
239337 {
240338 var analyzers = this . GetCSharpDiagnosticAnalyzers ( ) . ToImmutableArray ( ) ;
241- var document = this . CreateDocument ( source , LanguageNames . CSharp ) ;
339+ var document = this . CreateDocument ( source , LanguageNames . CSharp , sourceFileName ) ;
242340 var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync ( analyzers , new [ ] { document } , cancellationToken ) . ConfigureAwait ( false ) ;
243341
244342 Assert . Equal ( 1 , analyzerDiagnostics . Length ) ;
0 commit comments