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);
            }
        public ScenarioExpectationDiscovererTests()
        {
            DiagnosticsMessageSink = new NullMessageSink();
            Discoverer             = new TestableScenarioExpectationDiscoverer(DiagnosticsMessageSink);

            ExpectThatAttribute = XunitMocks.ExpectThatAttribute();
            Options             = new TestFrameworkOptions();
        }
        public void Method_with_successful_and_null_and_exception_scenarios()
        {
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_successful_and_null_and_exception_scenarios));

            var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(3);
            testCases.Cast <ScenarioTestCase>().Should().NotContainNulls();
        }
        public void Method_with_two_equivalent_scenarios()
        {
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_two_same_scenarios));

            var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(2);
            testCases.Cast <ScenarioTestCase>().Should().NotContainNulls();
        }
        public void Method_with_scenario_wrong_discoverer()
        {
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_invalid_scenario_wrong_discoverer));

            var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(1);

            testCases.First().Should().BeOfType <ExecutionErrorScenarioTestCase>();
        }
        public void Method_with_one_scenario()
        {
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_one_scenario));

            var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(1);

            testCases.First().Should().BeOfType <MultipleScenariosTestCase>();
        }
Ejemplo n.º 8
0
        public void Attribute_on_method_and_class_returned()
        {
            var testMethod = XunitMocks.TestMethod(
                typeof(TestClassWithClassScenarioAttribute),
                nameof(TestClassWithClassScenarioAttribute.TestMethodWithScenarioAttribute));

            var scenarioAttributes = testMethod.GetScenarioAttributes();

            scenarioAttributes.Should().NotBeNull();
            scenarioAttributes.Should().HaveCount(2);
        }
Ejemplo n.º 9
0
        public void No_attributes_returns_empty_list()
        {
            var testMethod = XunitMocks.TestMethod(
                typeof(TestClassWithoutClassScenarioAttribute),
                nameof(TestClassWithoutClassScenarioAttribute.TestMethodWithoutScenarioAttribute));

            var scenarioAttributes = testMethod.GetScenarioAttributes();

            scenarioAttributes.Should().NotBeNull();
            scenarioAttributes.Should().BeEmpty();
        }
Ejemplo n.º 10
0
        private static MultipleScenariosTestCase CreateTestCase()
        {
            var testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases),
                                                   nameof(XunitExtensionsTestCases.Method_with_one_scenario));
            var scenarioIdentifier = TestScenarioDiscoverer.CreateScenarioIdentifier(testMethod);

            var target = new MultipleScenariosTestCase(new NullMessageSink(), TestMethodDisplay.ClassAndMethod,
                                                       TestMethodDisplayOptions.All, testMethod, null);

            return(target);
        }
        private static ExecutionErrorScenarioTestCase CreateTestCase(string errorMessage = null)
        {
            var testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases),
                                                   nameof(XunitExtensionsTestCases.Method_with_one_scenario));
            var scenarioIdentifier = TestScenarioDiscoverer.CreateScenarioIdentifier(testMethod);

            var target = new ExecutionErrorScenarioTestCase(new NullMessageSink(), TestMethodDisplay.ClassAndMethod,
                                                            TestMethodDisplayOptions.All, testMethod, scenarioIdentifier, errorMessage);

            return(target);
        }
        public void Method_without_scenarios(bool preEnumerateTestCases)
        {
            Discoverer.PreEnumerateTestCases = preEnumerateTestCases;
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_without_scenarios));

            var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(1);

            testCases.First().Should().BeOfType <ExecutionErrorTestCase>();
        }
        public void Method_with_skip_flag(bool preEnumerateTestCases)
        {
            Discoverer.PreEnumerateTestCases = preEnumerateTestCases;
            ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_without_scenarios));

            var skippedExpectThatAttribute = XunitMocks.ExpectThatAttribute(null, "Should be skipped");
            var testCases = Discoverer.Discover(Options, testMethod, skippedExpectThatAttribute);

            testCases.Should().NotBeNull();
            testCases.Count().Should().Be(1);

            testCases.First().Should().BeOfType <XunitTestCase>();
        }
Ejemplo n.º 14
0
        public void Duplicate_attribute_on_method_and_class_returns_method_attribute()
        {
            var testMethod = XunitMocks.TestMethod(
                typeof(TestClassWithClassScenarioAttribute),
                nameof(TestClassWithClassScenarioAttribute.TestMethodWithDuplicateClassScenarioAttribute));

            var scenarioAttributes = testMethod.GetScenarioAttributes();

            scenarioAttributes.Should().NotBeNull();
            scenarioAttributes.Should().HaveCount(1);

            var attribute = (ScenarioAttribute)((IReflectionAttributeInfo)scenarioAttributes.Single()).Attribute;

            attribute.DisplayName.Should().Be("Method scenario");
        }