public async Task <RunSummary> RunAsync(IXunitTestCase testCase, IServiceProvider provider, IMessageSink diagnosticMessageSink, IMessageBus messageBus, object?[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { var scope = provider.CreateScope(); await using var _ = scope.AsAsyncDisposable().ConfigureAwait(false); var raw = new Dictionary <int, object>(); foreach (var kv in FromServicesAttribute.CreateFromServices(testCase.Method.ToRuntimeMethod())) { raw[kv.Key] = testCase.TestMethodArguments[kv.Key]; testCase.TestMethodArguments[kv.Key] = kv.Value == typeof(ITestOutputHelper) ? throw new NotSupportedException("Can't inject ITestOutputHelper via method arguments when use StaFact") : provider.GetService(kv.Value); } constructorArguments = DependencyInjectionTestMethodRunner.CreateTestClassConstructorArguments(scope.ServiceProvider, constructorArguments, aggregator); var summary = await testCase.RunAsync(diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource).ConfigureAwait(false); foreach (var kv in raw) { testCase.TestMethodArguments[kv.Key] = kv.Value; } return(summary); }
/// <inheritdoc /> protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var scope = _provider.CreateScope(); await using var _ = scope.AsAsyncDisposable().ConfigureAwait(false); var testOutputHelper = _provider.GetRequiredService <ITestOutputHelperAccessor>().Output as TestOutputHelper; testOutputHelper?.Initialize(MessageBus, Test); var raw = new Dictionary <int, object>(); foreach (var kv in _fromServices) { raw[kv.Key] = TestMethodArguments[kv.Key]; TestMethodArguments[kv.Key] = kv.Value == typeof(ITestOutputHelper) ? testOutputHelper : scope.ServiceProvider.GetService(kv.Value); } var item = await new DependencyInjectionTestInvoker(scope.ServiceProvider, Test, MessageBus, TestClass, DependencyInjectionTestMethodRunner.CreateTestClassConstructorArguments(scope.ServiceProvider, ConstructorArguments, aggregator), TestMethod, TestMethodArguments, BeforeAfterAttributes, aggregator, CancellationTokenSource) .RunAsync().ConfigureAwait(false); foreach (var kv in raw) { TestMethodArguments[kv.Key] = kv.Value; } var output = string.Empty; if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(item, output)); }