Example #1
0
        public async Task Write_String()
        {
            // Arrange
            var pool  = new TestArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            // These numbers chosen to hit boundary conditions in buffer lengths
            Assert.Equal(4096, Content.Length); // Update these numbers if this changes.
            var chunkSizes = new int[] { 3, 1021, 1023, 1023, 1, 1, 1024 };

            // Act
            var offset = 0;

            foreach (var chunkSize in chunkSizes)
            {
                var chunk = new string(Content, offset, chunkSize);
                writer.Write(chunk);
                offset += chunkSize;
            }

            await writer.FlushAsync();

            // Assert
            Assert.Equal <char>(Content, inner.ToString().ToCharArray());
        }
Example #2
0
        public async Task Write_CharArray_Null()
        {
            // Arrange
            var pool  = new TestArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            // Act
            writer.Write((char[])null);

            await writer.FlushAsync();

            // Assert
            Assert.Empty(inner.ToString());
        }
Example #3
0
        public async Task FlushAsync_WritesContentToInner_WithLargeArrays()
        {
            // Arrange
            var pool  = new RentMoreArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            for (var i = 0; i < Content.Length; i++)
            {
                writer.Write(Content[i]);
            }

            // Act
            await writer.FlushAsync();

            // Assert
            Assert.Equal <char>(Content, inner.ToString().ToCharArray());
        }
Example #4
0
        public async Task Write_Char()
        {
            // Arrange
            var pool  = new TestArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            // Act
            for (var i = 0; i < Content.Length; i++)
            {
                writer.Write(Content[i]);
            }

            await writer.FlushAsync();

            // Assert
            Assert.Equal <char>(Content, inner.ToString().ToCharArray());
        }
Example #5
0
        public async Task FlushAsync_ReturnsPages()
        {
            // Arrange
            var pool  = new TestArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            for (var i = 0; i < Content.Length; i++)
            {
                writer.Write(Content[i]);
            }

            // Act
            await writer.FlushAsync();

            // Assert
            Assert.Equal(3, pool.Returned.Count);
        }
Example #6
0
        public async Task Write_CharArray()
        {
            // Arrange
            var pool  = new TestArrayPool();
            var inner = new StringWriter();

            var writer = new PagedBufferedTextWriter(pool, inner);

            // These numbers chosen to hit boundary conditions in buffer lengths
            Assert.Equal(4096, Content.Length); // Update these numbers if this changes.
            var chunkSizes = new int[] { 3, 1021, 1023, 1023, 1, 1, 1024 };

            // Act
            var offset = 0;

            foreach (var chunkSize in chunkSizes)
            {
                var chunk = new char[chunkSize];
                for (var j = 0; j < chunkSize; j++)
                {
                    chunk[j] = Content[offset + j];
                }

                writer.Write(chunk);
                offset += chunkSize;
            }

            await writer.FlushAsync();

            // Assert
            var array = inner.ToString().ToCharArray();

            for (var i = 0; i < Content.Length; i++)
            {
                Assert.Equal(Content[i], array[i]);
            }

            Assert.Equal <char>(Content, inner.ToString().ToCharArray());
        }