Пример #1
0
        public void Should_capture_constant_parameters_of_different_type_even_if_step_was_not_executed_yet()
        {
            try
            {
                _subject.RunScenario(
                    call => Ignored_method(),
                    call => Method_with_parameter("abc"),
                    call => Method_with_parameter(1),
                    call => Method_with_parameter(3.5),
                    call => Method_with_parameter(null),
                    call => Method_with_parameter(22.67m),
                    call => Method_with_parameter('a'),
                    call => Method_with_parameter(typeof(object)),
                    call => Method_with_parameter_and_OTHER("abc", new DateTime(2014, 05, 31)));
            }
            catch { }

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "CALL Ignored method", ResultStatus.Ignored, "ignored"),
                new StepResultExpectation(2, "CALL Method with parameter \"abc\"", ResultStatus.NotRun),
                new StepResultExpectation(3, "CALL Method with parameter \"1\"", ResultStatus.NotRun),
                new StepResultExpectation(4, "CALL Method with parameter \"3.5\"", ResultStatus.NotRun),
                new StepResultExpectation(5, "CALL Method with parameter \"\"", ResultStatus.NotRun),
                new StepResultExpectation(6, "CALL Method with parameter \"22.67\"", ResultStatus.NotRun),
                new StepResultExpectation(7, "CALL Method with parameter \"a\"", ResultStatus.NotRun),
                new StepResultExpectation(8, "CALL Method with parameter \"System.Object\"", ResultStatus.NotRun),
                new StepResultExpectation(9, "CALL Method with parameter \"abc\" and \"<?>\"", ResultStatus.NotRun)
            });
        }
Пример #2
0
        public void Should_collect_scenario_result_for_failed_parameterized_steps()
        {
            try
            {
                _subject.RunScenario(
                    given => Customer_has_bought_product("wooden desk"),
                    and => Product_has_usage_marks("wooden desk"),
                    when => Customer_gives_it_back(),
                    then => Product_is_not_accepted("wooden desk"));
            }
            catch { }

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect scenario result for failed parameterized steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Failed));
            Assert.That(result.StatusDetails, Is.EqualTo("Step 2: Product usage verification is not implemented yet"));
            Assert.That(result.Label, Is.Null);
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN Customer has bought product \"wooden desk\"", ResultStatus.Passed),
                new StepResultExpectation(2, "AND Product \"wooden desk\" has usage marks", ResultStatus.Failed, "Product usage verification is not implemented yet"),
                new StepResultExpectation(3, "WHEN Customer gives it back", ResultStatus.NotRun),
                new StepResultExpectation(4, "THEN Product \"wooden desk\" is not accepted", ResultStatus.NotRun)
            });
        }
Пример #3
0
        public void It_should_collect_scenario_result_for_ignored_scenario_with_bypassed_steps()
        {
            try
            {
                _subject.RunScenario(Step_one, Step_with_bypass, Step_with_bypass2, Step_with_ignore_assertion, Step_two);
            }
            catch { }

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect scenario result for ignored scenario with bypassed steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Ignored));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step with bypass", ResultStatus.Bypassed, BypassReason),
                new StepResultExpectation(3, "Step with bypass2", ResultStatus.Bypassed, BypassReason2),
                new StepResultExpectation(4, "Step with ignore assertion", ResultStatus.Ignored, IgnoreReason),
                new StepResultExpectation(5, "Step two", ResultStatus.NotRun)
            });
            Assert.That(result.StatusDetails, Is.EqualTo(
                            "Step 2: " + BypassReason + Environment.NewLine +
                            "Step 3: " + BypassReason2 + Environment.NewLine +
                            "Step 4: " + IgnoreReason));
        }
Пример #4
0
        public void Should_capture_method_call()
        {
            _subject.RunScenario(call => Product_is_available_in_product_storage(GetType().ToString()));

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, string.Format("CALL Product \"{0}\" is available in product storage", GetType()), ResultStatus.Passed)
            });
        }
Пример #5
0
        public void Should_capture_local_variable()
        {
            string name = GetType().Name;

            _subject.RunScenario(call => Product_is_available_in_product_storage(name));

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, string.Format("CALL Product \"{0}\" is available in product storage", name), ResultStatus.Passed)
            });
        }
