Example #1
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return new Sentence
     {
         format = _label
     };
 }
        public Cell BuildCell(CellHandling handling, Fixture fixture)
        {
            var cell = new Cell(handling, Name, _columnType);
            CellModifications.Apply(cell);

            return cell;
        }
        public static CompiledFixture CreateCompiledFixture(CellHandling cellHandling, Type type)
        {
            try
            {
                var fixture = Activator.CreateInstance(type) as Fixture;
                FixtureCache[type] = fixture;
                return new CompiledFixture
                {
                    Fixture = fixture,
                    Model = fixture.Compile(cellHandling)
                };
            }
            catch (Exception e)
            {
                var fixture = new InvalidFixture(type, e);
                var model = fixture.Compile(cellHandling);
                model.implementation = type.FullName;

                return new CompiledFixture
                {
                    Fixture = fixture,
                    Model = model
                };
            }
        }
Example #4
0
            public Cell BuildCell(CellHandling handling, Fixture fixture)
            {
                Cell = new Cell(handling, _key, typeof(T));
                Customize.Apply(Cell);

                return(Cell);
            }
        protected override IEnumerable <Cell> buildCells(CellHandling cellHandling, Fixture fixture)
        {
            _cell = new Cell(cellHandling, _accessor.Name, _accessor.PropertyType);
            CellModifications.Apply(_cell);

            return(new[] { _cell });
        }
Example #6
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);
        }
Example #7
0
        protected override IEnumerable <Cell> buildCells(CellHandling cellHandling, Fixture fixture)
        {
            _cellHandling = cellHandling;
            _cell         = new Cell(cellHandling, _key, typeof(T));

            return(new [] { _cell });
        }
Example #8
0
        protected override IEnumerable <Cell> buildCells(CellHandling cellHandling, Fixture fixture)
        {
            _cell = Cell.For(cellHandling, _accessor, fixture);
            CellModifications.Apply(_cell);

            return(new[] { _cell });
        }
        public override FixtureModel Compile(CellHandling conversions)
        {
            var model = new FixtureModel(Key);
            model.AddError(_error);

            return model;
        }
Example #10
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();
        }
        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");
        }
Example #12
0
        public Cell BuildCell(CellHandling handling, Fixture fixture)
        {
            var cell = new Cell(handling, _accessor.Name, _accessor.PropertyType);
            CellModifications.Apply(cell);

            return cell;
        }
Example #13
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return(new Sentence
     {
         format = _label
     });
 }
        public static FixtureLibrary CreateForAppDomain(CellHandling cellHandling)
        {
            var currentDomain = AppDomain.CurrentDomain;
            var assemPath     = currentDomain.BaseDirectory;
            var binPath       = currentDomain.SetupInformation.PrivateBinPath;

            if (binPath.IsNotEmpty())
            {
                assemPath = assemPath.AppendPath(binPath);
            }



            var fixtures = AssembliesFromPath(assemPath, referencesStoryteller)
                           .SelectMany(FixtureTypesFor)
                           .Select(
                type => CreateCompiledFixture(cellHandling, type));


            var library = new FixtureLibrary();

            fixtures.Each(x =>
            {
                library.Fixtures[x.Fixture.Key] = x.Fixture;
                library.Models[x.Fixture.Key]   = x.Model;
            });

            return(library);
        }
        public static CompiledFixture CreateCompiledFixture(CellHandling cellHandling, Type type)
        {
            try
            {
                var fixture = Activator.CreateInstance(type) as Fixture;
                FixtureCache[type] = fixture;
                return(new CompiledFixture
                {
                    Fixture = fixture,
                    Model = fixture.Compile(cellHandling)
                });
            }
            catch (Exception e)
            {
                var fixture = new InvalidFixture(type, e);
                var model   = fixture.Compile(cellHandling);
                model.implementation = type.FullName;

                return(new CompiledFixture
                {
                    Fixture = fixture,
                    Model = model
                });
            }
        }
Example #16
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return(new Sentence
     {
         format = _method.DeriveFormat()
     });
 }
        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 Cell CompileCell(CellHandling cellHandling, Fixture fixture)
        {
            _cell        = Cell.For(cellHandling, _property, fixture);
            _cell.result = true;

            return(_cell);
        }
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     // TODO -- write a UT to pin this behavior down
     // This is important to get the right lists, *use* the lists
     // from the inner fixture here.
     return _inner.Compile(_innerFixture, cells);
 }
