Beispiel #1
0
        public void get_template_for_the_method_if_no_attribute_is_found()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.DoSomethingWith(null, 34), dooer);

            action.Template.ShouldEqual("DoSomethingWith {name}, {age}");
        }
        public void select_format_by_names()
        {
            var grammar = ActionMethodGrammar.Create(x => x.FancyGo(null, 0, 0), theTarget);
            var model   = grammar.Compile(new Fixture(), CellHandling.Basic()).ShouldBeOfType <Sentence>();

            model.format.ShouldBe("fancy go {name}, {age}, {percentAwake}");
        }
Beispiel #3
0
        public void executing_with_an_exception_in_the_target_method_increments_the_exception_count()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.MethodThatThrowsException(), dooer);
            var step = new Step("a");

            action.Execute(step, _testContext);

            theCounts.Exceptions.ShouldEqual(1);
        }
Beispiel #4
0
        public void execute_the_void_action_that_would_catch_an_exception()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.MethodThatThrowsException(), dooer);

            var step    = new Step();
            var results = action.Execute(step);

            results.Results.ExceptionText.ShouldContain("NotImplementedException");
            results.Counts.ShouldEqual(0, 0, 1, 0);
        }
Beispiel #5
0
        public void creates_grammar_structure()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.DoSomethingWith2(null, 34), dooer);
            MethodInfo          method = ReflectionHelper.GetMethod <Dooer>(x => x.DoSomethingWith2(null, 34));


            var sentence = action.ToStructure(new FixtureLibrary()).ShouldBeOfType <Sentence>();

            sentence.ShouldEqual(Sentence.For(method.GetTemplate(), Cell.For <string>("name"), Cell.For <int>("age")));
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void ignores_Testcontext_and_non_simple_types_when_building_a_grammar_structure()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(
                x => x.DoSomethingUsingContextAndAddress(null, null, null), dooer);
            MethodInfo method =
                ReflectionHelper.GetMethod <Dooer>(x => x.DoSomethingUsingContextAndAddress(null, null, null));

            var      sentence = action.ToStructure(new FixtureLibrary()).ShouldBeOfType <Sentence>();
            Sentence expected = Sentence.For(method.GetTemplate(), Cell.For <string>("name"));

            sentence.ShouldEqual(expected);
        }
Beispiel #8
0
        public void execute_the_void_action_with_all_the_arguments()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.DoSomethingWith(null, 34), dooer);

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

            action.Execute(step, _testContext);

            dooer.Age.ShouldEqual(32);
            dooer.Name.ShouldEqual("Josh");
        }
Beispiel #9
0
        public void execute_the_void_action_with_a_parse_error()
        {
            var dooer = new Dooer();
            ActionMethodGrammar action = ActionMethodGrammar.Create(x => x.DoSomethingWith(null, 34), dooer);

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

            action.Execute(step, _testContext);
            var results = _testContext.ResultsFor(step);

            results.ExceptionText.Contains("System.FormatException : Input string was not in a correct format");
            results.ExceptionText.Contains("\"age\" is malformed or invalid");
        }
        public void execute()
        {
            var grammar = ActionMethodGrammar.Create(x => x.Go(null, 0, 0), theTarget);

            grammar.Compile(new Fixture(), CellHandling.Basic()).ShouldBeOfType <Sentence>();

            var values = new StepValues("id");

            values.Store("name", "Jeremy");
            values.Store("age", 41);
            values.Store("percentAwake", 50.1);

            ShouldBeTestExtensions.ShouldBe(grammar.Execute(values, SpecContext.Basic()).Any(), false);

            theTarget.Name.ShouldBe("Jeremy");
            theTarget.Age.ShouldBe(41);
            theTarget.PercentAwake.ShouldBe(50.1);
        }