Пример #6
0
        public void It_should_collect_scenario_result_via_fluent_interfaces()
        {
            _subject.NewScenario().Run(Step_one, Step_two);

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect scenario result via fluent interfaces"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step two", ResultStatus.Passed)
            });
        }
Пример #7
0
        public void It_should_collect_scenario_result()
        {
            _subject.RunScenario(Step_one, Step_two);
            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect scenario result"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            Assert.That(result.Categories, Is.Empty);

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step two", ResultStatus.Passed)
            });
        }
Пример #8
0
        public void Should_collect_scenario_result_with_steps_parameters_inserted_in_proper_places()
        {
            _subject.RunScenario(
                replace => Method_with_parameters_where_param_has_PARAM_value("abc"),
                insert => Method_with_parameters_where_param_is_first_param_on_list("abc_123"),
                others => Method_with_parameters_where_param_is_VALUE("abc", 5, "other param"));

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "REPLACE Method with parameters where param has \"abc\" value", ResultStatus.Passed),
                new StepResultExpectation(2, "INSERT Method with parameters where param \"abc_123\" is first param on list", ResultStatus.Passed),
                new StepResultExpectation(3, "OTHERS Method with parameters where param \"abc\" is \"5\" [lastParam: \"other param\"]", ResultStatus.Passed)
            });
        }
Пример #9
0
        public void It_should_collect_scenario_result_for_explicitly_named_scenario()
        {
            const string scenarioName = "my scenario";

#pragma warning disable 0618
            _subject.RunScenario(scenarioName, Step_one, Step_two);
#pragma warning restore 0618
            var result = _subject.Result.Scenarios.Single();
            Assert.That(result.Name, Is.EqualTo(scenarioName));
            Assert.That(result.Label, Is.Null);
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step two", ResultStatus.Passed)
            });
        }
        public void Should_collect_results_for_scenario_with_shared_context_passed_explicitly()
        {
            _subject.RunScenario(new CustomContext {
                Shared = 3
            },
                                 Step_checking_shared_value_eq_3);

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect results for scenario with shared context passed explicitly"));
            Assert.That(result.Label, Is.EqualTo("Label-1"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step checking shared value eq 3", ResultStatus.Passed)
            });
        }
        public void Should_collect_results_for_scenario_with_shared_context()
        {
            _subject.RunScenario <CustomContext>(
                Given_shared_value_is_5,
                Then_shared_value_is_passed_to_second_step_and_still_match_5);

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect results for scenario with shared context"));
            Assert.That(result.Label, Is.EqualTo("Label-12"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN shared value is 5", ResultStatus.Passed),
                new StepResultExpectation(2, "THEN shared value is passed to second step and still match 5", ResultStatus.Passed)
            });
        }
Пример #12
0
        public void Should_allow_to_reuse_existing_steps_with_action_type()
        {
            _subject.RunScenario(
                _ => Given_product_is_available_in_product_storage("wooden desk"),
                _ => When_customer_orders_this_product(),
                _ => Then_customer_receives_invoice_for_product_in_amount_pounds("wooden desk", 62),
                _ => Then_product_is_sent_to_customer());

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN product \"wooden desk\" is available in product storage", ResultStatus.Passed),
                new StepResultExpectation(2, "WHEN customer orders this product", ResultStatus.Passed),
                new StepResultExpectation(3, "THEN customer receives invoice for product \"wooden desk\" in amount \"62\" pounds", ResultStatus.Passed),
                new StepResultExpectation(4, "AND product is sent to customer", ResultStatus.Passed)
            });
        }
Пример #13
0
        public void Should_capture_parameters_just_before_call_and_evaluate_them_once()
        {
            int x = 0;

            _subject.RunScenario(
                then => Values_equal(1, Add(ref x)),
                then => Values_equal(2, Add(ref x)),
                then => Values_equal(3, Add(ref x)));

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "THEN Values equal [expected: \"1\"] [actual: \"1\"]", ResultStatus.Passed),
                new StepResultExpectation(2, "THEN Values equal [expected: \"2\"] [actual: \"2\"]", ResultStatus.Passed),
                new StepResultExpectation(3, "THEN Values equal [expected: \"3\"] [actual: \"3\"]", ResultStatus.Passed)
            });
        }
