Пример #1
0
        public void ManyTeardownsInASingleStep(Type feature, ITestResultMessage[] results)
        {
            "Given a step with many teardowns"
                .f(() => feature = typeof(StepWithManyTeardowns));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

#if !V2
            "Then there should be two results"
                .f(() => results.Length.Should().Be(2));
#else
            "Then there should be one resilt"
                .f(() => results.Length.Should().Be(1));
#endif

            "And there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

#if !V2
            "And the first result should be generated by the step"
                .f(() => results[0].Test.DisplayName.Should().NotContainEquivalentOf("(Teardown)"));

            "And the second result should be generated by the teardown"
                .f(() => results[1].Test.DisplayName.Should().Contain("(Teardown)"));
#endif

            "Ann the teardowns should be executed in reverse order after the step"
                .f(() => typeof(TeardownFeature).GetTestEvents()
                    .Should().Equal("step1", "teardown3", "teardown2", "teardown1"));
        }
        public void AsyncScenario(Type feature, ITestResultMessage[] results)
        {
            "Given an async scenario"
                .f(() => feature = typeof(FeatureWithAsyncScenario));

            "When I run the scenarios"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "Then the result should be a pass"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());
        }
        public void MemberDataProperty(Type feature, ITestResultMessage[] results)
        {
            "Given {0}"
                .f(() => { });

            "When I run the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "Then there should be three results"
                .f(() => results.Length.Should().Be(3));

            "Then each of the member data value sets should be passed into the scenario"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());
        }
        public void ThrowsAfter(Type feature, ITestResultMessage[] results)
        {
            "Given a scenario with a throw after attribute"
                .f(() => feature = typeof(ScenarioWithThrowAfterAttribute));

            "When I run the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

#if V2
            "Then there is a single test failure"
                .f(() => results.Should().ContainSingle(result => result is ITestFailed));
#else
            "Then there are three test failures"
                .f(() => results.OfType<ITestFailed>().Count().Should().Be(3));
#endif
        }
        public void BackgroundSteps(Type feature, ITestResultMessage[] results)
        {
            "Given a {0}"
                .f(() => { });

            "When I run the scenarios"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "Then the background steps are run before each scenario"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

            "And there are eight results"
                .f(() => results.Length.Should().Be(8));

            "And the background steps have '(Background)' in their names"
                .f(() =>
                {
                    foreach (var result in results.Take(2).Concat(results.Skip(4).Take(2)))
                    {
                        result.Test.DisplayName.Should().Contain("(Background)");
                    }
                });
        }
        public void ManyDisposablesInASingleStep(Type feature, ITestResultMessage[] results)
        {
            "Given {0}"
                .f(() => { });

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "And there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

#if !V2
            "And all but the last result should not be generated by a teardown"
                .f(() => results.Reverse().Skip(1).Should().NotContain(
                    result => result.Test.DisplayName.IndexOf("(Teardown)", StringComparison.OrdinalIgnoreCase) >= 0));

            "And the last result should be generated by a teardown"
                .f(() => results.Last().Test.DisplayName.Should().Contain("(Teardown)"));
#endif

            "And the disposables should each have been disposed in reverse order"
                .f(() => typeof(ObjectDisposalFeature).GetTestEvents()
                    .Should().Equal("disposed3", "disposed2", "disposed1"));
        }
Пример #7
0
        public void ManyTeardownsInManySteps(Type feature, ITestResultMessage[] results)
        {
            "Given two steps with three teardowns each"
                .f(() => feature = typeof(TwoStepsWithThreeTeardownsEach));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

#if !V2
            "Then there should be three results"
                .f(() => results.Length.Should().Be(3));
#else
            "Then there should be two results"
                .f(() => results.Length.Should().Be(2));
#endif

            "And there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

            "And the teardowns should be executed in reverse order after the steps"
                .f(() => typeof(TeardownFeature).GetTestEvents().Should().Equal(
                    "step1", "step2", "teardown6", "teardown5", "teardown4", "teardown3", "teardown2", "teardown1"));
        }
