16
16
using Microsoft . VisualStudio . TestPlatform . ObjectModel . DataCollection ;
17
17
using Microsoft . VisualStudio . TestPlatform . ObjectModel . DataCollector . InProcDataCollector ;
18
18
using Moq ;
19
- using Moq . Language . Flow ;
20
19
using Stryker . Core . Initialisation ;
21
20
using Stryker . Core . Mutants ;
22
21
using Stryker . Core . MutationTest ;
@@ -130,18 +129,19 @@ protected TestProjectsInfo BuildTestProjectsInfo() =>
130
129
131
130
protected IReadOnlyList < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > TestCases { get ; }
132
131
133
- private static Task DiscoverTests ( ITestDiscoveryEventsHandler discoveryEventsHandler , IReadOnlyCollection < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > tests , bool aborted ) =>
134
- Task . Run ( ( ) => discoveryEventsHandler . HandleDiscoveredTests ( tests ) ) .
135
- ContinueWith ( ( _ , u ) => discoveryEventsHandler . HandleDiscoveryComplete ( ( int ) u , null , aborted ) , tests . Count ) ;
132
+ private static void DiscoverTests ( ITestDiscoveryEventsHandler discoveryEventsHandler , IReadOnlyCollection < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > tests , bool aborted )
133
+ {
134
+ discoveryEventsHandler . HandleDiscoveredTests ( tests ) ;
135
+ discoveryEventsHandler . HandleDiscoveryComplete ( tests . Count , null , aborted ) ;
136
+ }
136
137
137
138
protected Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase BuildCase ( string name , TestFrameworks framework = TestFrameworks . xUnit , string displayName = null )
138
139
=> new ( name , framework == TestFrameworks . xUnit ? _xUnitUri : _NUnitUri , _testAssemblyPath ) { Id = new Guid ( ) , DisplayName = displayName ?? name } ;
139
140
140
141
private Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase FindOrBuildCase ( string testResultId ) => TestCases . FirstOrDefault ( t => t . FullyQualifiedName == testResultId ) ?? BuildCase ( testResultId ) ;
141
142
142
- private static Task MockTestRun ( ITestRunEventsHandler testRunEvents , IReadOnlyList < TestResult > testResults ,
143
- Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase timeOutTest = null ) =>
144
- Task . Run ( ( ) =>
143
+ private static void MockTestRun ( ITestRunEventsHandler testRunEvents , IReadOnlyList < TestResult > testResults ,
144
+ Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase timeOutTest = null )
145
145
{
146
146
if ( testResults . Count == 0 )
147
147
{
@@ -174,7 +174,7 @@ private static Task MockTestRun(ITestRunEventsHandler testRunEvents, IReadOnlyLi
174
174
new TestRunChangedEventArgs ( null , Array . Empty < TestResult > ( ) , new List < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > ( ) ) ,
175
175
null ,
176
176
null ) ;
177
- } ) ;
177
+ }
178
178
179
179
protected void SetupMockTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , bool testResult , IReadOnlyList < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > testCases )
180
180
{
@@ -200,25 +200,25 @@ protected void SetupMockTestRun(Mock<IVsTestConsoleWrapper> mockVsTest, IEnumera
200
200
SetupMockTestRun ( mockVsTest , results ) ;
201
201
}
202
202
203
- protected IReturnsResult < IVsTestConsoleWrapper > SetupMockTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyList < TestResult > results ) =>
203
+ protected void SetupMockTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyList < TestResult > results ) =>
204
204
mockVsTest . Setup ( x =>
205
- x . RunTestsWithCustomTestHostAsync (
205
+ x . RunTestsWithCustomTestHost (
206
206
It . Is < IEnumerable < string > > ( t => t . Any ( source => source == _testAssemblyPath ) ) ,
207
207
It . Is < string > ( settings => ! settings . Contains ( "<Coverage" ) ) ,
208
208
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
209
209
It . IsAny < ITestRunEventsHandler > ( ) ,
210
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
210
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
211
211
( IEnumerable < string > _ , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
212
212
ITestHostLauncher _ ) => MockTestRun ( testRunEvents , results ) ) ;
213
213
214
214
protected void SetupFailingTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest ) =>
215
215
mockVsTest . Setup ( x =>
216
- x . RunTestsWithCustomTestHostAsync (
216
+ x . RunTestsWithCustomTestHost (
217
217
It . Is < IEnumerable < string > > ( t => t . Any ( source => source == _testAssemblyPath ) ) ,
218
218
It . Is < string > ( settings => ! settings . Contains ( "<Coverage" ) ) ,
219
219
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
220
220
It . IsAny < ITestRunEventsHandler > ( ) ,
221
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
221
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
222
222
( IEnumerable < string > _ , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
223
223
ITestHostLauncher _ ) =>
224
224
// generate test results
@@ -239,14 +239,15 @@ protected void SetupFailingTestRun(Mock<IVsTestConsoleWrapper> mockVsTest) =>
239
239
null ,
240
240
null ) ;
241
241
} ) ) ;
242
+
242
243
protected void SetupFrozenTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , int repeated = 1 ) =>
243
244
mockVsTest . Setup ( x =>
244
- x . RunTestsWithCustomTestHostAsync (
245
+ x . RunTestsWithCustomTestHost (
245
246
It . Is < IEnumerable < string > > ( t => t . Any ( source => source == _testAssemblyPath ) ) ,
246
247
It . Is < string > ( settings => ! settings . Contains ( "<Coverage" ) ) ,
247
248
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
248
249
It . IsAny < ITestRunEventsHandler > ( ) ,
249
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
250
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
250
251
( IEnumerable < string > _ , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
251
252
ITestHostLauncher _ ) =>
252
253
// generate test results
@@ -276,18 +277,18 @@ protected void SetupFrozenTestRun(Mock<IVsTestConsoleWrapper> mockVsTest, int re
276
277
null ) ;
277
278
}
278
279
} ) ) ;
280
+
279
281
protected void SetupFrozenVsTest ( Mock < IVsTestConsoleWrapper > mockVsTest , int repeated = 1 ) =>
280
282
mockVsTest . Setup ( x =>
281
- x . RunTestsWithCustomTestHostAsync (
283
+ x . RunTestsWithCustomTestHost (
282
284
It . Is < IEnumerable < string > > ( t => t . Any ( source => source == _testAssemblyPath ) ) ,
283
285
It . Is < string > ( settings => ! settings . Contains ( "<Coverage" ) ) ,
284
286
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
285
287
It . IsAny < ITestRunEventsHandler > ( ) ,
286
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
288
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
287
289
( IEnumerable < string > _ , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
288
290
ITestHostLauncher _ ) =>
289
291
// generate test results
290
- Task . Run ( ( ) =>
291
292
{
292
293
testRunEvents . HandleTestRunStatsChange (
293
294
new TestRunChangedEventArgs ( new TestRunStatistics ( 0 , null ) , null , null ) ) ;
@@ -303,18 +304,18 @@ protected void SetupFrozenVsTest(Mock<IVsTestConsoleWrapper> mockVsTest, int rep
303
304
304
305
if ( repeated -- > 0 )
305
306
Thread . Sleep ( 1000 ) ;
306
- } ) ) ;
307
+ } ) ;
307
308
308
309
protected void SetupMockCoverageRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyDictionary < string , string > coverageResults ) => SetupMockCoverageRun ( mockVsTest , GenerateCoverageTestResults ( coverageResults ) ) ;
309
310
310
311
protected void SetupMockCoverageRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyList < TestResult > results ) =>
311
312
mockVsTest . Setup ( x =>
312
- x . RunTestsWithCustomTestHostAsync (
313
+ x . RunTestsWithCustomTestHost (
313
314
It . Is < IEnumerable < string > > ( t => t . Any ( source => source == _testAssemblyPath ) ) ,
314
315
It . Is < string > ( settings => settings . Contains ( "<Coverage" ) ) ,
315
316
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
316
317
It . IsAny < ITestRunEventsHandler > ( ) ,
317
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
318
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
318
319
( IEnumerable < string > _ , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
319
320
ITestHostLauncher _ ) => MockTestRun ( testRunEvents , results ) ) ;
320
321
@@ -347,12 +348,12 @@ private List<TestResult> GenerateCoverageTestResults(IReadOnlyDictionary<string,
347
348
348
349
protected void SetupMockCoveragePerTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyDictionary < string , string > coverageResults ) =>
349
350
mockVsTest . Setup ( x =>
350
- x . RunTestsWithCustomTestHostAsync (
351
+ x . RunTestsWithCustomTestHost (
351
352
It . Is < IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > > ( t => t . Any ( ) ) ,
352
353
It . Is < string > ( settings => settings . Contains ( "<Coverage" ) ) ,
353
354
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
354
355
It . IsAny < ITestRunEventsHandler > ( ) ,
355
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
356
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
356
357
( IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > testCases , string _ , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
357
358
ITestHostLauncher _ ) =>
358
359
{
@@ -368,7 +369,7 @@ protected void SetupMockCoveragePerTestRun(Mock<IVsTestConsoleWrapper> mockVsTes
368
369
var result = BuildCoverageTestResult ( key , coveredList ) ;
369
370
results . Add ( result ) ;
370
371
}
371
- return MockTestRun ( testRunEvents , results ) ;
372
+ MockTestRun ( testRunEvents , results ) ;
372
373
} ) ;
373
374
374
375
protected TestResult BuildCoverageTestResult ( string key , string [ ] coveredList )
@@ -390,14 +391,14 @@ protected TestResult BuildCoverageTestResult(string key, string[] coveredList)
390
391
391
392
protected static void SetupMockPartialTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyDictionary < string , string > results ) =>
392
393
mockVsTest . Setup ( x =>
393
- x . RunTestsWithCustomTestHostAsync (
394
+ x . RunTestsWithCustomTestHost (
394
395
It . IsAny < IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > > ( ) ,
395
396
It . Is < string > ( s => ! s . Contains ( "<Coverage" ) ) ,
396
397
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
397
398
It . IsAny < ITestRunEventsHandler > ( ) ,
398
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
399
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
399
400
( IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > sources , string settings , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
400
- ITestHostLauncher _ ) => Task . Run ( ( ) =>
401
+ ITestHostLauncher _ ) =>
401
402
{
402
403
var collector = new CoverageCollector ( ) ;
403
404
var start = new TestSessionStartArgs
@@ -435,20 +436,20 @@ protected static void SetupMockPartialTestRun(Mock<IVsTestConsoleWrapper> mockVs
435
436
runResults . Add ( result ) ;
436
437
}
437
438
// setup a normal test run
438
- MockTestRun ( testRunEvents , runResults ) . Wait ( ) ;
439
+ MockTestRun ( testRunEvents , runResults ) ;
439
440
collector . TestSessionEnd ( new TestSessionEndArgs ( ) ) ;
440
- } ) ) ;
441
+ } ) ;
441
442
442
443
protected static void SetupMockTimeOutTestRun ( Mock < IVsTestConsoleWrapper > mockVsTest , IReadOnlyDictionary < string , string > results , string timeoutTest ) =>
443
444
mockVsTest . Setup ( x =>
444
- x . RunTestsWithCustomTestHostAsync (
445
+ x . RunTestsWithCustomTestHost (
445
446
It . IsAny < IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > > ( ) ,
446
447
It . IsAny < string > ( ) ,
447
448
It . Is < TestPlatformOptions > ( o => o != null && o . TestCaseFilter == null ) ,
448
449
It . IsAny < ITestRunEventsHandler > ( ) ,
449
- It . IsAny < ITestHostLauncher > ( ) ) ) . Returns (
450
+ It . IsAny < ITestHostLauncher > ( ) ) ) . Callback (
450
451
( IEnumerable < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > sources , string settings , TestPlatformOptions _ , ITestRunEventsHandler testRunEvents ,
451
- ITestHostLauncher _ ) => Task . Run ( ( ) =>
452
+ ITestHostLauncher _ ) =>
452
453
{
453
454
var collector = new CoverageCollector ( ) ;
454
455
var start = new TestSessionStartArgs
@@ -490,10 +491,10 @@ protected static void SetupMockTimeOutTestRun(Mock<IVsTestConsoleWrapper> mockVs
490
491
runResults . Add ( result ) ;
491
492
}
492
493
// setup a normal test run
493
- MockTestRun ( testRunEvents , runResults , timeOutTestCase ) . Wait ( ) ;
494
+ MockTestRun ( testRunEvents , runResults , timeOutTestCase ) ;
494
495
collector . TestSessionEnd ( new TestSessionEndArgs ( ) ) ;
495
496
496
- } ) ) ;
497
+ } ) ;
497
498
498
499
protected Mock < IVsTestConsoleWrapper > BuildVsTestRunnerPool ( StrykerOptions options ,
499
500
out VsTestRunnerPool runner , IReadOnlyCollection < Microsoft . VisualStudio . TestPlatform . ObjectModel . TestCase > testCases = null , TestProjectsInfo testProjectsInfo = null )
@@ -505,13 +506,13 @@ protected Mock<IVsTestConsoleWrapper> BuildVsTestRunnerPool(StrykerOptions optio
505
506
mockedVsTestConsole . Setup ( x => x . AbortTestRun ( ) ) ;
506
507
mockedVsTestConsole . Setup ( x => x . EndSession ( ) ) ;
507
508
ITestDiscoveryEventsHandler discoveryHandler = null ;
509
+
508
510
mockedVsTestConsole . Setup ( x =>
509
- x . DiscoverTestsAsync ( It . Is < IEnumerable < string > > ( d => d . Any ( e => e == _testAssemblyPath ) ) ,
511
+ x . DiscoverTests ( It . Is < IEnumerable < string > > ( d => d . Any ( e => e == _testAssemblyPath ) ) ,
510
512
It . IsAny < string > ( ) ,
511
- It . IsAny < ITestDiscoveryEventsHandler > ( ) ) ) . Callback (
513
+ It . IsAny < ITestDiscoveryEventsHandler > ( ) ) ) /* .Callback(
512
514
(IEnumerable<string> _, string _, ITestDiscoveryEventsHandler handler) =>
513
- discoveryHandler = handler ) . Returns ( ( ) => DiscoverTests ( discoveryHandler , testCases , false ) ) ;
514
-
515
+ discoveryHandler = handler)*/ . Callback ( ( IEnumerable < string > _ , string _ , ITestDiscoveryEventsHandler handler ) => DiscoverTests ( handler , testCases , false ) ) ;
515
516
var context = new VsTestContextInformation (
516
517
options ,
517
518
new Mock < IVsTestHelper > ( ) . Object ,
@@ -561,5 +562,4 @@ private class MockStrykerTestHostLauncher : IStrykerTestHostLauncher
561
562
562
563
public int ErrorCode { get ; }
563
564
}
564
-
565
565
}
0 commit comments