Esempio n. 1
0
        public async Task ShouldWriteUndefinedReport()
        {
            var sb     = new StringBuilder();
            var writer = XmlWriter.Create(sb, new XmlWriterSettings()
            {
                Async = true
            });
            var reportWriter   = new ReportWriter(writer);
            var scenarioReport = new ScenarioReport("Test", reportWriter, new TestMessageSink());
            var scenario       = new ScenarioRunResult("Undefined", new Given[] {}, new When("when", new Detail[] {}), new Then[] {}, null);

            scenarioReport.Report(scenario);
            await scenarioReport.WriteFinalAsync();

            var xml = XElement.Parse(sb.ToString());

            Assert.Single(xml.Descendants(Constants.XmlTagScenario));
        }
            public static async Task ExecuteTestMethodAsync <T>(ScenarioReport report,
                                                                string methodName, ScenarioRunner runner = null, object[] parameters = null)
            {
                parameters = parameters ?? new object[] { };
                var methodInfo = typeof(T).GetMethod(methodName);

                if (methodInfo == null)
                {
                    throw new InvalidOperationException($"Unknown method {methodName} on type {typeof(T)}.FullName");
                }
                var method = new FakeMethodInfo(Reflector.Wrap(methodInfo),
                                                Reflector.Wrap(typeof(T)),
                                                new [] { new FakeAttributeInfo(
                                                             parameters.Length == 0? new FactAttribute() :new TheoryAttribute(),
                                                             new object[] {},
                                                             new Dictionary <string, object>()
                    {
                        ["DisplayName"] = null, ["Skip"] = null
                    }) });
                var aggregator = new ExceptionAggregator();
                var testMethod = Mock.TestMethod <T>(method);
                var invoker    = new ScenarioReportingTestInvoker(
                    scenarioRunner: runner,
                    report: report,
                    test: new XunitTest(new ScenarioReportingXunitTestCase(new NullMessageSink(), TestMethodDisplay.ClassAndMethod, testMethod, parameters), "Test"),
                    messageBus: new MessageBus(new NullMessageSink()),
                    constructorArguments: new object[] { },
                    testClass: typeof(T),
                    testMethod: method.ToRuntimeMethod(),
                    testMethodArguments: parameters,
                    beforeAfterAttributes: new BeforeAfterTestAttribute[] { },
                    aggregator: aggregator,
                    cancellationTokenSource: new CancellationTokenSource(1000)
                    );
                await invoker.RunAsync();

                if (aggregator.HasExceptions)
                {
                    throw aggregator.ToException();
                }
                await report.WriteFinalAsync();
            }
Esempio n. 3
0
        public async Task ShouldWriteUndefinedReport()
        {
            var sb     = new StringBuilder();
            var writer = XmlWriter.Create(sb, new XmlWriterSettings()
            {
                Async = true
            });
            var reportWriter   = new ReportWriter(writer);
            var scenarioReport = new ScenarioReport("Test", reportWriter);
            var scenario       = new TestScenario {
                Title = "Undefined"
            };

            scenarioReport.Report(scenario);
            await scenarioReport.WriteFinalAsync();

            var xml = XElement.Parse(sb.ToString());

            Assert.Single(xml.Descendants(Constants.XmlTagScenario));
        }