4
4
using System ;
5
5
using System . IO ;
6
6
using System . Linq ;
7
+ using System . Runtime . InteropServices ;
7
8
using Coverlet . Tests . Utils ;
8
9
using Xunit ;
9
10
@@ -109,7 +110,7 @@ public void TestMsbuild_CoverletOutput_Folder_FileNameExtension()
109
110
public void TestMsbuild_CoverletOutput_Folder_FileNameExtension_SpecifyFramework ( )
110
111
{
111
112
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
112
- string [ ] targetFrameworks = new string [ ] { "net6 .0" } ;
113
+ string [ ] targetFrameworks = new string [ ] { "net8 .0" } ;
113
114
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
114
115
Assert . False ( clonedTemplateProject . IsMultipleTargetFramework ( ) ) ;
115
116
string framework = clonedTemplateProject . GetTargetFrameworks ( ) . Single ( ) ;
@@ -152,7 +153,8 @@ public void TestMsbuild_CoverletOutput_Folder_FileNameWithDoubleExtension()
152
153
public void Test_MultipleTargetFrameworkReport_NoCoverletOutput ( )
153
154
{
154
155
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
155
- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
156
+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
157
+ string fileToCheck = "" ;
156
158
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
157
159
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 ! ) ;
158
160
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -168,17 +170,24 @@ public void Test_MultipleTargetFrameworkReport_NoCoverletOutput()
168
170
169
171
foreach ( string targetFramework in targetFrameworks )
170
172
{
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 } ") ;
172
180
}
173
181
174
- AssertCoverage ( clonedTemplateProject , "coverage.*.json" ) ;
182
+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
175
183
}
176
184
177
185
[ Fact ]
178
186
public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder ( )
179
187
{
180
188
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
181
- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
189
+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
190
+ string fileToCheck = "" ;
182
191
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
183
192
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 ! ) ;
184
193
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -195,18 +204,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder()
195
204
196
205
foreach ( string targetFramework in targetFrameworks )
197
206
{
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
+ }
199
213
Assert . True ( File . Exists ( fileToCheck ) , $ "Expected file '{ fileToCheck } '\n Output:\n { standardOutput } ") ;
200
214
}
201
215
202
- AssertCoverage ( clonedTemplateProject , "coverage.*.json" ) ;
216
+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
203
217
}
204
218
205
219
[ Fact ]
206
220
public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithoutExtension ( )
207
221
{
208
222
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
209
- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
223
+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
224
+ string fileToCheck = "" ;
210
225
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
211
226
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 ! ) ;
212
227
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -222,17 +237,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
222
237
223
238
foreach ( string targetFramework in targetFrameworks )
224
239
{
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 } ") ;
226
247
}
227
248
228
- AssertCoverage ( clonedTemplateProject , "file.*.json" ) ;
249
+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
229
250
}
230
251
231
252
[ Fact ]
232
253
public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithExtension_SpecifyFramework ( )
233
254
{
255
+ Assert . SkipUnless ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) , "Test requires Windows [net48]" ) ;
234
256
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
235
- string [ ] targetFrameworks = new string [ ] { "net6 .0" , "net8.0 " } ;
257
+ string [ ] targetFrameworks = new string [ ] { "net8 .0" , "net48 " } ;
236
258
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
237
259
Assert . True ( clonedTemplateProject . IsMultipleTargetFramework ( ) ) ;
238
260
string [ ] frameworks = clonedTemplateProject . GetTargetFrameworks ( ) ;
@@ -261,15 +283,15 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
261
283
Assert . False ( File . Exists ( Path . Combine ( clonedTemplateProject . ProjectRootPath , $ "file.{ targetFramework } .ext") ) ) ;
262
284
}
263
285
}
264
-
265
286
AssertCoverage ( clonedTemplateProject , "file.*.ext" ) ;
266
287
}
267
288
268
289
[ Fact ]
269
290
public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithExtension ( )
270
291
{
271
292
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
272
- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
293
+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
294
+ string fileToCheck = "" ;
273
295
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
274
296
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 ! ) ;
275
297
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -285,17 +307,24 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
285
307
286
308
foreach ( string targetFramework in targetFrameworks )
287
309
{
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 } ") ;
289
317
}
290
318
291
- AssertCoverage ( clonedTemplateProject , "file.*.ext" ) ;
319
+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
292
320
}
293
321
294
322
[ Fact ]
295
323
public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWithDoubleExtension ( )
296
324
{
297
325
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject ( ) ;
298
- string [ ] targetFrameworks = new string [ ] { "net6.0" , "net8.0" } ;
326
+ string [ ] targetFrameworks = new string [ ] { "net8.0" } ;
327
+ string fileToCheck = "" ;
299
328
UpdateProjectTargetFramework ( clonedTemplateProject , targetFrameworks ) ;
300
329
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 ! ) ;
301
330
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -311,10 +340,16 @@ public void Test_MultipleTargetFrameworkReport_CoverletOutput_Folder_FileNameWit
311
340
312
341
foreach ( string targetFramework in targetFrameworks )
313
342
{
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 } ") ;
315
350
}
316
351
317
- AssertCoverage ( clonedTemplateProject , "file.ext1.*.ext2" ) ;
352
+ AssertCoverage ( clonedTemplateProject , Path . GetFileName ( fileToCheck ) ) ;
318
353
}
319
354
}
320
355
}
0 commit comments