private IDictionary <Type, object> CreateMethodFixtures(IXunitTestCase testCase, RunSummary runSummary) { var methodFixtureTypes = _constructorArguments .OfType <IMethodFixture>() .Select(f => f.GetType()) .ToList(); var methodFixtureFactories = _assemblyFixtureMappings.Values .OfType <IMethodFixtureFactory <object> >() .ToList(); try { _stopwatch.Restart(); var methodFixtures = MethodFixtureTypes.CreateMethodFixtures(methodFixtureTypes, methodFixtureFactories); _stopwatch.Stop(); runSummary.Aggregate(new RunSummary { Time = (decimal)_stopwatch.Elapsed.TotalSeconds }); return(methodFixtures); } catch (Exception exception) { _stopwatch.Stop(); runSummary.Aggregate(RegisterFailedRunSummary(testCase, (decimal)_stopwatch.Elapsed.TotalSeconds, exception)); return(null); } }
protected override async Task <RunSummary> RunTestCaseAsync(IXunitTestCase testCase) { if (!_hasMethodFixtures) { return(await base.RunTestCaseAsync(testCase)); } var methodFixtureTypes = _constructorArguments .OfType <IMethodFixture>() .Select(f => f.GetType()) .ToList(); var methodFixtureFactories = _assemblyFixtureMappings.Values .OfType <IMethodFixtureFactory <object> >() .ToList(); IDictionary <Type, object> methodFixtures; try { methodFixtures = MethodFixtureTypes.CreateMethodFixtures(methodFixtureTypes, methodFixtureFactories); } catch (Exception exception) { var runSummary = new RunSummary { Total = 1, Failed = 1, Time = 0 }; MessageBus.QueueMessage(new TestFailed(new XunitTest(testCase, testCase.DisplayName), runSummary.Time, string.Empty, exception)); return(runSummary); } var testCaseConstructorArguments = GetConstructorArguments(methodFixtures); var testInput = new TestInput(testCase, Class.Type, TestMethod.Method.ToRuntimeMethod(), testCase.DisplayName, testCaseConstructorArguments, testCase.TestMethodArguments); var tasks = await InitializeMethodFixturesAsync(testInput, methodFixtures, MessageBus); var runTestTask = testCase.RunAsync(_diagnosticMessageSink, MessageBus, testCaseConstructorArguments, new ExceptionAggregator(Aggregator), CancellationTokenSource); tasks.Add(runTestTask); var runSummaryTask = await Task.WhenAny(tasks); await runSummaryTask; if (runSummaryTask != runTestTask) { CancellationTokenSource.Cancel(); } await DisposeMethodFixturesAsync(runSummaryTask.Result, methodFixtures, MessageBus); return(runSummaryTask.Result); }