public async Task Output_before() { /* Given */ var md = @" before #include::xref://section:file.md "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@" before included ", actual); }
public async Task Mixed_content_with_headers() { /* Given */ var md = @" # header #include::xref://src:DocsTool/Program.cs?f=Main "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@" # header included ", actual); }
public async Task Process_full_example() { /* Given */ var md = @"## Syntax ### Include csharp code snippets #### Include file ```markdown \#include::xref://src:DocsTool/Program.cs ``` ```csharp #include::xref://src:DocsTool/Program.cs ``` #### Include function ```markdown \#include::xref://src:DocsTool/Program.cs?f=Main ``` ```csharp #include::xref://src:DocsTool/Program.cs?f=Main ``` "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@"## Syntax ### Include csharp code snippets #### Include file ```markdown \#include::xref://src:DocsTool/Program.cs ``` ```csharp included ``` #### Include function ```markdown \#include::xref://src:DocsTool/Program.cs?f=Main ``` ```csharp included ``` ", actual); }