Exemplo n.º 1
0
        public void Changed(string file)
        {
            try
            {
                _lock.Read(() =>
                {
                    var fixture = FixtureReader.ReadFromFile(file);

                    ConsoleWriter.Write($"{file} changed");

                    _fixtures.Models[fixture.key] = fixture;

                    // send to client

                    return(true);
                });
            }
            catch (IOException)
            {
                ConsoleWriter.Write(ConsoleColor.Yellow, $"Unable to reload {file}, file may be locked by your editor");
            }
            catch (Exception e)
            {
                Logger.Error("Failed to handle a changed file: " + file, e);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void reads_sentence_cells_with_quoted_options()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title
|cell|default|options|
|first|default|hello, ""goodbye, friend"", ciao|");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();

            var sentence = result.grammars[0].As <Sentence>();

            sentence.cells.ShouldNotBeNull();
            sentence.cells.Length.ShouldBe(1);

            var cell = sentence.cells[0];

            cell.Key.ShouldBe("first");
            cell.options.ShouldNotBeNull();
            cell.options.Length.ShouldBe(3);
            cell.options[0].value.ShouldBe("hello");
            cell.options[1].value.ShouldBe("goodbye, friend");
            cell.options[2].value.ShouldBe("ciao");
        }
Exemplo n.º 4
0
        public void reads_table_multiple_columns()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title
|table|column 1|column 2|
|default|one|two|
|editor|text||");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Table>();

            var table = result.grammars[0].As <Table>();

            table.cells.ShouldNotBeNull();
            table.cells.Length.ShouldBe(2);

            var cell = table.cells[0];

            cell.Key.ShouldBe("column 1");
            cell.DefaultValue.ShouldBe("one");
            cell.editor.ShouldBe("text");

            cell = table.cells[1];
            cell.Key.ShouldBe("column 2");
            cell.DefaultValue.ShouldBe("two");
        }
Exemplo n.º 5
0
        public void reads_sentence_cells_with_options()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
|sentence|first               |
|default |somthing            |
|options |hello, goodbye, ciao|");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();

            var sentence = result.grammars[0].As <Sentence>();

            sentence.cells.ShouldNotBeNull();
            sentence.cells.Length.ShouldBe(1);

            var cell = sentence.cells[0];

            cell.Key.ShouldBe("first");
            cell.options.ShouldNotBeNull();
            cell.options.Length.ShouldBe(3);
            cell.options[0].value.ShouldBe("hello");
            cell.options[1].value.ShouldBe("goodbye");
            cell.options[2].value.ShouldBe("ciao");
        }
Exemplo n.º 6
0
        public void can_derive_a_title_from_the_key()
        {
            var result = FixtureReader.ReadFrom(@"
## SomeKindOfKey
");

            result.grammars.Single().ShouldBeOfType <Sentence>()
            .format.ShouldBe("Some Kind Of Key");
        }
Exemplo n.º 7
0
        public void reads_sentence()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();
            result.grammars[0].As <Sentence>().format.ShouldBe("a title");
            result.grammars[0].As <Sentence>().key.ShouldBe("a key");
        }
Exemplo n.º 8
0
        public void can_fix_up_a_key_with_spaces()
        {
            var result   = FixtureReader.ReadFrom(@"
## Some Kind Of Key
");
            var sentence = result.grammars.Single().ShouldBeOfType <Sentence>();

            sentence
            .format.ShouldBe("Some Kind Of Key");

            sentence.key.ShouldBe("SomeKindOfKey");
        }
Exemplo n.º 9
0
        public void can_create_a_new_fixture_file_if_it_does_not_exist()
        {
            theController.CreateFixture("One");

            var file = theFixtureDirectory.AppendPath("One.md");

            File.Exists(file).ShouldBeTrue();

            var fixture = FixtureReader.ReadFromFile(file);

            fixture.key.ShouldBe("One");
            fixture.title.ShouldBe("One");

            theClient.ReceivedWithAnyArgs().SendMessageToClient(new FixturesReloaded());
        }
Exemplo n.º 10
0
        public void does_not_overwrite_an_existing_fixture()
        {
            var file     = theFixtureDirectory.AppendPath("One.md");
            var original = new FixtureModel("One")
            {
                title = "a fancier title"
            };

            FixtureWriter.Write(original, file);

            theController.CreateFixture("One");

            FixtureReader.ReadFromFile(file)
            .title.ShouldBe(original.title);

            theClient.ReceivedCalls().Any().ShouldBeFalse();
        }
Exemplo n.º 11
0
        public void reads_table()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title
|table|col1|");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Table>();

            var table = result.grammars[0].As <Table>();

            table.cells.ShouldNotBeNull();
            table.cells.Length.ShouldBe(1);

            var cell = table.cells[0];

            cell.Key.ShouldBe("col1");
        }
Exemplo n.º 12
0
        public void reads_sentence_cells()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
|cell|default|
|first|default|");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();

            var sentence = result.grammars[0].As <Sentence>();

            sentence.cells.ShouldNotBeNull();
            sentence.cells.Length.ShouldBe(1);

            var cell = sentence.cells[0];

            cell.Key.ShouldBe("first");
            cell.DefaultValue.ShouldBe("default");
        }
Exemplo n.º 13
0
        protected override void ReadBody(XmlReader reader)
        {
            // This is duplicated from a Sequence, but that's to keep it independent.
            // Just because that changes doesn't mean this should.

            // Module data
            reader.ReadStartElement("ModuleData");
            ModuleDataSet.Deserialize(reader.ReadOuterXml());
            reader.ReadEndElement();             // ModuleData

            // Fixtures
            if (reader.ElementsExistWithin("Fixtures"))              // Container element for child entity
            {
                FixtureReader fixtureReader = new FixtureReader();
                while (fixtureReader.Read(reader))
                {
                    InsertFixture(fixtureReader.Fixture);
                }
                reader.ReadEndElement();                 // Fixtures
            }
        }
Exemplo n.º 14
0
        public void reads_sentence_cells_with_result()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title
|cell|result|
|first|result|");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();

            var sentence = result.grammars[0].As <Sentence>();

            sentence.cells.ShouldNotBeNull();
            sentence.cells.Length.ShouldBe(1);

            var cell = sentence.cells[0];

            cell.Key.ShouldBe("first");
            cell.result.ShouldBe("result");
        }
Exemplo n.º 15
0
        public void reads_sentence_cells_with_editor()
        {
            var result = FixtureReader.ReadFrom(@"
## a key
### a title
|sentence|first   |
|editor  |bigtext |
");

            result.grammars.ShouldNotBeNull();
            result.grammars.Length.ShouldBe(1);
            result.grammars[0].ShouldBeOfType <Sentence>();

            var sentence = result.grammars[0].As <Sentence>();

            sentence.cells.ShouldNotBeNull();
            sentence.cells.Length.ShouldBe(1);

            var cell = sentence.cells[0];

            cell.Key.ShouldBe("first");
            cell.editor.ShouldBe("bigtext");
        }
Exemplo n.º 16
0
        public void reads_title()
        {
            var result = FixtureReader.ReadFrom(@"# a title");

            result.title.ShouldBe("a title");
        }