public void get_cell()
        {
            Cell cell = _matchCity.As <IColumnMatch>().BuildCell(CellHandling.Basic(), new Fixture());

            cell.Key.ShouldBe("City");
            cell.Type.ShouldBe(typeof(string));
        }
예제 #2
0
        public Cell ApplyOverrides(Cell over)
        {
            var cell = new Cell(CellHandling.Basic(), Key, Type);

            cell.OptionListName = OptionListName;
            cell.Position       = Position;

            if (over == null)
            {
                cell.DefaultValue = DefaultValue;
                cell.result       = result;
                cell.editor       = editor;
                cell.header       = header;
                cell.options      = options?.Select(x => x.Copy()).ToArray();
                return(cell);
            }

            cell.DefaultValue = over.DefaultValue.IsNotEmpty() ? over.DefaultValue : DefaultValue;
            cell.result       = over.result.IsNotEmpty() ? over.result : result;
            cell.editor       = over.editor.IsNotEmpty() ? over.editor : editor;
            cell.header       = over.header.IsNotEmpty() ? over.header : header;
            cell.options      = over.options != null
                ? over.options?.Select(x => x.Copy()).ToArray()
                : options?.Select(x => x.Copy()).ToArray();

            return(cell);
        }
예제 #3
0
        public void invoke_with_out_parameters_happy_path()
        {
            var    age          = 0;
            double percentAwake = 0;

            var target = new Target();
            var method = ReflectionHelper.GetMethod <Target>(x => x.GoOutput(null, out age, out percentAwake));

            var values = new StepValues(method.Name);

            values.Store("name", "Grace Potter");
            values.Store("age", 5);
            values.Store("percentAwake", .5);

            var invocation = MethodInvocation.For(method, target);

            invocation.Compile(target, CellHandling.Basic());

            var results = invocation.Invoke(values).ToArray();

            results.ShouldHaveTheSameElementsAs(
                new CellResult("age", ResultStatus.success),
                new CellResult("percentAwake", ResultStatus.success)
                );
        }
예제 #4
0
        private void roundTrip <T>() where T : Fixture, new()
        {
            var fixture = new T();
            var model   = fixture.Compile(CellHandling.Basic());

            var markdown1 = FixtureWriter.Write(model);


            Console.WriteLine("Fixture " + typeof(T).Name);
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine(markdown1);
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine();
            Console.WriteLine();



            var model2 = FixtureReader.ReadFrom(markdown1);

            var markdown2 = FixtureWriter.Write(model2);

            var grammars1 = model.grammars.Where(x => x.key != "TODO").OrderBy(x => x.key).Select(x => x.key);
            var grammars2 = model2.grammars.OrderBy(x => x.key).Select(x => x.key);

            grammars2.ShouldHaveTheSameElementsAs(grammars1.ToArray());

            markdown2.ShouldBe(markdown1);
        }
        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}");
        }
        public void build_cells()
        {
            var cells = comparer.BuildCells(CellHandling.Basic(), new Fixture());

            cells.Select(x => x.Key).ShouldHaveTheSameElementsAs("City", "Address1", "DistanceFromOffice");
            cells.Select(x => x.Type).ShouldHaveTheSameElementsAs(typeof(string), typeof(string), typeof(double));
        }
        public void no_hidden_grammars_in_fixture_model()
        {
            var compiledFixture = FixtureLibrary.CreateCompiledFixture(CellHandling.Basic(), typeof(TopicFolderFixture));

            compiledFixture.Model.grammars.OrderBy(x => x.key).Select(x => x.key)
            .ShouldHaveTheSameElementsAs("AllTopicsShouldBe", "CheckTopic", "ForFile", "TheTopicsAre", "TODO", "WriteFile");
        }
예제 #8
0
        public override IReaderMode Read(int indention, string text)
        {
            if (!text.IsTableLine())
            {
                return(null);
            }

            var values = text.ToTableValues();

            if (_template == null)
            {
                _template = values;
                return(this);
            }

            var cell = new Cell(CellHandling.Basic(), null, typeof(string));

            values.Each((value, i) =>
            {
                applyValue(_template[i], cell, value);
            });

            _sentence.AddCell(cell);

            return(this);
        }
