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); } }
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 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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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()); }
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(); }
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"); }
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"); }
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 } }
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"); }
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"); }
public void reads_title() { var result = FixtureReader.ReadFrom(@"# a title"); result.title.ShouldBe("a title"); }