public void WriteTo_WritesRazorValues_ToTextWriter() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new StringWriter(); // Act buffer.Append("Hello"); buffer.AppendHtml(new HtmlString(" world")); buffer.AppendHtml(" 123"); buffer.WriteTo(writer, new HtmlTestEncoder()); // Assert Assert.Equal("Hello world 123", writer.ToString()); }
public void WriteTo_WritesSelf_WhenWriterIsHtmlTextWriter() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var htmlWriter = new Mock <HtmlTextWriter>(); htmlWriter.Setup(w => w.Write(buffer)).Verifiable(); // Act buffer.Append("Hello world"); buffer.WriteTo(htmlWriter.Object, new HtmlTestEncoder()); // Assert htmlWriter.Verify(); }
public void WriteTo_WritesRazorValuesFromAllBuffers(int valuesToWrite) { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(4), "some-name"); var writer = new StringWriter(); var expected = string.Join("", Enumerable.Range(0, valuesToWrite).Select(_ => "abc")); // Act for (var i = 0; i < valuesToWrite; i++) { buffer.AppendHtml("abc"); } buffer.WriteTo(writer, new HtmlTestEncoder()); // Assert Assert.Equal(expected, writer.ToString()); }
public void WriteTo_WritesRazorValuesFromAllBuffers(int valuesToWrite) { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4); var writer = new StringWriter(); var expected = string.Join("", Enumerable.Range(0, valuesToWrite).Select(_ => "abc")); // Act for (var i = 0; i < valuesToWrite; i++) { buffer.AppendHtml("abc"); } buffer.WriteTo(writer, new HtmlTestEncoder()); // Assert Assert.Equal(expected, writer.ToString()); }
public void WriteTo_WritesRazorValues_ToTextWriter() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 32); var writer = new StringWriter(); // Act buffer.Append("Hello"); buffer.AppendHtml(new HtmlString(" world")); buffer.AppendHtml(" 123"); buffer.WriteTo(writer, new HtmlTestEncoder()); // Assert Assert.Equal("HtmlEncode[[Hello]] world 123", writer.ToString()); }