Ejemplo n.º 1
0
        protected ScenarioTestRunnerMock CreateRunner(Type testClass, string testMethodName)
        {
            var testCaseDiscoverer =
                new ScenarioExpectationDiscovererTests.TestableScenarioExpectationDiscoverer(new NullMessageSink())
            {
                PreEnumerateTestCases = true
            };

            var testMethod          = XunitMocks.TestMethod(testClass, testMethodName);
            var expectThatAttribute = XunitMocks.ExpectThatAttribute();
            var testCases           = testCaseDiscoverer.Discover(new TestFrameworkOptions(), testMethod, expectThatAttribute);
            var testCase            = testCases.SingleOrDefault() as ScenarioTestCase;

            if (testCase == null)
            {
                throw new NotSupportedException("Test case is not a ScenarioTestCase");
            }

            var test = new ScenarioTest(testCase, testCase.DisplayName);

            var runner = new ScenarioTestRunnerMock(test,
                                                    new NullMessageSink(),
                                                    MessageBus.Object,
                                                    test.TestCase.TestMethod.TestClass.Class.ToRuntimeType(),
                                                    new object[0],
                                                    test.TestCase.Method.ToRuntimeMethod(),
                                                    new object[0],
                                                    testCase.SkipReason,
                                                    new BeforeAfterTestAttribute[0],
                                                    Aggregator,
                                                    new CancellationTokenSource()
                                                    );

            return(runner);
        }
            public static MultipleScenariosTestCaseRunnerMock Create(Type testClass, string testMethodName, ExceptionAggregator aggregator = null, IMessageBus bus = null)
            {
                var testCaseDiscoverer =
                    new ScenarioExpectationDiscovererTests.TestableScenarioExpectationDiscoverer(new NullMessageSink())
                {
                    PreEnumerateTestCases = false
                };

                var testMethod          = XunitMocks.TestMethod(testClass, testMethodName);
                var expectThatAttribute = XunitMocks.ExpectThatAttribute();
                var testCases           = testCaseDiscoverer.Discover(new TestFrameworkOptions(), testMethod, expectThatAttribute);
                var testCase            = testCases.SingleOrDefault() as MultipleScenariosTestCase;

                if (testCase == null)
                {
                    throw new NotSupportedException("Test case is not a MultipleScenariosTestCase");
                }

                var runner = new MultipleScenariosTestCaseRunnerMock(testCase,
                                                                     testCase.DisplayName,
                                                                     testCase.SkipReason,
                                                                     new object[0],
                                                                     new NullMessageSink(),
                                                                     bus,
                                                                     aggregator,
                                                                     new CancellationTokenSource()
                                                                     );

                return(runner);
            }