示例#1
0
        public void Append_CreatesNewSegments_WhenCurrentSegmentIsFull()
        {
            // Arrange
            var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name");
            var expected = Enumerable.Range(0, TestViewBufferScope.DefaultBufferSize).Select(i => i.ToString());

            // Act
            foreach (var item in expected)
            {
                buffer.Append(item);
            }
            buffer.Append("Hello");
            buffer.Append("world");

            // Assert
            Assert.Equal(2, buffer.CurrentCount);
            Assert.Collection(buffer.BufferSegments,
                segment => Assert.Equal(expected, segment.Select(v => v.Value)),
                segment =>
                {
                    var array = segment;
                    Assert.Equal("Hello", array[0].Value);
                    Assert.Equal("world", array[1].Value);
                });
        }
示例#2
0
        public void Append_AddsStringRazorValue()
        {
            // Arrange
            var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name");

            // Act
            buffer.Append("Hello world");

            // Assert
            var segment = Assert.Single(buffer.BufferSegments);
            Assert.Equal(1, buffer.CurrentCount);
            Assert.Equal("Hello world", segment[0].Value);
        }
示例#3
0
        public void Clear_ResetsBackingBufferAndIndex(int valuesToWrite)
        {
            // Arrange
            var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name");

            // Act
            for (var i = 0; i < valuesToWrite; i++)
            {
                buffer.Append("Hello");
            }
            buffer.Clear();
            buffer.Append("world");

            // Assert
            var segment = Assert.Single(buffer.BufferSegments);
            Assert.Equal(1, buffer.CurrentCount);
            Assert.Equal("world", segment[0].Value);
        }
示例#4
0
        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());
        }
示例#5
0
        public async Task WriteToAsync_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");
            await buffer.WriteToAsync(htmlWriter.Object, new HtmlTestEncoder());

            // Assert
            htmlWriter.Verify();
        }