Esempio n. 1
0
        private static TestOutputs InjectTestOutputs(AppRunner runner)
        {
            TestOutputs outputs = new TestOutputs();

            runner.Configure(c => c.UseMiddleware((context, next) =>
            {
                context.InvocationPipeline.All
                .Select(i => i.Instance)
                .ForEach(instance =>
                {
                    instance.GetType()
                    .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                    .Where(p => p.PropertyType == typeof(TestOutputs))
                    .ForEach(p =>
                    {
                        // principal of least surprise
                        // if the test class sets the instance, then use that instance
                        var value = (TestOutputs)p.GetValue(instance);
                        if (value == null)
                        {
                            p.SetValue(instance, outputs);
                        }
                        else
                        {
                            outputs.UseOutputsFromInstance(value);
                        }
                    });
                });
                return(next(context));
            }, MiddlewareStages.PostBindValuesPreInvoke));

            return(outputs);
        }
 public AppRunnerResult(int exitCode, TestConsole testConsole, TestOutputs testOutputs, CommandContext commandContext)
 {
     _testConsole   = testConsole;
     ExitCode       = exitCode;
     TestOutputs    = testOutputs;
     CommandContext = commandContext;
 }
        internal void UseOutputsFromInstance(TestOutputs testOutputs)
        {
            if (Outputs.Count > 0)
            {
                throw new InvalidOperationException(
                          $"cannot link to a {nameof(TestOutputs)} that already has outputs recorded. keys:{Outputs.Keys.ToOrderedCsv()}");
            }

            Outputs = testOutputs.Outputs;
        }
        private static TestOutputs InjectTestOutputs(AppRunner runner)
        {
            var outputs = new TestOutputs();

            runner.Configure(c =>
            {
                c.Services.Add(outputs);
                c.UseMiddleware(InjectTestOutputs, MiddlewareStages.PostBindValuesPreInvoke);
            });

            return(outputs);
        }
 public AppRunnerResult(int exitCode, TestConsole testConsole, TestOutputs testOutputs)
 {
     _testConsole = testConsole;
     ExitCode     = exitCode;
     TestOutputs  = testOutputs;
 }