44using System ;
55using System . IO ;
66using System . Linq ;
7+ using System . Runtime . InteropServices ;
78using Coverlet . Tests . Utils ;
89using Xunit ;
910
@@ -109,7 +110,7 @@ public void TestMsbuild_CoverletOutput_Folder_FileNameExtension()
109110 public void TestMsbuild_CoverletOutput_Folder_FileNameExtension_SpecifyFramework ( )
110111 {
111112 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
112- string [ ] targetFrameworks = new string [ ] { "net6 .0" } ;
113+ string [ ] targetFrameworks = new string [ ] { "net8 .0" } ;
113114 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
114115 Assert . False ( clonedTemplateProject . IsMultipleTargetFramework ( ) ) ;
115116 string framework = clonedTemplateProject . GetTargetFrameworks ( ) . Single ( ) ;
@@ -152,7 +153,8 @@ public void TestMsbuild_CoverletOutput_Folder_FileNameWithDoubleExtension()
152153 public void Test_MultipleTargetFrameworkReport_NoCoverletOutput ( )
153154 {
154155 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
155- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
156+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
157+ string fileToCheck = "" ;
156158 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
157159 DotnetCli ( $ "test -c { _buildConfiguration } \" { clonedTemplateProject . ProjectRootPath } \" /p:CollectCoverage=true /p:Include=\" [{ ClonedTemplateProject . AssemblyName } ]*DeepThought\" /p:IncludeTestAssembly=true", out string standardOutput , out string standardError , clonedTemplateProject . ProjectRootPath ! ) ;
158160 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -168,17 +170,24 @@ public void Test_MultipleTargetFrameworkReport_NoCoverletOutput()
168170
169171 foreach ( string targetFramework in targetFrameworks )
170172 {
171- Assert . True ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.{ targetFramework } .json") ) ) ;
173+ //if targetFrameworks has more than one framework
174+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.{ targetFramework } .json") ;
175+ if ( targetFrameworks . Length == 1 )
176+ {
177+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.json") ;
178+ }
179+ Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
172180 }
173181
174- AssertCoverage ( clonedTemplateProject , "coverage.*.json" ) ;
182+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
175183 }
176184
177185 [ Fact ]
178186 public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder ( )
179187 {
180188 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
181- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
189+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
190+ string fileToCheck = "" ;
182191 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
183192 int result = DotnetCli ( $ "test -c { _buildConfiguration } \" { clonedTemplateProject . ProjectRootPath } \" /p:CollectCoverage=true /p:Include=\" [{ ClonedTemplateProject . AssemblyName } ]*DeepThought\" /p:IncludeTestAssembly=true /p:CoverletOutput=\" { clonedTemplateProject . ProjectRootPath } \" \\ ", out string standardOutput , out string standardError , clonedTemplateProject . ProjectRootPath ! ) ;
184193 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -195,18 +204,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder()
195204
196205 foreach ( string targetFramework in targetFrameworks )
197206 {
198- string fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.{ targetFramework } .json") ;
207+ //if targetFrameworks has more than one framework
208+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.{ targetFramework } .json") ;
209+ if ( targetFrameworks . Length == 1 )
210+ {
211+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "coverage.json") ;
212+ }
199213 Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
200214 }
201215
202- AssertCoverage ( clonedTemplateProject , "coverage.*.json" ) ;
216+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
203217 }
204218
205219 [ Fact ]
206220 public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithoutExtension ( )
207221 {
208222 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
209- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
223+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
224+ string fileToCheck = "" ;
210225 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
211226 DotnetCli ( $ "test -c { _buildConfiguration } \" { clonedTemplateProject . ProjectRootPath } \" /p:CollectCoverage=true /p:Include=\" [{ ClonedTemplateProject . AssemblyName } ]*DeepThought\" /p:IncludeTestAssembly=true /p:CoverletOutput=\" { clonedTemplateProject . ProjectRootPath } \" \\ file", out string standardOutput , out string standardError , clonedTemplateProject . ProjectRootPath ! ) ;
212227 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -222,17 +237,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
222237
223238 foreach ( string targetFramework in targetFrameworks )
224239 {
225- Assert . True ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .json") ) ) ;
240+ //if targetFrameworks has more than one framework
241+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .json") ;
242+ if ( targetFrameworks . Length == 1 )
243+ {
244+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.json") ;
245+ }
246+ Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
226247 }
227248
228- AssertCoverage ( clonedTemplateProject , "file.*.json" ) ;
249+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
229250 }
230251
231252 [ Fact ]
232253 public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithExtension_SpecifyFramework ( )
233254 {
255+ Assert . SkipUnless ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) , "Test requires Windows [net48]" ) ;
234256 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
235- string [ ] targetFrameworks = new string [ ] { "net6 .0" , "net8.0 " } ;
257+ string [ ] targetFrameworks = new string [ ] { "net8 .0" , "net48 " } ;
236258 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
237259 Assert . True ( clonedTemplateProject . IsMultipleTargetFramework ( ) ) ;
238260 string [ ] frameworks = clonedTemplateProject . GetTargetFrameworks ( ) ;
@@ -261,15 +283,15 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
261283 Assert . False ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .ext") ) ) ;
262284 }
263285 }
264-
265286 AssertCoverage ( clonedTemplateProject , "file.*.ext" ) ;
266287 }
267288
268289 [ Fact ]
269290 public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithExtension ( )
270291 {
271292 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
272- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
293+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
294+ string fileToCheck = "" ;
273295 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
274296 DotnetCli ( $ "test -c { _buildConfiguration } \" { clonedTemplateProject . ProjectRootPath } \" /p:CollectCoverage=true /p:Include=\" [{ ClonedTemplateProject . AssemblyName } ]*DeepThought\" /p:IncludeTestAssembly=true /p:CoverletOutput=\" { clonedTemplateProject . ProjectRootPath } \" \\ file.ext", out string standardOutput , out string standardError , clonedTemplateProject . ProjectRootPath ! ) ;
275297 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -285,17 +307,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
285307
286308 foreach ( string targetFramework in targetFrameworks )
287309 {
288- Assert . True ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .ext") ) ) ;
310+ //if targetFrameworks has more than one framework
311+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .ext") ;
312+ if ( targetFrameworks . Length == 1 )
313+ {
314+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.ext") ;
315+ }
316+ Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
289317 }
290318
291- AssertCoverage ( clonedTemplateProject , "file.*.ext" ) ;
319+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
292320 }
293321
294322 [ Fact ]
295323 public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithDoubleExtension ( )
296324 {
297325 using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
298- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
326+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
327+ string fileToCheck = "" ;
299328 UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
300329 DotnetCli ( $ "test -c { _buildConfiguration } \" { clonedTemplateProject . ProjectRootPath } \" /p:CollectCoverage=true /p:Include=\" [{ ClonedTemplateProject . AssemblyName } ]*DeepThought\" /p:IncludeTestAssembly=true /p:CoverletOutput=\" { clonedTemplateProject . ProjectRootPath } \" \\ file.ext1.ext2", out string standardOutput , out string standardError , clonedTemplateProject . ProjectRootPath ! ) ;
301330 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -311,10 +340,16 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
311340
312341 foreach ( string targetFramework in targetFrameworks )
313342 {
314- Assert . True ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.ext1.{ targetFramework } .ext2") ) ) ;
343+ //if targetFrameworks has more than one framework
344+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.ext1.{ targetFramework } .ext2") ;
345+ if ( targetFrameworks . Length == 1 )
346+ {
347+ fileToCheck = Path . Combine ( clonedTemplateProject . ProjectRootPath , "file.ext1.ext2" ) ;
348+ }
349+ Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
315350 }
316351
317- AssertCoverage ( clonedTemplateProject , "file.ext1.*.ext2" ) ;
352+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
318353 }
319354 }
320355}
0 commit comments