public void Write_WritesDataTypes_ToUnderlyingStream_WhenNotBuffering() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718" }; var unbufferedWriter = new Mock<TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); var testClass = new TestClass(); // Act writer.Flush(); writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(testClass); writer.Write(3.14); writer.Write(2.718m); // Assert Assert.Null(buffer.BufferSegments); foreach (var item in expected) { unbufferedWriter.Verify(v => v.Write(item), Times.Once()); } }
public void Write_WritesDataTypes_ToUnderlyingStream_WhenNotBuffering() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718" }; var unbufferedWriter = new Mock <TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); var testClass = new TestClass(); // Act writer.Flush(); writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(testClass); writer.Write(3.14); writer.Write(2.718m); // Assert Assert.Null(buffer.BufferSegments); foreach (var item in expected) { unbufferedWriter.Verify(v => v.Write(item), Times.Once()); } }
public async Task Write_WritesCharValues_ToUnderlyingStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter> { CallBase = true }; var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); var buffer1 = new[] { 'a', 'b', 'c', 'd' }; var buffer2 = new[] { 'd', 'e', 'f' }; // Act writer.Flush(); writer.Write('x'); writer.Write(buffer1, 1, 2); writer.Write(buffer2); await writer.WriteAsync(buffer2, 1, 1); await writer.WriteLineAsync(buffer1); // Assert Assert.Empty(writer.BufferedWriter.Buffer.BufferEntries); unbufferedWriter.Verify(v => v.Write('x'), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 1, 2), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 0, 4), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer2, 0, 3), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(buffer2, 1, 1), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Once()); }
public async Task Write_WritesCharValues_ToUnderlyingStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter> { CallBase = true }; var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); var buffer1 = new[] { 'a', 'b', 'c', 'd' }; var buffer2 = new[] { 'd', 'e', 'f' }; // Act writer.Flush(); writer.Write('x'); writer.Write(buffer1, 1, 2); writer.Write(buffer2); await writer.WriteAsync(buffer2, 1, 1); await writer.WriteLineAsync(buffer1); // Assert Assert.Empty(writer.BufferedWriter.Content.Entries); unbufferedWriter.Verify(v => v.Write('x'), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 1, 2), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 0, 4), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer2, 0, 3), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(buffer2, 1, 1), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Once()); }
public async Task Write_WritesStringValues_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); // Act await writer.FlushAsync(); writer.Write("a"); writer.WriteLine("ab"); await writer.WriteAsync("ef"); await writer.WriteLineAsync("gh"); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write("a"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine("ab"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("ef"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLineAsync("gh"), Times.Once()); }
public async Task Write_WritesCharValues_ToUnderlyingStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter> { CallBase = true }; unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); var buffer1 = new[] { 'a', 'b', 'c', 'd' }; var buffer2 = new[] { 'd', 'e', 'f' }; // Act writer.Flush(); writer.Write('x'); writer.Write(buffer1, 1, 2); writer.Write(buffer2); await writer.WriteAsync(buffer2, 1, 1); await writer.WriteLineAsync(buffer1); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write('x'), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 1, 2), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 0, 4), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer2, 0, 3), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(buffer2, 1, 1), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Once()); }
public async Task Write_WritesCharValues_ToUnderlyingStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter> { CallBase = true }; unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); var buffer1 = new[] { 'a', 'b', 'c', 'd' }; var buffer2 = new[] { 'd', 'e', 'f' }; // Act writer.Flush(); writer.Write('x'); writer.Write(buffer1, 1, 2); writer.Write(buffer2); await writer.WriteAsync(buffer2, 1, 1); await writer.WriteLineAsync(buffer1); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write('x'), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 1, 2), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer1, 0, 4), Times.Once()); unbufferedWriter.Verify(v => v.Write(buffer2, 0, 3), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(buffer2, 1, 1), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Once()); }
public async Task WriteLines_WritesCharBuffer() { // Arrange var newLine = Environment.NewLine; var writer = new RazorTextWriter(Encoding.UTF8); // Act writer.WriteLine(); await writer.WriteLineAsync(); // Assert var actual = writer.Buffer.BufferEntries; Assert.Equal<object>(new[] { newLine, newLine }, actual); }
public void Write_Object_HtmlContent_AddsToEntries() { // Arrange var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder()); var content = new HtmlString("Hello, world!"); // Act writer.Write((object)content); // Assert Assert.Collection( writer.BufferedWriter.Entries, item => Assert.Same(content, item)); }
public async Task WriteLines_WritesCharBuffer() { // Arrange var newLine = Environment.NewLine; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.WriteLine(); await writer.WriteLineAsync(); // Assert var actual = writer.BufferedWriter.Content.Entries; Assert.Equal <object>(new[] { newLine, newLine }, actual); }
public void WriteLine_WritesDataTypes_ToBuffer() { // Arrange var newLine = Environment.NewLine; var expected = new List<object> { "False", newLine, "1.1", newLine, "3", newLine }; var writer = new RazorTextWriter(Encoding.UTF8); // Act writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Equal(expected, writer.Buffer.BufferEntries); }
public async Task WriteLines_WritesCharBuffer() { // Arrange var newLine = Environment.NewLine; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.WriteLine(); await writer.WriteLineAsync(); // Assert var actual = GetValues(buffer); Assert.Equal <object>(new[] { newLine, newLine }, actual); }
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act source.WriteLine("Hello world"); source.Write(new[] { 'x', 'a', 'b', 'c' }, 1, 3); await source.CopyToAsync(target); // Assert Assert.Equal(3, source.BufferedWriter.Content.Entries.Count); Assert.Equal(1, target.BufferedWriter.Content.Entries.Count); Assert.Equal(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Content.Entries)); }
public void Copy_WritesContent_IfTargetTextWriterIsNotARazorTextWriter() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new StringWriter(); var expected = @"Hello world abc"; // Act source.WriteLine("Hello world"); source.Write(new[] { 'x', 'a', 'b', 'c' }, 1, 3); source.CopyTo(target); // Assert Assert.Equal(expected, target.ToString()); }
public void Write_HtmlContent_AfterFlush_GoesToStream() { // Arrange var stringWriter = new StringWriter(); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(stringWriter, buffer, new HtmlTestEncoder()); writer.Flush(); var content = new HtmlString("Hello, world!"); // Act writer.Write(content); // Assert Assert.Equal("Hello, world!", stringWriter.ToString()); }
public void WriteLine_WritesDataTypes_ToBuffer() { // Arrange var newLine = Environment.NewLine; var expected = new List <object> { "False", newLine, "1.1", newLine, "3", newLine }; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Equal(expected, writer.BufferedWriter.Content.Entries); }
public void Write_HtmlContent_AfterFlush_GoesToStream() { // Arrange var stringWriter = new StringWriter(); var writer = new RazorTextWriter(stringWriter, Encoding.UTF8, new CommonTestEncoder()); writer.Flush(); var content = new HtmlString("Hello, world!"); // Act writer.Write(content); // Assert Assert.Equal("Hello, world!", stringWriter.ToString()); }
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsNotARazorTextWriter() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new StringWriter(); var expected = @"Hello world "; // Act source.Write("Hello "); await source.WriteLineAsync(new[] { 'w', 'o', 'r', 'l', 'd' }); await source.CopyToAsync(target); // Assert Assert.Equal(expected, target.ToString()); }
public void Copy_CopiesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act source.Write("Hello world"); source.Write(new char[1], 0, 1); source.CopyTo(target); // Assert // Make sure content was written to the source. Assert.Equal(2, source.BufferedWriter.Content.Entries.Count); Assert.Equal(1, target.BufferedWriter.Content.Entries.Count); Assert.Same(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Content.Entries)); }
public void WriteLine_WritesDataTypes_ToBuffer() { // Arrange var newLine = Environment.NewLine; var expected = new List <object> { "False", newLine, "1.1", newLine, "3", newLine }; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Equal(expected, GetValues(buffer)); }
public void Write_WritesDataTypes_ToBuffer() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718", "m" }; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(new TestClass()); writer.Write(3.14); writer.Write(2.718m); writer.Write('m'); // Assert Assert.Equal<object>(expected, writer.BufferedWriter.Buffer.BufferEntries); }
public void Write_WritesDataTypes_ToBuffer() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718", "m" }; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(new TestClass()); writer.Write(3.14); writer.Write(2.718m); writer.Write('m'); // Assert Assert.Equal(expected, writer.BufferedWriter.Content.Entries); }
public void Write_WritesDataTypes_ToBuffer() { // Arrange var expected = new object[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718", "m" }; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(new TestClass()); writer.Write(3.14); writer.Write(2.718m); writer.Write('m'); // Assert Assert.Equal(expected, GetValues(buffer)); }
public void WriteLine_WritesDataTypes_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act writer.Flush(); writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Empty(writer.BufferedWriter.Content.ToString()); unbufferedWriter.Verify(v => v.Write("False"), Times.Once()); unbufferedWriter.Verify(v => v.Write("1.1"), Times.Once()); unbufferedWriter.Verify(v => v.Write("3"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Exactly(3)); }
public void Copy_CopiesContent_IfTargetTextWriterIsARazorTextWriterAndNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act target.Flush(); source.Write("Hello world"); source.Write(new[] { 'a', 'b', 'c', 'd' }, 1, 2); source.CopyTo(target); // Assert // Make sure content was written to the source. Assert.Equal(2, source.BufferedWriter.Content.Entries.Count); Assert.Empty(target.BufferedWriter.Content.ToString()); unbufferedWriter.Verify(v => v.Write("Hello world"), Times.Once()); unbufferedWriter.Verify(v => v.Write("bc"), Times.Once()); }
public async Task Write_WritesCharBuffer() { // Arrange var input1 = new ArraySegment<char>(new char[] { 'a', 'b', 'c', 'd' }, 1, 3); var input2 = new ArraySegment<char>(new char[] { 'e', 'f' }, 0, 2); var input3 = new ArraySegment<char>(new char[] { 'g', 'h', 'i', 'j' }, 3, 1); var writer = new RazorTextWriter(Encoding.UTF8); // Act writer.Write(input1.Array, input1.Offset, input1.Count); await writer.WriteAsync(input2.Array, input2.Offset, input2.Count); await writer.WriteLineAsync(input3.Array, input3.Offset, input3.Count); // Assert var buffer = writer.Buffer.BufferEntries; Assert.Equal(4, buffer.Count); Assert.Equal("bcd", buffer[0]); Assert.Equal("ef", buffer[1]); Assert.Equal("j", buffer[2]); Assert.Equal(Environment.NewLine, buffer[3]); }
public async Task Write_WritesStringBuffer() { // Arrange var newLine = Environment.NewLine; var input1 = "Hello"; var input2 = "from"; var input3 = "ASP"; var input4 = ".Net"; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.Write(input1); writer.WriteLine(input2); await writer.WriteAsync(input3); await writer.WriteLineAsync(input4); // Assert var actual = writer.BufferedWriter.Content.Entries; Assert.Equal <object>(new[] { input1, input2, newLine, input3, input4, newLine }, actual); }
public void WriteLine_WritesDataTypes_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); // Act writer.Flush(); writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write("False"), Times.Once()); unbufferedWriter.Verify(v => v.Write("1.1"), Times.Once()); unbufferedWriter.Verify(v => v.Write("3"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Exactly(3)); }
public async Task Write_WritesStringValues_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act await writer.FlushAsync(); writer.Write("a"); writer.WriteLine("ab"); await writer.WriteAsync("ef"); await writer.WriteLineAsync("gh"); // Assert Assert.Empty(writer.BufferedWriter.Content.Entries); unbufferedWriter.Verify(v => v.Write("a"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine("ab"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("ef"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLineAsync("gh"), Times.Once()); }
public async Task Write_WritesCharBuffer() { // Arrange var input1 = new ArraySegment <char>(new char[] { 'a', 'b', 'c', 'd' }, 1, 3); var input2 = new ArraySegment <char>(new char[] { 'e', 'f' }, 0, 2); var input3 = new ArraySegment <char>(new char[] { 'g', 'h', 'i', 'j' }, 3, 1); var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.Write(input1.Array, input1.Offset, input1.Count); await writer.WriteAsync(input2.Array, input2.Offset, input2.Count); await writer.WriteLineAsync(input3.Array, input3.Offset, input3.Count); // Assert var buffer = writer.BufferedWriter.Content.Entries; Assert.Equal(4, buffer.Count); Assert.Equal("bcd", buffer[0]); Assert.Equal("ef", buffer[1]); Assert.Equal("j", buffer[2]); Assert.Equal(Environment.NewLine, buffer[3]); }
//[Fact] // IHtmlContent currently does not support async writes. Hence disabling this test. public async Task CopyAsync_WritesContent_IfTargetTextWriterIsARazorTextWriterAndNotBuffering() { // Arrange var unbufferedWriter = new Mock <TextWriter>(); var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act await target.FlushAsync(); source.WriteLine("Hello from Asp.Net"); await source.WriteAsync(new[] { 'x', 'y', 'z', 'u' }, 0, 3); await source.CopyToAsync(target); // Assert // Make sure content was written to the source. Assert.Equal(3, source.BufferedWriter.Content.Entries.Count); Assert.Empty(target.BufferedWriter.Content.ToString()); unbufferedWriter.Verify(v => v.WriteAsync("Hello from Asp.Net"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(Environment.NewLine), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("xyz"), Times.Once()); }
public async Task Write_WritesStringBuffer() { // Arrange var newLine = Environment.NewLine; var input1 = "Hello"; var input2 = "from"; var input3 = "ASP"; var input4 = ".Net"; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.Write(input1); writer.WriteLine(input2); await writer.WriteAsync(input3); await writer.WriteLineAsync(input4); // Assert var actual = GetValues(buffer); Assert.Equal <object>(new[] { input1, input2, newLine, input3, input4, newLine }, actual); }
public void Write_WritesDataTypes_ToUnderlyingStream_WhenNotBuffering() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718" }; var unbufferedWriter = new Mock<TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); var testClass = new TestClass(); // Act writer.Flush(); writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(testClass); writer.Write(3.14); writer.Write(2.718m); // Assert Assert.Empty(writer.BufferedWriter.Buffer.BufferEntries); foreach (var item in expected) { unbufferedWriter.Verify(v => v.Write(item), Times.Once()); } }
public void Write_WritesDataTypes_ToUnderlyingStream_WhenNotBuffering() { // Arrange var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718" }; var unbufferedWriter = new Mock <TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); var testClass = new TestClass(); // Act writer.Flush(); writer.Write(true); writer.Write(3); writer.Write(ulong.MaxValue); writer.Write(testClass); writer.Write(3.14); writer.Write(2.718m); // Assert Assert.Empty(writer.BufferedWriter.Content.Entries); foreach (var item in expected) { unbufferedWriter.Verify(v => v.Write(item), Times.Once()); } }
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsARazorTextWriterAndNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act await target.FlushAsync(); source.WriteLine("Hello from Asp.Net"); await source.WriteAsync(new[] { 'x', 'y', 'z', 'u' }, 0, 3); await source.CopyToAsync(target); // Assert // Make sure content was written to the source. Assert.Equal(3, source.BufferedWriter.Buffer.BufferEntries.Count); Assert.Empty(target.BufferedWriter.Buffer.BufferEntries); unbufferedWriter.Verify(v => v.WriteAsync("Hello from Asp.Net"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync(Environment.NewLine), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("xyz"), Times.Once()); }
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act source.WriteLine("Hello world"); source.Write(new[] { 'x', 'a', 'b', 'c' }, 1, 3); await source.CopyToAsync(target); // Assert Assert.Equal(3, source.BufferedWriter.Buffer.BufferEntries.Count); Assert.Equal(1, target.BufferedWriter.Buffer.BufferEntries.Count); Assert.Same(source.BufferedWriter.Buffer.BufferEntries, target.BufferedWriter.Buffer.BufferEntries[0]); }
public void Copy_CopiesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering() { // Arrange var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act source.Write("Hello world"); source.Write(new char[1], 0, 1); source.CopyTo(target); // Assert // Make sure content was written to the source. Assert.Equal(2, source.BufferedWriter.Buffer.BufferEntries.Count); Assert.Equal(1, target.BufferedWriter.Buffer.BufferEntries.Count); Assert.Same(source.BufferedWriter.Buffer.BufferEntries, target.BufferedWriter.Buffer.BufferEntries[0]); }
public void Copy_CopiesContent_IfTargetTextWriterIsARazorTextWriterAndNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act target.Flush(); source.Write("Hello world"); source.Write(new[] { 'a', 'b', 'c', 'd' }, 1, 2); source.CopyTo(target); // Assert // Make sure content was written to the source. Assert.Equal(2, source.BufferedWriter.Buffer.BufferEntries.Count); Assert.Empty(target.BufferedWriter.Buffer.BufferEntries); unbufferedWriter.Verify(v => v.Write("Hello world"), Times.Once()); unbufferedWriter.Verify(v => v.Write("bc"), Times.Once()); }
public async Task Write_WritesStringValues_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); // Act await writer.FlushAsync(); writer.Write("a"); writer.WriteLine("ab"); await writer.WriteAsync("ef"); await writer.WriteLineAsync("gh"); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write("a"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine("ab"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("ef"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLineAsync("gh"), Times.Once()); }
public async Task Write_WritesStringBuffer() { // Arrange var newLine = Environment.NewLine; var input1 = "Hello"; var input2 = "from"; var input3 = "ASP"; var input4 = ".Net"; var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8); // Act writer.Write(input1); writer.WriteLine(input2); await writer.WriteAsync(input3); await writer.WriteLineAsync(input4); // Assert var actual = writer.BufferedWriter.Buffer.BufferEntries; Assert.Equal<object>(new[] { input1, input2, newLine, input3, input4, newLine }, actual); }
public void WriteLine_WritesDataTypes_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act writer.Flush(); writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Empty(writer.BufferedWriter.Buffer.BufferEntries); unbufferedWriter.Verify(v => v.Write("False"), Times.Once()); unbufferedWriter.Verify(v => v.Write("1.1"), Times.Once()); unbufferedWriter.Verify(v => v.Write("3"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Exactly(3)); }
public void WriteLine_Object_HtmlContent_AddsToEntries() { // Arrange var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder()); var content = new HtmlString("Hello, world!"); // Act writer.WriteLine(content); // Assert Assert.Collection( writer.BufferedWriter.Entries, item => Assert.Same(content, item), item => Assert.Equal(Environment.NewLine, item)); }
public void WriteLine_WritesDataTypes_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); unbufferedWriter.SetupGet(w => w.Encoding).Returns(Encoding.UTF8); var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(unbufferedWriter.Object, buffer, new HtmlTestEncoder()); // Act writer.Flush(); writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Null(buffer.BufferSegments); unbufferedWriter.Verify(v => v.Write("False"), Times.Once()); unbufferedWriter.Verify(v => v.Write("1.1"), Times.Once()); unbufferedWriter.Verify(v => v.Write("3"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine(), Times.Exactly(3)); }
public async Task Write_WritesStringBuffer() { // Arrange var newLine = Environment.NewLine; var input1 = "Hello"; var input2 = "from"; var input3 = "ASP"; var input4 = ".Net"; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.Write(input1); writer.WriteLine(input2); await writer.WriteAsync(input3); await writer.WriteLineAsync(input4); // Assert var actual = GetValues(buffer); Assert.Equal<object>(new[] { input1, input2, newLine, input3, input4, newLine }, actual); }
public async Task WriteLines_WritesCharBuffer() { // Arrange var newLine = Environment.NewLine; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.WriteLine(); await writer.WriteLineAsync(); // Assert var actual = GetValues(buffer); Assert.Equal<object>(new[] { newLine, newLine }, actual); }
public async Task Write_WritesStringValues_ToUnbufferedStream_WhenNotBuffering() { // Arrange var unbufferedWriter = new Mock<TextWriter>(); var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8); // Act await writer.FlushAsync(); writer.Write("a"); writer.WriteLine("ab"); await writer.WriteAsync("ef"); await writer.WriteLineAsync("gh"); // Assert Assert.Empty(writer.BufferedWriter.Buffer.BufferEntries); unbufferedWriter.Verify(v => v.Write("a"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLine("ab"), Times.Once()); unbufferedWriter.Verify(v => v.WriteAsync("ef"), Times.Once()); unbufferedWriter.Verify(v => v.WriteLineAsync("gh"), Times.Once()); }
public void WriteLine_WritesDataTypes_ToBuffer() { // Arrange var newLine = Environment.NewLine; var expected = new List<object> { "False", newLine, "1.1", newLine, "3", newLine }; var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name"); var writer = new RazorTextWriter(TextWriter.Null, buffer, new HtmlTestEncoder()); // Act writer.WriteLine(false); writer.WriteLine(1.1f); writer.WriteLine(3L); // Assert Assert.Equal(expected, GetValues(buffer)); }