public void Append_AddsHtmlContentRazorValue() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var content = new HtmlString("hello-world"); // Act buffer.AppendHtml(content); // Assert var segment = Assert.Single(buffer.BufferSegments); Assert.Equal(1, buffer.CurrentCount); Assert.Same(content, segment[0].Value); }
public void AppendHtml_AddsHtmlStringValues() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var value = "Hello world"; // Act buffer.AppendHtml(value); // Assert var segment = Assert.Single(buffer.BufferSegments); Assert.Equal(1, buffer.CurrentCount); var htmlString = Assert.IsType<HtmlString>(segment[0].Value); Assert.Equal("Hello world", htmlString.ToString()); }
public async Task WriteToAsync_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"); } await buffer.WriteToAsync(writer, new HtmlTestEncoder()); // Assert Assert.Equal(expected, writer.ToString()); }
public async Task WriteToAsync_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"); await buffer.WriteToAsync(writer, new HtmlTestEncoder()); // Assert Assert.Equal("Hello world 123", writer.ToString()); }