@@ -89,6 +89,7 @@ public void Should_Set_The_TestAdapter()
89
89
new TestUserRunSettingsProjectDetails
90
90
{
91
91
CoverageOutputFolder = "" ,
92
+ TestDllFile = "" ,
92
93
Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
93
94
ExcludedReferencedProjects = new List < string > ( ) ,
94
95
IncludedReferencedProjects = new List < string > ( ) ,
@@ -116,6 +117,7 @@ public void Should_Set_The_ResultsDirectory_To_The_First_OutputFolder(string out
116
117
new TestUserRunSettingsProjectDetails
117
118
{
118
119
CoverageOutputFolder = outputFolder1 ,
120
+ TestDllFile = "" ,
119
121
Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
120
122
ExcludedReferencedProjects = new List < string > ( ) ,
121
123
IncludedReferencedProjects = new List < string > ( ) ,
@@ -126,6 +128,7 @@ public void Should_Set_The_ResultsDirectory_To_The_First_OutputFolder(string out
126
128
new TestUserRunSettingsProjectDetails
127
129
{
128
130
CoverageOutputFolder = outputFolder2 ,
131
+ TestDllFile = "" ,
129
132
Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
130
133
ExcludedReferencedProjects = new List < string > ( ) ,
131
134
IncludedReferencedProjects = new List < string > ( ) ,
@@ -157,7 +160,6 @@ TestMsCodeCoverageOptions CreateSettings(string id)
157
160
return new TestMsCodeCoverageOptions
158
161
{
159
162
IncludeTestAssembly = true ,
160
-
161
163
AttributesExclude = new string [ ] { $ "AttributeExclude{ id } " } ,
162
164
AttributesInclude = new string [ ] { $ "AttributeInclude{ id } " } ,
163
165
CompanyNamesExclude = new string [ ] { $ "CompanyNameExclude{ id } " } ,
@@ -178,6 +180,7 @@ TestMsCodeCoverageOptions CreateSettings(string id)
178
180
new TestUserRunSettingsProjectDetails
179
181
{
180
182
CoverageOutputFolder = "" ,
183
+ TestDllFile = "" ,
181
184
Settings = CreateSettings ( "1" ) ,
182
185
ExcludedReferencedProjects = new List < string > ( ) ,
183
186
IncludedReferencedProjects = new List < string > ( ) ,
@@ -188,6 +191,7 @@ TestMsCodeCoverageOptions CreateSettings(string id)
188
191
new TestUserRunSettingsProjectDetails
189
192
{
190
193
CoverageOutputFolder = "" ,
194
+ TestDllFile = "" ,
191
195
Settings = CreateSettings ( "2" ) ,
192
196
ExcludedReferencedProjects = new List < string > ( ) ,
193
197
IncludedReferencedProjects = new List < string > ( ) ,
@@ -276,8 +280,9 @@ string GetModulePathExcludeWhenExcludingTestAssembly(bool first)
276
280
Assert . AreEqual ( expectedModulePathExcludes , replacements . ModulePathsExclude ) ;
277
281
}
278
282
279
- [ Test ]
280
- public void Should_Add_Regexed_IncludedExcluded_Referenced_Projects_To_ModulePaths ( )
283
+ [ TestCase ( true ) ]
284
+ [ TestCase ( false ) ]
285
+ public void Should_Add_Regexed_IncludedExcluded_Referenced_Projects_To_ModulePaths ( bool included )
281
286
{
282
287
var testContainers = new List < ITestContainer > ( )
283
288
{
@@ -290,48 +295,47 @@ public void Should_Add_Regexed_IncludedExcluded_Referenced_Projects_To_ModulePat
290
295
{
291
296
"Source1" ,
292
297
new TestUserRunSettingsProjectDetails
293
- {
294
- CoverageOutputFolder = "" ,
295
- Settings = new TestMsCodeCoverageOptions {
296
- IncludeTestAssembly = true ,
297
- ModulePathsExclude = new string [ ] { "ModulePathExclude" } ,
298
- ModulePathsInclude = new string [ ] { "ModulePathInclude" }
299
- } ,
300
- ExcludedReferencedProjects = new List < string > { "ExcludedReferenced1" } ,
301
- IncludedReferencedProjects = new List < string > { "IncludedReferenced1" } ,
302
- }
298
+ {
299
+ CoverageOutputFolder = "" ,
300
+ TestDllFile = "" ,
301
+ Settings = new TestMsCodeCoverageOptions
302
+ {
303
+ IncludeTestAssembly = ! included ,
304
+ ModulePathsExclude = new string [ ] { "ModulePathExclude" } ,
305
+ ModulePathsInclude = new string [ ] { "ModulePathInclude" }
306
+ } ,
307
+ ExcludedReferencedProjects = new List < string > { "ExcludedReferenced1" } ,
308
+ IncludedReferencedProjects = new List < string > { "IncludedReferenced1" } ,
309
+ }
303
310
} ,
304
311
{
305
312
"Source2" ,
306
313
new TestUserRunSettingsProjectDetails
307
314
{
308
315
CoverageOutputFolder = "" ,
309
- Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
310
- ExcludedReferencedProjects = new List < string > { "ExcludedReferenced2" } ,
311
- IncludedReferencedProjects = new List < string > { "IncludedReferenced2" } ,
316
+ TestDllFile = "" ,
317
+ Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = ! included } ,
318
+ ExcludedReferencedProjects = new List < string > { "ExcludedReferenced2" } ,
319
+ IncludedReferencedProjects = new List < string > { "IncludedReferenced2" } ,
312
320
}
313
321
} ,
314
322
} ;
315
323
316
324
var projectDetails = userRunSettingsProjectDetailsLookup . Select ( kvp => kvp . Value ) . ToList ( ) ;
317
- var allExcludedReferencesProjects = projectDetails . SelectMany ( pd => pd . ExcludedReferencedProjects ) ;
318
- var allIncludedReferencesProjects = projectDetails . SelectMany ( pd => pd . IncludedReferencedProjects ) ;
325
+ IEnumerable < string > allReferencedProjects = projectDetails . SelectMany ( pd => included ? pd . IncludedReferencedProjects : pd . ExcludedReferencedProjects ) ;
319
326
320
327
string GetExpectedExcludedOrIncludedEscaped ( IEnumerable < string > excludedOrIncludedReferenced )
321
328
{
322
329
return string . Join ( "" , excludedOrIncludedReferenced . Select ( referenced => ModulePathElement ( MsCodeCoverageRegex . RegexModuleName ( referenced ) ) ) ) ;
323
330
}
324
-
325
- var expectedModulePathExcludes = GetExpectedExcludedOrIncludedEscaped ( allExcludedReferencesProjects ) + ModulePathElement ( "ModulePathExclude" ) ;
326
- var expectedModulePathIncludes = GetExpectedExcludedOrIncludedEscaped ( allIncludedReferencesProjects ) + ModulePathElement ( "ModulePathInclude" ) ;
331
+ var expectedExcludes = GetExpectedExcludedOrIncludedEscaped ( allReferencedProjects ) + ModulePathElement ( included ? "ModulePathInclude" : "ModulePathExclude" ) ;
327
332
328
333
var replacements = runSettingsTemplateReplacementsFactory . Create ( testContainers , userRunSettingsProjectDetailsLookup , null ) ;
329
- Assert . AreEqual ( expectedModulePathExcludes , replacements . ModulePathsExclude ) ;
330
- Assert . AreEqual ( expectedModulePathIncludes , replacements . ModulePathsInclude ) ;
334
+ Assert . AreEqual ( expectedExcludes , included ? replacements . ModulePathsInclude : replacements . ModulePathsExclude ) ;
331
335
}
332
336
333
337
[ Test ]
334
- public void Should_Be_Empty_String_Replacement_When_Null ( )
338
+ public void Should_Be_Null_TestAdapter_Replacement_When_Null ( )
335
339
{
336
340
var testContainers = new List < ITestContainer > ( )
337
341
{
@@ -346,6 +350,7 @@ public void Should_Be_Empty_String_Replacement_When_Null()
346
350
new TestUserRunSettingsProjectDetails
347
351
{
348
352
CoverageOutputFolder = "" ,
353
+ TestDllFile = "" ,
349
354
Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
350
355
ExcludedReferencedProjects = new List < string > ( ) ,
351
356
IncludedReferencedProjects = new List < string > ( ) ,
@@ -356,14 +361,15 @@ public void Should_Be_Empty_String_Replacement_When_Null()
356
361
new TestUserRunSettingsProjectDetails
357
362
{
358
363
CoverageOutputFolder = "" ,
364
+ TestDllFile = "" ,
359
365
Settings = new TestMsCodeCoverageOptions { IncludeTestAssembly = true } ,
360
366
ExcludedReferencedProjects = new List < string > ( ) ,
361
367
IncludedReferencedProjects = new List < string > ( ) ,
362
368
}
363
369
}
364
370
} ;
365
371
var replacements = runSettingsTemplateReplacementsFactory . Create ( testContainers , userRunSettingsProjectDetailsLookup , null ) ;
366
- ReplacementsAssertions . AssertAllEmpty ( replacements ) ;
372
+ Assert . That ( replacements . TestAdapter , Is . Null ) ;
367
373
}
368
374
369
375
[ TestCase ( true , true , "true" ) ]
@@ -386,6 +392,7 @@ public void Should_Be_Disabled_When_All_Projects_Are_Disabled(bool project1Enabl
386
392
new TestUserRunSettingsProjectDetails
387
393
{
388
394
CoverageOutputFolder = "" ,
395
+ TestDllFile = "" ,
389
396
Settings = new TestMsCodeCoverageOptions { Enabled = project1Enabled , IncludeTestAssembly = true } ,
390
397
ExcludedReferencedProjects = new List < string > ( ) ,
391
398
IncludedReferencedProjects = new List < string > ( ) ,
@@ -396,6 +403,7 @@ public void Should_Be_Disabled_When_All_Projects_Are_Disabled(bool project1Enabl
396
403
new TestUserRunSettingsProjectDetails
397
404
{
398
405
CoverageOutputFolder = "" ,
406
+ TestDllFile = "" ,
399
407
Settings = new TestMsCodeCoverageOptions { Enabled = project2Enabled , IncludeTestAssembly = true } ,
400
408
ExcludedReferencedProjects = new List < string > ( ) ,
401
409
IncludedReferencedProjects = new List < string > ( ) ,
@@ -438,13 +446,14 @@ public void Should_Set_The_TestAdapter()
438
446
Assert . AreEqual ( "MsTestAdapterPath" , replacements . TestAdapter ) ;
439
447
}
440
448
441
- private ICoverageProject CreateCoverageProject ( Action < Mock < ICoverageProject > > furtherSetup = null )
449
+ private ICoverageProject CreateCoverageProject ( Action < Mock < ICoverageProject > > furtherSetup = null , bool includeTestAssembly = true )
442
450
{
443
451
var mockSettings = new Mock < IAppOptions > ( ) ;
444
- mockSettings . Setup ( settings => settings . IncludeTestAssembly ) . Returns ( true ) ;
452
+ mockSettings . Setup ( settings => settings . IncludeTestAssembly ) . Returns ( includeTestAssembly ) ;
445
453
var mockCoverageProject = new Mock < ICoverageProject > ( ) ;
446
454
mockCoverageProject . Setup ( cp => cp . ExcludedReferencedProjects ) . Returns ( new List < string > ( ) ) ;
447
455
mockCoverageProject . Setup ( cp => cp . IncludedReferencedProjects ) . Returns ( new List < string > ( ) ) ;
456
+ mockCoverageProject . Setup ( cp => cp . TestDllFile ) . Returns ( "" ) ;
448
457
mockCoverageProject . Setup ( cp => cp . Settings ) . Returns ( mockSettings . Object ) ;
449
458
furtherSetup ? . Invoke ( mockCoverageProject ) ;
450
459
return mockCoverageProject . Object ;
@@ -498,7 +507,6 @@ void AssertReplacement(string replacement, string replacementProperty, bool isIn
498
507
}
499
508
500
509
AssertReplacement ( replacements . ModulePathsExclude , "ModulePath" , false ) ;
501
- AssertReplacement ( replacements . ModulePathsInclude , "ModulePath" , true ) ;
502
510
AssertReplacement ( replacements . FunctionsExclude , "Function" , false ) ;
503
511
AssertReplacement ( replacements . FunctionsInclude , "Function" , true ) ;
504
512
AssertReplacement ( replacements . CompanyNamesExclude , "CompanyName" , false ) ;
@@ -541,7 +549,6 @@ void AssertReplacement(string replacement, string replacementProperty, bool isIn
541
549
}
542
550
543
551
AssertReplacement ( replacements . ModulePathsExclude , "ModulePath" , false ) ;
544
- AssertReplacement ( replacements . ModulePathsInclude , "ModulePath" , true ) ;
545
552
546
553
AssertReplacement ( replacements . FunctionsExclude , "Function" , false ) ;
547
554
AssertReplacement ( replacements . FunctionsInclude , "Function" , true ) ;
@@ -556,7 +563,7 @@ void AssertReplacement(string replacement, string replacementProperty, bool isIn
556
563
}
557
564
558
565
[ Test ]
559
- public void Should_Be_Empty_String_Replacement_When_Null ( )
566
+ public void Should_Be_Null_TestAdapter_Replacement_When_Null ( )
560
567
{
561
568
var msCodeCoverageOptions = new TestCoverageProjectOptions
562
569
{
@@ -565,9 +572,7 @@ public void Should_Be_Empty_String_Replacement_When_Null()
565
572
566
573
var coverageProject = CreateCoverageProject ( mock => mock . Setup ( cp => cp . Settings ) . Returns ( msCodeCoverageOptions ) ) ;
567
574
var replacements = runSettingsTemplateReplacementsFactory . Create ( coverageProject , null ) ;
568
-
569
-
570
- ReplacementsAssertions . AssertAllEmpty ( replacements ) ;
575
+ Assert . That ( replacements . TestAdapter , Is . Null ) ;
571
576
}
572
577
573
578
[ Test ]
@@ -595,7 +600,7 @@ public void Should_Have_ModulePathsExclude_Replacements_From_ExcludedReferencedP
595
600
}
596
601
597
602
[ Test ]
598
- public void Should_Have_ModulePathsInclude_Replacements_From_IncludedReferencedProjects_And_Settings ( )
603
+ public void Should_Have_ModulePathsInclude_Replacements_From_IncludedReferencedProjects_Settings_And_Included_Test_Assembly ( )
599
604
{
600
605
var msCodeCoverageOptions = new TestCoverageProjectOptions
601
606
{
@@ -610,10 +615,11 @@ public void Should_Have_ModulePathsInclude_Replacements_From_IncludedReferencedP
610
615
{
611
616
"ModuleName"
612
617
} ) ;
618
+ mock . Setup ( cp => cp . TestDllFile ) . Returns ( @"Path\To\Test.dll" ) ;
613
619
} ) ;
614
620
615
621
var replacements = runSettingsTemplateReplacementsFactory . Create ( coverageProject , null ) ;
616
- var expectedModulePathsInclude = $ "{ ModulePathElement ( MsCodeCoverageRegex . RegexModuleName ( "ModuleName" ) ) } { ModulePathElement ( "FromSettings" ) } ";
622
+ var expectedModulePathsInclude = $ "{ ModulePathElement ( MsCodeCoverageRegex . RegexModuleName ( "ModuleName" ) ) } { ModulePathElement ( MsCodeCoverageRegex . RegexEscapePath ( @"Path\To\Test.dll" ) ) } { ModulePathElement ( "FromSettings" ) } ";
617
623
Assert . AreEqual ( expectedModulePathsInclude , replacements . ModulePathsInclude ) ;
618
624
}
619
625
0 commit comments