Ejemplo n.º 1
0
 public void TomlDeserializeTest()
 {
     using (MemoryStream inputStream = new MemoryStream())
     {
         Fixture fixture = new Fixture();
         Markdown.FrontmatterFormat = Frontmatter.Formats.TOML;
         MarkdownDeserializer <MockDoc> ds = new MarkdownDeserializer <MockDoc>();
         MockDoc      mockDoc = fixture.Create <MockDoc>();
         StreamWriter writer  = new StreamWriter(inputStream);
         writer.WriteLine(Markdown.FrontmatterDelimiter);
         writer.WriteLine("{0} = \"{1}\"", nameof(mockDoc.Title), mockDoc.Title);
         writer.WriteLine("{0} = \"{1}\"", nameof(mockDoc.Author), mockDoc.Author);
         writer.WriteLine("{0} = \"{1}\"", nameof(mockDoc.Date), mockDoc.Date.ToString("o", CultureInfo.InvariantCulture));
         writer.WriteLine(Markdown.FrontmatterDelimiter);
         writer.Write(mockDoc.Content);
         writer.Flush();
         inputStream.Seek(0, SeekOrigin.Begin);
         var newDoc = ds.Deserialize(inputStream);
         Assert.Equal(new { mockDoc.Author, mockDoc.Title, mockDoc.Date.Date, mockDoc.Content },
                      new { newDoc.Author, newDoc.Title, newDoc.Date.Date, newDoc.Content });
     }
 }
Ejemplo n.º 2
0
 public void YamlSerializeTest()
 {
     using (MemoryStream outputStream = new MemoryStream())
         using (MemoryStream comparisonStream = new MemoryStream())
         {
             Fixture fixture = new Fixture();
             Markdown.FrontmatterFormat = Frontmatter.Formats.YAML;
             MarkdownSerializer markdownSerializer = new MarkdownSerializer();
             MockDoc            mockDoc            = fixture.Create <MockDoc>();
             TextWriter         writer             = new StreamWriter(comparisonStream);
             markdownSerializer.Serialize(mockDoc, outputStream);
             writer.WriteLine(Markdown.FrontmatterDelimiter);
             writer.WriteLine("{0}: {1}", nameof(mockDoc.Title), mockDoc.Title);
             writer.WriteLine("{0}: {1}", nameof(mockDoc.Author), mockDoc.Author);
             writer.WriteLine("{0}: {1}", nameof(mockDoc.Date), mockDoc.Date.ToString("o", CultureInfo.InvariantCulture));
             writer.Write("\r\n");
             writer.WriteLine(Markdown.FrontmatterDelimiter);
             writer.Write(mockDoc.Content);
             writer.Flush();
             Assert.Equal(outputStream.ToArray(), comparisonStream.ToArray());
         }
 }
Ejemplo n.º 3
0
 public void TomlSerializeTest()
 {
     using (MemoryStream outputStream = new MemoryStream())
         using (MemoryStream comparisonStream = new MemoryStream())
         {
             Fixture fixture = new Fixture();
             Markdown.FrontmatterFormat = Frontmatter.Formats.TOML;
             MarkdownSerializer markdownSerializer = new MarkdownSerializer();
             MockDoc            mockDoc            = fixture.Create <MockDoc>();
             TextWriter         writer             = new StreamWriter(comparisonStream);
             markdownSerializer.Serialize(mockDoc, outputStream);
             writer.WriteLine(Markdown.FrontmatterDelimiter);
             writer.WriteLine("{0} = \"{1}\"", nameof(mockDoc.Title), mockDoc.Title);
             writer.WriteLine("{0} = \"{1}\"", nameof(mockDoc.Author), mockDoc.Author);
             writer.WriteLine("{0} = {1}", nameof(mockDoc.Date), ((DateTimeOffset)mockDoc.Date).ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFK"));
             writer.Write("\r\n");
             writer.WriteLine(Markdown.FrontmatterDelimiter);
             writer.Write(mockDoc.Content);
             writer.Flush();
             var str  = Encoding.ASCII.GetString(outputStream.ToArray());
             var str2 = Encoding.ASCII.GetString(comparisonStream.ToArray());
             Assert.Equal(outputStream.ToArray(), comparisonStream.ToArray());
         }
 }