Example #20
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)
                );
        }
Example #21
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);
        }
Example #22
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);
        }
Example #23
0
        public static Cell For(CellHandling cells, ParameterInfo parameter, Fixture fixture)
        {
            var isOutput = false;
            var type     = parameter.ParameterType;

            if (parameter.IsOut)
            {
                type     = type.GetElementType();
                isOutput = true;
            }

            if (type.Closes(typeof(Task <>)))
            {
                type = type.GetGenericArguments().Single();
            }

            var cell = new Cell(cells, parameter.Name, type)
            {
                result = isOutput, Position = parameter.Position
            };

            parameter.ForAttribute <ModifyCellAttribute>(x => x.Modify(cell));
            type.ForAttribute <ModifyCellAttribute>(x => x.Modify(cell));

            if (parameter.HasDefaultValue)
            {
                cell.DefaultValue = parameter.DefaultValue?.ToString() ?? "NULL";
            }


            cell.readLists(cells, fixture);

            return(cell);
        }
Example #24
0
        protected override void configureCellHandling(CellHandling handling)
        {
            var directory = AppContext.BaseDirectory;

            while (Path.GetFileName(directory) != "ReduxSamples")
            {
                directory = directory.ParentDirectory();
            }

            var jsFile = directory.AppendPath("reduxharness.js");

            Console.WriteLine("Copying the reduxharness.js file to " + directory);
            var source = directory.AppendPath("..", "StorytellerRunner", "reduxharness.js");


            File.Copy(source, jsFile, true);

            var harnessPath = directory.AppendPath("harness.htm");

            if (!File.Exists(harnessPath))
            {
                var doc = new HtmlDocument();

                var href = "file://" + jsFile;

                doc.Head.Add("script").Attr("src", href);

                Console.WriteLine("Writing the harness file to " + harnessPath);
                doc.WriteToFile(harnessPath);
            }

            var url = "file://" + harnessPath;

            handling.Extensions.Add(new ReduxSagaExtension(url));
        }
Example #25
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);
        }
        public Cell CompileCell(CellHandling cellHandling, Fixture fixture)
        {
            _cell = Cell.For(cellHandling, _property, fixture);
            _cell.output = true;

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

            cell.Key.ShouldBe("City");
            cell.Type.ShouldBe(typeof(string));
        }
        protected override IEnumerable <Cell> buildCells(CellHandling cellHandling, Fixture fixture)
        {
            _cell = new Cell(cellHandling, _key, typeof(TInput));
            _cell.DefaultValue = DefaultValue;

            return(new[] { _cell });
        }
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     // TODO -- write a UT to pin this behavior down
     // This is important to get the right lists, *use* the lists
     // from the inner fixture here.
     return(_inner.Compile(_innerFixture, cells));
 }
        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}");
        }
Example #31
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;
        }
Example #32
0
        public Cell BuildCell(CellHandling handling, Fixture fixture)
        {
            var cell = new Cell(handling, _accessor.Name, _accessor.PropertyType);

            CellModifications.Apply(cell);

            return(cell);
        }
        public override FixtureModel Compile(CellHandling cellHandling)
        {
            var model = new FixtureModel(Key);

            model.AddError(_error);

            return(model);
        }
 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}");
 }
 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 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));
        }
        protected override IEnumerable <Cell> buildCells(CellHandling cellHandling, Fixture fixture)
        {
            _cell = new Cell(cellHandling, _key, typeof(TInput));

            CellModifications.Apply(_cell);

            return(new[] { _cell });
        }
Example #38
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return new Sentence
     {
         fact = true,
         format = _label,
         cells = new Cell[0]
     };
 }
Example #39
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     // Let the UI handle the format errors
     _cells = buildCells(cells, fixture).ToArray();
     return new Sentence
     {
         cells = _cells,
         format = format()
     };
 }
        public GrammarModel Compile(Fixture fixture, CellHandling cells)
        {
            var inner = _inner.Compile(fixture, cells);
            var innerCells = inner.As<IModelWithCells>().cells;

            return new Sentence
            {
                cells = filterCells(innerCells).ToArray(),
                format = _template,
            };
        }
        public GrammarModel Compile(Fixture fixture, CellHandling cells)
        {
            _cells = _comparison.BuildCells(cells, fixture);

            return new SetVerification
            {
                title = _title,
                cells = _cells,
                collection = _leafName,
                ordered = _ordered
            };
        }
