Пример #1
0
        public void execute_the_void_action_and_missing_an_argument()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.DoSomethingWith(null, 34), dooer);

            var step = new Step("something", x => { x.Set("name", "Josh"); });

            action.Execute(step, _testContext);

            _testContext.ResultsFor(step).ExceptionText.Contains("\"age\" is not defined.");
            theCounts.SyntaxErrors.ShouldEqual(1);
        }
Пример #2
0
        public void execute_with_exception()
        {
            FactAssertion assertion = FactAssertion.Create(x => x.Exception(), new AssertionFixture());
            var           step      = new Step();

            var context = new TestContext();

            assertion.Execute(step, context);
            context.Counts.ShouldEqual(0, 0, 1, 0);

            step.Get("returnValue").Parse <bool>().ShouldBeTrue();
            context.ResultsFor(step).ActualDisplay <bool>("returnValue").ShouldBeFalse();
            context.ResultsFor(step).ExceptionText.ShouldContain("NotImplementedException");
        }
Пример #3
0
        public void SetUp()
        {
            grammar =
                Fixture.VerifyStringList(() => { throw new NotImplementedException(); }).Titled(
                    "The list of strings should be").LeafNameIs("row").Grammar();

            step = new Step("anything").WithChildren("row", new Step(), new Step(), new Step());

            var context = new TestContext();

            grammar.Execute(step, context);
            counts = context.Counts;

            rowResults  = context.ResultsFor(step).GetResult <IList <SetRow> >(grammar.LeafName);
            stepResults = context.ResultsFor(step);
        }
        public void SetUp()
        {
            grammar =
                Fixture.VerifyStringList(() => { throw new NotImplementedException(); }).Titled(
                    "The list of strings should be").LeafNameIs("row").Grammar();

            step = new Step("anything").WithChildren("row", new Step(), new Step(), new Step());

            var context = new TestContext();

            grammar.Execute(step, context);
            counts = context.Counts;

            rowResults = context.ResultsFor(step).GetResult<IList<SetRow>>(grammar.LeafName);
            stepResults = context.ResultsFor(step);
        }
Пример #5
0
        public static StepExecutionResult Execute(this IGrammar grammar, IStep step)
        {
            var context = new TestContext();

            grammar.Execute(step, context);

            return(new StepExecutionResult {
                Counts = context.Counts,
                Results = context.ResultsFor(step)
            });
        }
Пример #6
0
        public void SetUp()
        {
            step = new Step("a").With("key1", "abc");
            cell = new Cell("key1", typeof(int));

            var context = new TestContext();

            cell.ReadArgument(context, step, x => Assert.Fail("should not have called me"));

            counts  = context.Counts;
            results = context.ResultsFor(step);
        }
Пример #7
0
        public void record_actual_stores_the_data()
        {
            MethodInfo method = ReflectionHelper.GetMethod <CellTarget>(x => x.Add(0, 0));
            Step       step   = new Step("a").With("returnValue", "10");

            Cell cell = method.GetReturnCell();
            var  data = new TestContext();

            cell.RecordActual(32.0, step, data);

            data.ResultsFor(step).ActualDisplay <double>("returnValue").ShouldEqual(32);
        }
Пример #8
0
        public void read_argument_with_a_format_exception()
        {
            Step step = new Step("a").With("age", "abc");
            var  cell = new Cell("age", typeof(int));

            var context = new TestContext();

            cell.ReadArgument(context, step, x => Assert.Fail("should not have been called"));

            context.Counts.SyntaxErrors.ShouldEqual(1);

            context.ResultsFor(step).ExceptionText.ShouldContain("Format exception for 'age'");
        }
Пример #9
0
        public void execute_successfully()
        {
            FactAssertion assertion = FactAssertion.Create(x => x.Success(), new AssertionFixture());
            var           step      = new Step();

            var context = new TestContext();

            assertion.Execute(step, context);
            context.Counts.ShouldEqual(1, 0, 0, 0);

            step.Get("returnValue").Parse <bool>().ShouldBeTrue();
            context.ResultsFor(step).ActualDisplay <bool>("returnValue").ShouldBeTrue();
        }
Пример #10
0
        public void record_actual_calls_mark_missing_value_when_the_expected_value_is_missing()
        {
            MethodInfo method = ReflectionHelper.GetMethod <CellTarget>(x => x.Add(0, 0));
            Cell       cell   = method.GetReturnCell();
            var        step   = new Step();

            var data = new TestContext();

            cell.RecordActual(32.0, step, data);

            data.ResultsFor(step).GetActual("returnValue").ShouldEqual(32.0);
            data.Counts.SyntaxErrors.ShouldEqual(1);
        }