Пример #14
0
        public void Should_capture_parameters_formatted_with_invariant_culture()
        {
            _subject.RunScenario(
                call => Method_with_parameter(1234234),
                call => Method_with_parameter(3.53),
                call => Method_with_parameter(22.67m),
                call => Method_with_parameter(new DateTime(2014, 05, 31, 17, 31, 27)));

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "CALL Method with parameter \"1234234\"", ResultStatus.Passed),
                new StepResultExpectation(2, "CALL Method with parameter \"3.53\"", ResultStatus.Passed),
                new StepResultExpectation(3, "CALL Method with parameter \"22.67\"", ResultStatus.Passed),
                new StepResultExpectation(4, "CALL Method with parameter \"05/31/2014 17:31:27\"", ResultStatus.Passed)
            });
        }
Пример #15
0
        public void Should_collect_scenario_result_for_parameterized_steps_with_bypassed_steps()
        {
            _subject.RunScenario(
                call => Step_one(),
                call => Step_with_bypass(),
                call => Step_two());

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect scenario result for parameterized steps with bypassed steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Bypassed));
            Assert.That(result.StatusDetails, Is.EqualTo("Step 2: " + BypassReason));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "CALL Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "CALL Step with bypass", ResultStatus.Bypassed, BypassReason),
                new StepResultExpectation(3, "CALL Step two", ResultStatus.Passed)
            });
        }
Пример #16
0
        public void It_should_collect_step_comments()
        {
            _subject.NewScenario().Run(
                Step_one,
                Step_with_comments,
                Step_with_other_comment);

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect step comments"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step with comments", ResultStatus.Passed, null, "comment one", "comment 2"),
                new StepResultExpectation(3, "Step with other comment", ResultStatus.Passed, null, "other comment")
            });
        }
Пример #17
0
        public void Should_capture_step_name_with_parameters_having_custom_formatters()
        {
            _subject.RunScenario(
                call => Method_with_amount_percentage_and_other_value(42, 42, 42),
                call => Today_is_BEAUTIFUL_day(true),
                call => Today_is_BEAUTIFUL_day(false));

            var steps = _subject.Result.Scenarios.Single().Steps.ToArray();

            StepResultExpectation.Assert(steps, new[]
            {
                new StepResultExpectation(1, "CALL Method with amount \"$42.00\" percentage \"42%\" and other value \"42\"", ResultStatus.Passed),
                new StepResultExpectation(2, "CALL Today is \"beautiful\" day", ResultStatus.Passed),
                new StepResultExpectation(3, "CALL Today is \"ugly\" day", ResultStatus.Passed)
            });

            AssertStepName(steps[1], "CALL", "Today is \"{0}\" day", new StepParameterExpectation("beautiful", true));
            AssertStepName(steps[2], "CALL", "Today is \"{0}\" day", new StepParameterExpectation("ugly", true));
        }
        public void Should_collect_results_for_customized_scenario_with_shared_context_passed_explicitly_but_no_label()
        {
            const string scenarioName = "Scenario name";

#pragma warning disable 0618
            _subject.RunScenario(new CustomContext {
                Shared = 3
            }, scenarioName,
                                 Step_checking_shared_value_eq_3);
#pragma warning restore 0618

            var result = _subject.Result.Scenarios.Single();
            Assert.That(result.Name, Is.EqualTo(scenarioName));
            Assert.That(result.Label, Is.Null);
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step checking shared value eq 3", ResultStatus.Passed)
            });
        }
        public void Should_collect_results_for_customized_scenario_with_shared_context_but_no_label()
        {
            const string scenarioName = "Scenario name";

#pragma warning disable 0618
            _subject.RunScenario <CustomContext>(scenarioName,
                                                 Given_shared_value_is_5,
                                                 Then_shared_value_is_passed_to_second_step_and_still_match_5);
#pragma warning restore 0618

            var result = _subject.Result.Scenarios.Single();
            Assert.That(result.Name, Is.EqualTo(scenarioName));
            Assert.That(result.Label, Is.Null);
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN shared value is 5", ResultStatus.Passed),
                new StepResultExpectation(2, "THEN shared value is passed to second step and still match 5", ResultStatus.Passed)
            });
        }