예제 #9
0
        public void embedded_fixture_exists_in_code_but_has_overrides()
        {
            writeFile("Master", @"
## MoveAround
### Move Around
embeds Actions
");

            writeFile("Actions", @"
## GoLeft
### Go left

## GoBack
### Go back
");

            theSystemFixtures.Models["Actions"] = new ActionsFixture().Compile(CellHandling.Basic());

            var grammar = theCombinedFixtures.Models["Master"]
                          .FindGrammar("MoveAround").ShouldBeOfType <EmbeddedSection>();

            grammar.fixture.FindGrammar("GoLeft").ShouldBeOfType <Sentence>()
            .format.ShouldBe("Go left");

            grammar.fixture.FindGrammar("GoBack").ShouldBeOfType <Sentence>()
            .format.ShouldBe("Go back");

            grammar.fixture.FindGrammar("GoRight").ShouldNotBeNull();
            grammar.fixture.FindGrammar("GoForward").ShouldNotBeNull();
        }
예제 #10
0
        public override IReaderMode Read(int indention, string text)
        {
            if (!text.IsTableLine())
            {
                return(null);
            }

            var values = text.ToTableValues();

            if (_table.cells == null)
            {
                _table.cells = values
                               .Skip(1)
                               .Select(x => new Cell(CellHandling.Basic(), x, typeof(string)))
                               .ToArray();

                return(this);
            }

            var target = values.First();
            var rest   = values.Skip(1).Take(_table.cells.Length).ToList();

            if (!rest.Any())
            {
                return(null);
            }

            rest.Each((value, i) =>
            {
                var cell = _table.cells[i];
                applyValue(target, cell, value);
            });

            return(this);
        }
 public void derived_format_has_the_return_value_too()
 {
     ValueCheckMethod
     .For(new Target(), x => x.Fullname3(null, null))
     .Compile(new Fixture(), CellHandling.Basic())
     .ShouldBeOfType <Sentence>()
     .format.ShouldBe("Fullname3({first}, {last}) should be {returnValue}");
 }
 public void format_from_attribute_if_it_exists()
 {
     ValueCheckMethod
     .For(new Target(), x => x.Fullname(null, null))
     .Compile(new Fixture(), CellHandling.Basic())
     .ShouldBeOfType <Sentence>()
     .format.ShouldBe("The fullname for {first} & {second} should be {expected}");
 }
예제 #13
0
        public Sentence_code_generation()
        {
            var model = new TestbedFixture().Compile(CellHandling.Basic());

            model.IsMissing = true;
            model.grammars.Each(x => x.IsMissing = true);
            theCode = model.missingCode;
        }
예제 #14
0
        public CellHandling Start()
        {
            var handling = CellHandling.Basic();

            configureCellHandling(handling);

            return(handling);
        }
예제 #15
0
        public void AddWithDefaultCellHandling <T>() where T : Fixture, new()
        {
            var fixture = new T();
            var model   = fixture.Compile(CellHandling.Basic());

            Fixtures[fixture.Key] = fixture;
            Models[fixture.Key]   = model;
        }
        public void can_correct_the_return_type_if_Task_of_T_to_T()
        {
            var parameter = ReflectionHelper.GetMethod <CellTarget>(x => x.GoPlacesAsync()).ReturnParameter;

            var cell = Cell.For(CellHandling.Basic(), parameter, new Fixture());

            cell.Type.ShouldBe(typeof(bool));
        }
예제 #17
0
        public void build_cells()
        {
            var comparison = new StringListComparison("expected", c => new String[0]);

            var cell = comparison.BuildCells(CellHandling.Basic(), new Fixture()).Single();

            cell.Key.ShouldBe("expected");
            cell.Type.ShouldBe(typeof(string));
        }
예제 #18
0
        public void smoke_test_of_fixture_model_serialization()
        {
            var fixture = new SentenceFixture();
            var model   = fixture.Compile(CellHandling.Basic());

            var json = JsonSerialization.ToCleanJson(model);

            Debug.WriteLine(json);
        }
        public static FactCheckMethod For <T>(T target, Expression <Func <T, bool> > expression)
        {
            var method  = ReflectionHelper.GetMethod(expression);
            var grammar = new FactCheckMethod(method, target);

            grammar.Compile(new Fixture(), CellHandling.Basic());

            return(grammar);
        }
예제 #20
0
        public void fixture_puts_a_fixture_key_on_all_grammars()
        {
            var fixture = new MathFixture();

            fixture.Compile(CellHandling.Basic());
            var allGrammars = fixture.AllGrammars().ToArray();

            allGrammars.Each(x => x.Key.ShouldNotBeNull());
        }
        public void uses_NULL_from_the_default_value()
        {
            ParameterInfo parameter = ReflectionHelper.GetMethod <CellTarget>(x => x.GoPlaces2(null))
                                      .GetParameters()[0];

            var cell = Cell.For(CellHandling.Basic(), parameter, new Fixture());

            cell.DefaultValue.ShouldBe("NULL");
        }
예제 #22
0
        public void can_customize_cell_display_and_usage()
        {
            var fixture  = new AddressBuilderFixture();
            var model    = fixture.Compile(CellHandling.Basic());
            var sentence = model.FindGrammar("City").As <Sentence>();

            sentence.cells[0].options.Length.ShouldBe(3);
            sentence.cells[0].editor.ShouldBe("select");
        }
예제 #23
0
        public void build_for_grammar_that_blows_up_in_a_method()
        {
            var compiled = FixtureLibrary.CreateCompiledFixture(CellHandling.Basic(), typeof(FixtureWithGrammarThatBlowsUp));
            var grammar  = compiled.Model.FindGrammar("Bad");

            grammar.key.ShouldBe("Bad");
            grammar.errors.Single()
            .error.ShouldContain("No!");
        }
        public void build_cell_with_modifications()
        {
            _matchCity.CellModifications.Header("The City");
            Cell cell = _matchCity.As <IColumnMatch>().BuildCell(CellHandling.Basic(), new Fixture());

            cell.Key.ShouldBe("City");
            cell.header.ShouldBe("The City");
            cell.Type.ShouldBe(typeof(string));
        }
예제 #25
0
        public void should_use_the_embedded_grammar_title_in_the_forward()
        {
            var fixture = new FakeEmbeddedFixture();
            var model   = fixture.Compile(CellHandling.Basic());

            var grammar = model.FindGrammar("BuildUp").ShouldBeOfType <EmbeddedSection>();

            grammar.title.ShouldBe("Gimme an Address");
        }
예제 #26
0
        public void can_compile_a_fixture_with_a_mix_of_fields_and_properties()
        {
            var fixture = new AddressBuilderFixture();

            fixture.Compile(CellHandling.Basic());

            fixture["City"].ShouldBeOfType <SetMemberGrammar>();
            fixture["County"].ShouldBeOfType <SetMemberGrammar>();
            fixture["Area.Name"].ShouldBeOfType <SetMemberGrammar>();
        }
        public void is_output_negative_case()
        {
            int           num       = 0;
            ParameterInfo parameter = ReflectionHelper.GetMethod <CellTarget>(x => x.GoPlaces(out num, 0))
                                      .GetParameters()[1];

            var cell = Cell.For(CellHandling.Basic(), parameter, new Fixture());

            cell.result.ShouldBeFalse();
        }
        public void use_default_value_on_parameter_if_one_exists()
        {
            int           num       = 0;
            ParameterInfo parameter = ReflectionHelper.GetMethod <CellTarget>(x => x.GoPlaces(out num, 0))
                                      .GetParameters()[1];

            var cell = Cell.For(CellHandling.Basic(), parameter, new Fixture());

            cell.DefaultValue.ShouldBe("5");
        }
예제 #29
0
        public void should_use_the_explicit_title_of_an_embedded_grammar()
        {
            var fixture = new FakeEmbeddedFixture();
            var model   = fixture.Compile(CellHandling.Basic());

            var grammar = model.FindGrammar("Embedded").ShouldBeOfType <EmbeddedSection>();

            grammar.title.ShouldBe("I wanna do some math");
            grammar.TitleOrFormat().ShouldBe("I wanna do some math");
        }
        public void build_out_the_grammar_model()
        {
            var grammar = new ActionGrammar("do something", c => { });

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

            model.errors.Any().ShouldBe(false);
            model.format.ShouldBe("do something");
            model.cells.Any().ShouldBe(false);
        }