Пример #11
0
        public void read_expected_value_from_step_that_is_boolean_missing_and_input_should_still_log_error()
        {
            var cell = new Cell("success", typeof(bool))
            {
                IsResult = false
            };
            var step = new Step();

            var context = new TestContext();

            cell.ReadArgument(context, step, o => Assert.Fail("should not have called back"));

            context.ResultsFor(step).IsInException("success").ShouldBeTrue();
        }
Пример #12
0
        public void read_expected_value_from_step_for_a_boolean_result_cell()
        {
            var cell = new Cell("success", typeof(bool))
            {
                IsResult = true
            };
            bool returnValue = false;
            var  step        = new Step();
            var  context     = new TestContext();

            cell.ReadArgument(context, step, o => returnValue = (bool)o);

            returnValue.ShouldBeTrue();
            context.ResultsFor(step).IsInException("success").ShouldBeFalse();
        }
Пример #13
0
        public void SetUp()
        {
            sentence = Sentence.For("{name} is {age}", Cell.For <string>("name"), Cell.For <int>("age"));
            step     = new Step().With("name:Max,age:6");
            tag      = new SentenceTag(sentence, step);

            context = new TestContext();
            StepResults results = context.ResultsFor(step);

            results.CaptureException("bad stuff");
            results.ExceptionText.ShouldEqual("bad stuff");


            tag.WriteResults(context);
        }
Пример #14
0
        public void catch_all_exception_on_grammar_adds_exception_count_and_exception_text()
        {
            var      step    = new Step("the step");
            var      context = new TestContext();
            IGrammar grammar = context.SetupMockGrammar(step.GrammarKey);

            grammar.Expect(x => x.Execute(step, context))
            .Throw(new NotImplementedException());

            context.RunStep(step);

            context.Counts.ShouldEqual(0, 0, 1, 0);

            context.ResultsFor(step).ExceptionText.ShouldContain("NotImplementedException");
        }
Пример #15
0
        public void log_exception_from_section_setup()
        {
            var fixture = MockRepository.GenerateMock <IFixture>();
            var context = new TestContext();

            var exception = new NotImplementedException();

            fixture.Expect(x => x.SetUp(context)).Throw(exception);

            var step = new Step();

            context.LoadFixture(fixture, step);

            context.Counts.Exceptions.ShouldEqual(1);
            context.ResultsFor(step).ExceptionText.ShouldContain(exception.ToString());
        }
Пример #16
0
        public void reverting_a_fixture_with_an_exception_in_teardown_increments_exceptions_and_captures_the_exception()
        {
            var fixture   = MockRepository.GenerateMock <IFixture>();
            var exception = new NotImplementedException();

            fixture.Expect(x => x.TearDown()).Throw(exception);

            var context = new TestContext();
            var section = new Section("something");

            context.LoadFixture(fixture, section);
            context.RevertFixture(section);

            context.ResultsFor(section).ExceptionText.ShouldEqual(exception.ToString());

            context.Counts.Exceptions.ShouldEqual(1);
        }
Пример #17
0
        public void execute_records_the_actual()
        {
            var context = new TestContext();
            var target  = new ServiceTarget
            {
                Color = "Red"
            };

            context.Store(target);

            var step = new Step();

            var grammar = new TestServiceAssertionGrammar();

            grammar.Execute(step, context);
            context.Counts.SyntaxErrors.ShouldEqual(1);
            context.ResultsFor(step).GetActual("Color").ShouldEqual("Red");
        }
Пример #18
0
        public void catch_the_storyteller_exception_on_grammar_adds_exception_count_and_exception_message_only()
        {
            var step = new Step("the step");

            var grammar = new GrammarThatAssertsFailure();
            var fixture = MockRepository.GenerateMock <IFixture>();

            fixture.Stub(x => x[step.GrammarKey]).Return(grammar);

            var context = new TestContext();

            context.LoadFixture(fixture, new StubTestPart());

            context.RunStep(step);

            context.Counts.ShouldEqual(0, 0, 1, 0);

            context.ResultsFor(step).ExceptionText.ShouldEqual("I don't want to run");
        }
Пример #19
0
        public void record_actual_calls_mark_missing_value_when_the_expected_value_is_missing()
        {
            MethodInfo method = ReflectionHelper.GetMethod<CellTarget>(x => x.Add(0, 0));
            Cell cell = method.GetReturnCell();
            var step = new Step();

            var data = new TestContext();
            cell.RecordActual(32.0, step, data);

            data.ResultsFor(step).GetActual("returnValue").ShouldEqual(32.0);
            data.Counts.SyntaxErrors.ShouldEqual(1);
        }
Пример #20
0
        public void reverting_a_fixture_with_an_exception_in_teardown_increments_exceptions_and_captures_the_exception()
        {
            var fixture = MockRepository.GenerateMock<IFixture>();
            var exception = new NotImplementedException();
            fixture.Expect(x => x.TearDown()).Throw(exception);

            var context = new TestContext();
            var section = new Section("something");

            context.LoadFixture(fixture, section);
            context.RevertFixture(section);

            context.ResultsFor(section).ExceptionText.ShouldEqual(exception.ToString());

            context.Counts.Exceptions.ShouldEqual(1);
        }
