public void serialize_a_spec_with_extended_charactors() { var spec = MarkdownReader.ReadFromText(@" # Use an array argument -> id = e0e4da7a-4d0a-41c6-940b-c9ed654194d2 -> lifecycle = Acceptance -> max-retries = 0 -> last-updated = 2017-01-07T15:55:20.5381011Z -> tags = [Array] |> TheNameArrayShouldBe ``` names é, à, ç ``` |> FibonacciSeries ``` numbers 1,1,2,3 ``` ~~~ "); var section = spec.Children[0].As <Section>(); section.Children[0].As <Step>().Values["names"].ShouldBe("é, à, ç"); var json = JsonSerialization.ToCleanJson(spec); json.ShouldContain("é, à, ç"); }
public void read_file() { var spec = MarkdownReader.ReadFromText(@" # Use an array argument -> id = e0e4da7a-4d0a-41c6-940b-c9ed654194d2 -> lifecycle = Acceptance -> max-retries = 0 -> last-updated = 2017-01-07T15:55:20.5381011Z -> tags = [Array] |> TheNameArrayShouldBe ``` names Hank, Tom, Todd ``` |> FibonacciSeries ``` numbers 1,1,2,3 ``` ~~~ "); var section = spec.Children[0].As <Section>(); section.Children[0].As <Step>().StagedValues.ShouldBeNull(); section.Children[0].As <Step>().Values["names"].ShouldBe("Hank, Tom, Todd"); section.Children[1].As <Step>().Values["numbers"].ShouldBe("1,1,2,3"); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { if (file.Type != DocumentType.Article) { throw new NotSupportedException(); } var content = MarkdownReader.ReadMarkdownAsConceptual(file.File); foreach (var item in metadata) { if (!content.ContainsKey(item.Key)) { content[item.Key] = item.Value; } } content[Constants.PropertyName.SystemKeys] = SystemKeys; var localPathFromRoot = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File)); return(new FileModel( file, content, serializer: new BinaryFormatter()) { LocalPathFromRoot = localPathFromRoot, }); }
public void should_read_in_the_table_data_to_the_default_section() { theFixtures.AddWithDefaultCellHandling <NumberTableFixture>(); var spec = MarkdownReader.ReadFromText(@" # Some Specification [NumberTable] |> Add |x|y|sum| |1|2|3| |2|3|5| |6|4|10| "); var step = spec.Children.Single().ShouldBeOfType <Section>() .Children.Single().ShouldBeOfType <Step>(); step.Collections.Count.ShouldBe(1); step.Collections.Single().Key.ShouldBe(Table.DefaultCollectionName); step.Collections[Table.DefaultCollectionName].Children.Count.ShouldBe(3); var row1 = step.Collections[Table.DefaultCollectionName].Children.First().ShouldBeOfType <Step>(); row1.Values["x"].ShouldBe("1"); row1.Values["y"].ShouldBe("2"); row1.Values["sum"].ShouldBe("3"); }
public void setting_the_lifecycle_when_the_new_lifecycle_is_different() { var spec = ClassUnderTest.Hierarchy.Specifications["general1"]; var newLifecycle = spec.Lifecycle == Lifecycle.Acceptance ? Lifecycle.Regression : Lifecycle.Acceptance; var completed1 = new SpecExecutionCompleted { Id = spec.id }; var completed2 = new SpecExecutionCompleted { Id = spec.id }; var completed3 = new SpecExecutionCompleted { Id = spec.id }; ClassUnderTest.Results.Store(completed1); ClassUnderTest.Results.Store(completed2); ClassUnderTest.Results.Store(completed3); ClassUnderTest.SetLifecycle("general1", newLifecycle); // Did save MarkdownReader.ReadFromFile(spec.Filename).Lifecycle .ShouldBe(newLifecycle); var message = MockFor <IClientConnector>().ReceivedCalls().First().GetArguments().First().As <SpecData>(); message.data.ShouldBeSameAs(spec); message.data.id.ShouldBe(spec.id); message.results.Any(x => ReferenceEquals(x, completed1)).ShouldBeTrue(); message.results.Any(x => ReferenceEquals(x, completed2)).ShouldBeTrue(); message.results.Any(x => ReferenceEquals(x, completed3)).ShouldBeTrue(); }
public override FileModel Load(FileAndType file, ImmutableDictionary <string, object> metadata) { if (file.Type != DocumentType.Article) { throw new NotSupportedException(); } var content = MarkdownReader.ReadMarkdownAsConceptual(file.BaseDir, file.File); foreach (var item in metadata) { if (!content.ContainsKey(item.Key)) { content[item.Key] = item.Value; } } var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath); return(new FileModel( file, content, serializer: Environment.Is64BitProcess?null: new BinaryFormatter()) { LocalPathFromRepoRoot = (content["source"] as SourceDetail)?.Remote?.RelativePath, LocalPathFromRoot = displayLocalPath }); }
public void change_a_file() { var file = ClassUnderTest.Hierarchy.Specifications["general1"].Filename; var old = MarkdownReader.ReadFromFile(file); old.Lifecycle = Lifecycle.Regression; MarkdownWriter.WriteToFile(old, file); ClassUnderTest.Changed(file); var newNode = ClassUnderTest.Hierarchy.Specifications["general1"]; newNode.ShouldNotBeTheSameAs(old); newNode.Lifecycle.ShouldBe(Lifecycle.Regression); ClassUnderTest.Hierarchy.Suites["General"] .Specifications.ShouldContain(newNode); var sent = MockFor <IClientConnector>().ReceivedCalls().First().GetArguments().First().As <SpecData>(); sent.ShouldNotBeNull(); sent.data.ShouldBe(newNode); sent.id.ShouldBe("general1"); }
public void add_spec_with_illegal_chars() { var c = Path.GetInvalidFileNameChars().First(); var added = ClassUnderTest.AddSpec("Sentences", $"The Third Sentence{c}{c}"); var expectedPath = thePath.AppendPath("Sentences", "The_Third_Sentence.md"); added.data.name.ShouldBe($"The Third Sentence{c}{c}"); added.data.Filename.ShouldBe(expectedPath); added.data.Lifecycle.ShouldBe(Lifecycle.Acceptance); added.data.Filename.ShouldBe(expectedPath); ClassUnderTest.Hierarchy.Specifications[added.data.id].ShouldBeTheSameAs(added.data); var specification = MarkdownReader.ReadFromFile(expectedPath); specification.name.ShouldBe($"The Third Sentence{c}{c}"); // Adds the spec to the node var suite = ClassUnderTest.Hierarchy.Suites["Sentences"]; suite.Specifications.ShouldContain(added.data); }
private SpecResults runSpec(string id) { var node = _hierarchy.ToHierarchy().Specifications[id]; var specification = MarkdownReader.ReadFromFile(node.Filename); return(_runner.Execute(specification)); }
/// <summary> /// </summary> /// <param name="markdown"> /// </param> /// <param name="xml"> /// </param> private void WriteBold( MarkdownReader markdown, XmlWriter xml) { xml.WriteStartElement("emphasis"); xml.WriteAttributeString("role", "strong"); }
/// <summary> /// Runs this process and performs the appropriate actions. /// </summary> public override void Run() { // Verify that the input file exists since if we can't, it is // meaningless to continue. if (this.Input == null) { throw new Exception("Input was not properly set to a value."); } // Open up a handle to the Markdown file that we are processing. This uses an // event-based reader to allow us to write the output file easily. var options = new MarkdownOptions() { AllowMetadata = true, }; using (var markdownReader = new MarkdownReader(this.Input, options)) { // We also need an XML writer for the resulting file. using (XmlWriter xmlWriter = this.CreateXmlWriter()) { // Convert the Markdown into XML. this.ConvertMarkdown( markdownReader, xmlWriter); } } }
public void clone_a_specification() { // This *should* be broken up into its own fixture, but I'm feeling lazy // today // sentence2 is marked as regression, but the newly cloned one // should be acceptance var added = ClassUnderTest.CloneSpecification("sentence2", "New Sentence"); var expectedPath = thePath.AppendPath("Sentences", "New_Sentence.md"); added.hierarchy.ShouldBeTheSameAs(ClassUnderTest.Hierarchy.Top); added.data.Lifecycle.ShouldBe(Lifecycle.Acceptance); added.data.id.ShouldNotBe("sentence2"); added.data.name.ShouldBe("New Sentence"); added.data.Filename.ShouldBe(expectedPath); ClassUnderTest.Hierarchy.Specifications[added.data.id].ShouldBeTheSameAs(added.data); var specification = MarkdownReader.ReadFromFile(expectedPath); specification.name.ShouldBe("New Sentence"); specification.Children.Any().ShouldBe(true); // Adds the spec to the node var suite = ClassUnderTest.Hierarchy.Suites["Sentences"]; suite.Specifications.ShouldContain(added.data); }
public void can_read_max_retries() { var path = TestingContext.FindParallelDirectory("Storyteller.Samples").AppendPath("Specs", "General", "Check properties.md"); var spec = MarkdownReader.ReadFromFile(path); spec.MaxRetries.ShouldBe(3); }
public void ThrowExceptionGivenNonExistFilePath() { var logger = new Mock <ILogger <MarkdownReader> >(); var target = new MarkdownReader(logger.Object); var ex = Assert.Throws <FileNotFoundException>(() => { target.ReadToEnd("xxxxxxxx/xxxxxx/xxxx"); }); }
public void ThrowArgumentNullExceptionGivenEmtpyFilePath() { var logger = new Mock <ILogger <MarkdownReader> >(); var target = new MarkdownReader(logger.Object); var ex = Assert.Throws <ArgumentNullException>(() => { target.ReadToEnd(string.Empty); }); }
public SpecExecutionRequestTester() { var path = TestingContext.FindParallelDirectory("Storyteller.Samples") .AppendPath("Specs", "General", "Check properties.md"); theSpec = MarkdownReader.ReadFromFile(path); listener = new RuntimeErrorListener(); }
/// <summary> /// </summary> /// <param name="markdown"> /// </param> /// <param name="xml"> /// </param> private void WriteBreak( MarkdownReader markdown, XmlWriter xml) { xml.WriteStartElement("bridgehead"); xml.WriteAttributeString("renderas", "other"); xml.WriteAttributeString("otherrenderas", "break"); xml.WriteEndElement(); }
private static bool TryDocument(string path, out RuleDocument document) { var reader = new MarkdownReader(yamlHeaderOnly: false); var stream = reader.Read(File.ReadAllText(path), path); var lexer = new RuleLexer(); document = lexer.Process(stream); return(document != null); }
public void can_read_max_retries() { var path = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory() .AppendPath("Storyteller.Samples", "Specs", "General", "Check properties.md"); var spec = MarkdownReader.ReadFromFile(path); spec.MaxRetries.ShouldBe(3); }
//[Fact] public void write_the_table5_spec() { var hierarchy = TestingContext.Hierarchy; var spec = hierarchy.ToHierarchy().Specifications["table5"]; var specification = MarkdownReader.ReadFromFile(spec.Filename); var json = JsonSerialization.ToIndentedJson(specification); Debug.WriteLine(json); }
private void roundTripCheck(Specification spec) { spec.ApplyRenumbering(); spec.path = null; // doesn't matter for the markdown persistence var markdown = MarkdownWriter.WriteToText(spec); var readCopy = MarkdownReader.ReadFromText(markdown); compare(spec, readCopy); }
private Counts running(string name) { var node = _allSpecs.FirstOrDefault(x => x.name == name); var spec = MarkdownReader.ReadFromFile(node.Filename); executeSpec(spec); theContext.Results.Each(x => Debug.WriteLine(x)); return(theContext.Counts); }
public void save_specification_updates_expiration_period() { var node = ClassUnderTest.Hierarchy.Specifications["embeds"]; var specification = MarkdownReader.ReadFromFile(node.Filename); specification.ExpirationPeriod = 5; ClassUnderTest.SaveSpecification(node.id, specification); var written = MarkdownReader.ReadFromFile(node.Filename); written.ExpirationPeriod.ShouldBe(5); }
public string toHTML() { string arguments = _arguments .Select(a => a.First + "=" + HttpUtility.UrlEncode(a.Second)) .Aggregate("", (a, b) => a + "&" + b); var markdown = "[](module:{0}{1}{2})".format( _moduleName, arguments != "" ? "?" : "", arguments); return(MarkdownReader.fromString(markdown)); }
private static void BuildItem(IHostService host, FileModel model) { var file = model.FileAndType; var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(host, model.FileAndType).ToList(); model.Content = overwrites; model.LocalPathFromRepoRoot = overwrites[0].Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath(); model.Uids = (from item in overwrites select new UidDefinition( item.Uid, model.LocalPathFromRepoRoot, item.Documentation.StartLine + 1)).ToImmutableArray(); }
private static void BuildItem(IHostService host, FileModel model) { var file = model.FileAndType; var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(host, model.FileAndType).ToList(); model.Content = overwrites; model.LinkToFiles = overwrites.SelectMany(o => o.LinkToFiles).ToImmutableHashSet(); model.LinkToUids = overwrites.SelectMany(o => o.LinkToUids).ToImmutableHashSet(); model.Uids = (from item in overwrites select new UidDefinition( item.Uid, model.LocalPathFromRoot, item.Documentation.StartLine + 1)).ToImmutableArray(); }
public void read_a_spec_node() { var path = TestingContext.FindParallelDirectory("Storyteller.Samples").AppendPath("Specs", "General", "Check properties.md"); var spec = MarkdownReader.ReadFromFile(path); spec.name.ShouldBe("Check properties"); spec.Lifecycle.ShouldBe(Lifecycle.Acceptance); spec.id.ShouldBe("general1"); spec.Filename.ShouldBe(path); spec.MaxRetries.ShouldBe(3); }
//[Fact] public void record_specification_json() { var hierarchy = TestingContext.Hierarchy; var dictionary = new Dictionary <string, Specification>(); hierarchy.GetAllSpecs().Each(x => { var spec = MarkdownReader.ReadFromFile(x.Filename); dictionary.Add(x.id, spec); }); var json = JsonSerialization.ToIndentedJson(dictionary); new FileSystem().WriteStringToFile("Specifications.js", "module.exports = " + json); }
private TokenStream GetToken(bool nx) { var reader = new MarkdownReader(yamlHeaderOnly: false); var content = GetMarkdownContent(); if (nx) { content = content.Replace("\r\n", "\n"); } else if (!content.Contains("\r\n")) { content = content.Replace("\n", "\r\n"); } return(reader.Read(content, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RuleDocument.md"))); }
public void save_specification_body() { var node = ClassUnderTest.Hierarchy.Specifications["embeds"]; var specification = MarkdownReader.ReadFromFile(node.Filename); specification.Children.Add(new Comment { Text = "a new comment" }); ClassUnderTest.SaveSpecification(node.id, specification); var written = MarkdownReader.ReadFromFile(node.Filename); written.Children.Last().ShouldBeOfType <Comment>() .Text.ShouldBe("a new comment"); }