Пример #20
0
        public void Should_collect_scenario_result_for_parameterized_steps()
        {
            _subject.RunScenario(
                given => Product_is_available_in_product_storage("wooden desk"),
                when => Customer_orders_this_product(),
                then => Customer_receives_invoice_for_product_in_amount_pounds("wooden desk", 62),
                then => Product_is_sent_to_customer());

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect scenario result for parameterized steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
            Assert.That(result.Label, Is.EqualTo("LABEL-57"));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN Product \"wooden desk\" is available in product storage", ResultStatus.Passed),
                new StepResultExpectation(2, "WHEN Customer orders this product", ResultStatus.Passed),
                new StepResultExpectation(3, "THEN Customer receives invoice for product \"wooden desk\" in amount \"62\" pounds", ResultStatus.Passed),
                new StepResultExpectation(4, "THEN Product is sent to customer", ResultStatus.Passed)
            });
        }
Пример #21
0
        public void Should_capture_constant_parameters_even_if_step_was_not_executed_yet()
        {
            try
            {
                _subject.RunScenario(
                    given => Customer_has_bought_product("desk"),
                    when => Customer_gives_it_back(),
                    then => Product_is_put_back_to_product_storage("desk"),
                    and => Customer_gets_money_back());
            }
            catch { }

            var result = _subject.Result.Scenarios.Single();

            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "GIVEN Customer has bought product \"desk\"", ResultStatus.Passed),
                new StepResultExpectation(2, "WHEN Customer gives it back", ResultStatus.Ignored, "Not implemented yet"),
                new StepResultExpectation(3, "THEN Product \"desk\" is put back to product storage", ResultStatus.NotRun),
                new StepResultExpectation(4, "AND Customer gets money back", ResultStatus.NotRun)
            });
        }
Пример #22
0
        public void It_should_collect_scenario_result_for_failing_scenario()
        {
            try
            {
                _subject.RunScenario(Step_one, Step_throwing_exception, Step_two);
            }
            catch
            {
            }
            const string expectedStatusDetails = "exception text";

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect scenario result for failing scenario"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Failed));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step throwing exception", ResultStatus.Failed, expectedStatusDetails),
                new StepResultExpectation(3, "Step two", ResultStatus.NotRun)
            });
            Assert.That(result.StatusDetails, Is.EqualTo("Step 2: " + expectedStatusDetails));
        }
Пример #23
0
        public void It_should_collect_scenario_result_for_ignored_scenario_steps()
        {
            try
            {
                _subject.RunScenario(Step_one, Step_with_ignore_assertion, Step_two);
            }
            catch
            {
            }
            const string expectedStatusDetails = "some reason";

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("It should collect scenario result for ignored scenario steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Ignored));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "Step with ignore assertion", ResultStatus.Ignored, expectedStatusDetails),
                new StepResultExpectation(3, "Step two", ResultStatus.NotRun)
            });
            Assert.That(result.StatusDetails, Is.EqualTo("Step 2: " + expectedStatusDetails));
        }
Пример #24
0
        public void Should_collect_scenario_result_for_ignored_parameterized_steps_with_bypassed_steps()
        {
            try
            {
                _subject.RunScenario(
                    call => Step_one(),
                    call => Step_with_bypass(),
                    call => Step_with_ignore_assertion());
            }
            catch { }

            var result = _subject.Result.Scenarios.Single();

            Assert.That(result.Name, Is.EqualTo("Should collect scenario result for ignored parameterized steps with bypassed steps"));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Ignored));
            Assert.That(result.StatusDetails, Is.EqualTo("Step 2: " + BypassReason + Environment.NewLine + "Step 3: " + IgnoreReason));
            StepResultExpectation.Assert(result.Steps, new[]
            {
                new StepResultExpectation(1, "CALL Step one", ResultStatus.Passed),
                new StepResultExpectation(2, "CALL Step with bypass", ResultStatus.Bypassed, BypassReason),
                new StepResultExpectation(3, "CALL Step with ignore assertion", ResultStatus.Ignored, IgnoreReason)
            });
        }