Пример #21
0
 private void captureException(string exceptionText)
 {
     _context.IncrementExceptions();
     _context.ResultsFor(_request.Test).CaptureException(exceptionText);
 }
Пример #22
0
        public void catch_the_storyteller_exception_on_grammar_adds_exception_count_and_exception_message_only()
        {
            var step = new Step("the step");

            var grammar = new GrammarThatAssertsFailure();
            var fixture = MockRepository.GenerateMock<IFixture>();
            fixture.Stub(x => x[step.GrammarKey]).Return(grammar);

            var context = new TestContext();
            context.LoadFixture(fixture, new StubTestPart());

            context.RunStep(step);

            context.Counts.ShouldEqual(0, 0, 1, 0);

            context.ResultsFor(step).ExceptionText.ShouldEqual("I don't want to run");
        }
Пример #23
0
        public void log_exception_from_section_setup()
        {
            var fixture = MockRepository.GenerateMock<IFixture>();
            var context = new TestContext();

            var exception = new NotImplementedException();
            fixture.Expect(x => x.SetUp(context)).Throw(exception);

            var step = new Step();
            context.LoadFixture(fixture, step);

            context.Counts.Exceptions.ShouldEqual(1);
            context.ResultsFor(step).ExceptionText.ShouldContain(exception.ToString());
        }
Пример #24
0
        public void SetUp()
        {
            step = new Step("a").With("key1", "abc");
            cell = new Cell("key1", typeof (int));

            var context = new TestContext();
            cell.ReadArgument(context, step, x => Assert.Fail("should not have called me"));

            counts = context.Counts;
            results = context.ResultsFor(step);
        }
Пример #25
0
        public void catch_all_exception_on_grammar_adds_exception_count_and_exception_text()
        {
            var step = new Step("the step");
            var context = new TestContext();
            IGrammar grammar = context.SetupMockGrammar(step.GrammarKey);

            grammar.Expect(x => x.Execute(step, context))
                .Throw(new NotImplementedException());

            context.RunStep(step);

            context.Counts.ShouldEqual(0, 0, 1, 0);

            context.ResultsFor(step).ExceptionText.ShouldContain("NotImplementedException");
        }
 public void should_have_logged_the_exception()
 {
     context.ResultsFor(step).HasErrors().ShouldBeTrue();
     context.ResultsFor(step).ExceptionText.ShouldContain("NotImplementedException");
 }
Пример #27
0
        public void the_results_should_completely_match()
        {
            var result = context.ResultsFor(step).GetResult <IList <SetRow> >("error");

            result.Count(x => x.Result == SetMatch.Match).ShouldEqual(1);
        }
Пример #28
0
        public void read_expected_value_from_step_that_is_boolean_missing_and_input_should_still_log_error()
        {
            var cell = new Cell("success", typeof (bool))
            {
                IsResult = false
            };
            var step = new Step();

            var context = new TestContext();
            cell.ReadArgument(context, step, o => Assert.Fail("should not have called back"));

            context.ResultsFor(step).IsInException("success").ShouldBeTrue();
        }
Пример #29
0
        public void read_expected_value_from_step_for_a_boolean_result_cell()
        {
            var cell = new Cell("success", typeof (bool))
            {
                IsResult = true
            };
            bool returnValue = false;
            var step = new Step();
            var context = new TestContext();
            cell.ReadArgument(context, step, o => returnValue = (bool) o);

            returnValue.ShouldBeTrue();
            context.ResultsFor(step).IsInException("success").ShouldBeFalse();
        }
Пример #30
0
        public void read_argument_with_a_format_exception()
        {
            Step step = new Step("a").With("age", "abc");
            var cell = new Cell("age", typeof (int));

            var context = new TestContext();
            cell.ReadArgument(context, step, x => Assert.Fail("should not have been called"));

            context.Counts.SyntaxErrors.ShouldEqual(1);

            context.ResultsFor(step).ExceptionText.ShouldContain("Format exception for 'age'");
        }
Пример #31
0
        public void record_actual_stores_the_data()
        {
            MethodInfo method = ReflectionHelper.GetMethod<CellTarget>(x => x.Add(0, 0));
            Step step = new Step("a").With("returnValue", "10");

            Cell cell = method.GetReturnCell();
            var data = new TestContext();

            cell.RecordActual(32.0, step, data);

            data.ResultsFor(step).ActualDisplay<double>("returnValue").ShouldEqual(32);
        }
        public static StepExecutionResult Execute(this IGrammar grammar, IStep step)
        {
            var context = new TestContext();

            grammar.Execute(step, context);

            return new StepExecutionResult{
                Counts = context.Counts,
                Results = context.ResultsFor(step)
            };
        }