Пример #8
0
        public void MultipleContexts(Type feature, ITestResultMessage[] results)
        {
            "Given a step with a teardown and steps which generate two contexts"
                .f(() => feature = typeof(SingleStepTwoContexts));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "Then there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

            "And the teardown should be executed after each context"
                .f(() => typeof(TeardownFeature).GetTestEvents().Should().Equal(
                    "step1.1", "step1.2", "step1.3", "teardown1.1", "step2.1", "step2.2", "step2.4", "teardown2.1"));
        }
        public void AsyncStepExceedsTimeout(Type feature, ITestResultMessage[] results)
        {
            "Given a feature with a scenario with a single step which exceeds it's 1ms timeout"._(() =>
                feature = typeof(AsyncStepWhichExceedsTimeout));

            "When I run the scenarios"._(() =>
                results = this.Run<ITestResultMessage>(feature));

            "Then there should be one result"._(() =>
                results.Count().Should().Be(1));

            "And the result should be a failure"._(() =>
                results.Should().ContainItemsAssignableTo<ITestFailed>());

            "And the result message should be \"Test execution time exceeded: 1ms\""._(() =>
                results.Cast<ITestFailed>().Should().OnlyContain(result =>
                    result.Messages.Single() == "Test execution time exceeded: 1ms"));
        }
Пример #10
0
        public void AsyncVoidStepThrowsException(Type feature, ITestResultMessage[] results)
        {
            "Given a feature with a scenario that throws an invalid operation exception"._(() =>
                feature = typeof(AsyncVoidStepWhichThrowsException));

            "When I run the scenarios"._(() =>
                results = this.Run<ITestResultMessage>(feature));

            "Then the result should be a failure"._(() =>
                results.Should().ContainItemsAssignableTo<ITestFailed>());

            "And the exception should be an invalid operation exception".f(() =>
                results.Cast<ITestFailed>().First().ExceptionTypes.Single().Should().Be("System.InvalidOperationException"));
        }
        public void DisposablesWhichCreateNewDisposablesWhenDisposed(
            Type feature, ITestResultMessage[] results)
        {
            ("Given a step with disposables which, when disposed," +
                "throw an exception and add more disposables which throw an exception when disposed")
                .f(() => feature = typeof(StepWithThreeRecursiveBadDisposables));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "Then the results should not be empty"
                .f(() => results.Should().NotBeEmpty());

            "And the first n-2 results should not be failures"
                .f(() => results.Reverse().Skip(2).Should().NotContain(result => result is ITestFailed));

            "And the last 2 results should be failures"
                .f(() => results.Reverse().Take(2).Should().ContainItemsAssignableTo<ITestFailed>());

            "And the disposables should be disposed in reverse order"
                .f(() => typeof(ObjectDisposalFeature).GetTestEvents()
                    .Should().Equal("disposed3", "disposed2", "disposed1"));
        }
        public void DisposablesAndTeardowns(Type feature, ITestResultMessage[] results)
        {
            "Given steps with disposables and teardowns"
                .f(() => feature = typeof(StepsWithDisposablesAndTeardowns));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "And there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

            "And the disposables and teardowns should be disposed/executed in reverse order"
                .f(() => typeof(ObjectDisposalFeature).GetTestEvents()
                    .Should().Equal("teardown4", "disposed3", "teardown2", "disposed1"));
        }
        public void MultipleContexts(Type feature, ITestResultMessage[] results)
        {
            "Given a step with a disposable and steps which generate two contexts"
                .f(() => feature = typeof(TwoContexts));

            "When running the scenario"
                .f(() => results = this.Run<ITestResultMessage>(feature));

            "And there should be no failures"
                .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>());

            "And the disposable should be disposed after each context"
                .f(() => typeof(ObjectDisposalFeature).GetTestEvents()
                    .Should().Equal("step1", "disposed1", "step2", "disposed2"));
        }