Exemplo n.º 1
0
        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", pageSize: 4);
            var writer = new ViewBufferTextWriter(buffer, Encoding.UTF8);

            // Act
            writer.WriteLine(false);
            writer.WriteLine(1.1f);
            writer.WriteLine(3L);

            // Assert
            Assert.Equal(expected, GetValues(buffer));
        }
Exemplo n.º 2
0
        public void WriteLine_WritesDataTypes_ToUnbufferedStream_WhenNotBuffering()
        {
            // Arrange
            var inner  = new Mock <TextWriter>();
            var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4);
            var writer = new ViewBufferTextWriter(buffer, Encoding.UTF8, new HtmlTestEncoder(), inner.Object);

            // Act
            writer.Flush();
            writer.WriteLine(false);
            writer.WriteLine(1.1f);
            writer.WriteLine(3L);

            // Assert
            inner.Verify(v => v.Write("False"), Times.Once());
            inner.Verify(v => v.Write("1.1"), Times.Once());
            inner.Verify(v => v.Write("3"), Times.Once());
            inner.Verify(v => v.WriteLine(), Times.Exactly(3));
        }
Exemplo n.º 3
0
        public async Task WriteLines_WritesCharBuffer()
        {
            // Arrange
            var newLine = Environment.NewLine;
            var buffer  = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4);
            var writer  = new ViewBufferTextWriter(buffer, Encoding.UTF8);

            // Act
            writer.WriteLine();
            await writer.WriteLineAsync();

            // Assert
            var actual = GetValues(buffer);

            Assert.Equal <object>(new[] { newLine, newLine }, actual);
        }
Exemplo n.º 4
0
        public async Task Write_WritesStringValues_ToUnbufferedStream_WhenNotBuffering()
        {
            // Arrange
            var inner  = new Mock <TextWriter>();
            var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4);
            var writer = new ViewBufferTextWriter(buffer, Encoding.UTF8, new HtmlTestEncoder(), inner.Object);

            // Act
            await writer.FlushAsync();

            writer.Write("a");
            writer.WriteLine("ab");
            await writer.WriteAsync("ef");

            await writer.WriteLineAsync("gh");

            // Assert
            inner.Verify(v => v.Write("a"), Times.Once());
            inner.Verify(v => v.WriteLine("ab"), Times.Once());
            inner.Verify(v => v.WriteAsync("ef"), Times.Once());
            inner.Verify(v => v.WriteLineAsync("gh"), Times.Once());
        }
Exemplo n.º 5
0
        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", pageSize: 4);
            var writer  = new ViewBufferTextWriter(buffer, Encoding.UTF8);

            // 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);
        }