Example #42
0
        public void use_a_runtime_converter_against_NULL()
        {
            var conversions = new Conversions();
            conversions.RegisterRuntimeConversion<ColorConverter>();
            var cellHandling = new CellHandling(new EquivalenceChecker(), conversions);

            var cell = new Cell(cellHandling, "color", typeof (Color));

            var values = new StepValues("foo");
            cell.ConvertValues(new Step("foo").With("color", "NULL"), values);

            values.Get("color").ShouldBeNull();
        }
        public void Compile(Fixture fixture, CellHandling cellHandling)
        {
            _cells = _method.GetParameters().Select(x => Cell.For(cellHandling, x, fixture)).ToArray();
            _outputs = _cells.Where(x => x.result).ToArray();

            if (_method.HasReturn())
            {
                ReturnCell = Cell.For(cellHandling, _method.ReturnParameter, fixture);
                ReturnCell.result = true;
                if (ReturnCell.Key.IsEmpty())
                {
                    ReturnCell.Key = Format.ParseTemplateKeys().LastOrDefault() ?? "returnValue";
                }
            }
        }
Example #44
0
        public GrammarModel Compile(Fixture fixture, CellHandling cells)
        {
            if (_inner is MissingGrammar)
            {
                return _inner.Compile(fixture, cells);
            }

            var innerModel = _inner.Compile(fixture, cells).As<IModelWithCells>();

            return new Table
            {
                cells = innerModel.cells.ToArray(),
                collection = _leafName,
                title = Title
            };
        }
Example #45
0
        public void use_a_runtime_converter_with_a_value()
        {
            var conversions = new Conversions();
            conversions.RegisterRuntimeConversion<ColorConverter>();

            var cellHandling = new CellHandling(new EquivalenceChecker(), conversions);

            var cell = new Cell(cellHandling, "color", typeof (Color));

            var values = new StepValues("foo");
            cell.ConvertValues(new Step("foo").With("color", "Red"), values);

            var delayed = values.DelayedConversions.Single();

            delayed.Key.ShouldBe("color");
            delayed.Raw.ShouldBe("Red");
            delayed.Converter.ShouldBeOfType<ColorConverter>();
        }
 public Cell[] BuildCells(CellHandling handling, Fixture fixture)
 {
     return new[]{new Cell(handling, _key, typeof(string)) };
 }
        public static FixtureLibrary CreateForAppDomain(CellHandling cellHandling)
        {
            var currentDomain = AppDomain.CurrentDomain;
            var assemPath = currentDomain.BaseDirectory;
            var binPath = currentDomain.SetupInformation.PrivateBinPath;
            if (binPath.IsNotEmpty())
            {
                assemPath = assemPath.AppendPath(binPath);
            }

            var fixtures = AssembliesFromPath(assemPath, referencesStoryteller)
                .SelectMany(FixtureTypesFor)
                .Select(
                    type => CreateCompiledFixture(cellHandling, type));

            var library = new FixtureLibrary();

            fixtures.Each(x =>
            {
                library.Fixtures[x.Fixture.Key] = x.Fixture;
                library.Models[x.Fixture.Key] = x.Model;
            });

            return library;
        }
Example #48
0
 protected virtual IEnumerable<Cell> buildCells(CellHandling cellHandling, Fixture fixture)
 {
     return Enumerable.Empty<Cell>();
 }
Example #49
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return Silent.Flyweight;
 }
 public Cell CompileCell(CellHandling cellHandling, Fixture fixture)
 {
     return Cell.For(cellHandling, _property, fixture);
 }
Example #51
0
 GrammarModel IGrammar.Compile(Fixture fixture, CellHandling cells)
 {
     return this;
 }
 protected override IEnumerable<Cell> buildCells(CellHandling cellHandling, Fixture fixture)
 {
     return _properties.Select(x => x.CompileCell(cellHandling, fixture));
 }
Example #53
0
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return new StubGrammarModel();
 }
 public GrammarModel Compile(Fixture fixture, CellHandling cells)
 {
     return _inner.Compile(fixture, cells);
 }