public void AppendWithChar_AddsCharacterToNewPage_AfterLengthFallback() { // Arrange // Imitate ArrayPool<char>.Shared after it falls back from its default char[1024] Bucket to the next one. var bufferSource = new Mock <ICharBufferSource>(); bufferSource .Setup(s => s.Rent(PagedCharBuffer.PageSize)) .Returns(() => new char[2 * PagedCharBuffer.PageSize]); var buffer = new PagedCharBuffer(bufferSource.Object); var stringToAppend = new string('a', 2 * PagedCharBuffer.PageSize); var charToAppend = 't'; // Act buffer.Append(stringToAppend); buffer.Append(charToAppend); // Assert Assert.Equal(2 * PagedCharBuffer.PageSize + 1, buffer.Length); Assert.Collection(buffer.Pages, page => Assert.Equal(stringToAppend.ToCharArray(), page), page => Assert.Equal(charToAppend, page[0])); }
public void AppendWithCharArray_AppendsToMultiplePages() { // Arrange var ch = 'e'; var length = PagedCharBuffer.PageSize * 2 + 3; var charsToAppend = Enumerable.Repeat(ch, 2 * length).ToArray(); var expected = Enumerable.Repeat(ch, PagedCharBuffer.PageSize); var buffer = new PagedCharBuffer(new CharArrayBufferSource()); // Act buffer.Append(charsToAppend, 0, length); // Assert Assert.Equal(length, buffer.Length); Assert.Collection(buffer.Pages, page => Assert.Equal(expected, page), page => Assert.Equal(expected, page), page => { Assert.Equal(ch, page[0]); Assert.Equal(ch, page[1]); Assert.Equal(ch, page[2]); }); }
public PagedBufferedTextWriter(ArrayPool <char> pool, TextWriter inner) { _charBuffer = new PagedCharBuffer(new ArrayPoolBufferSource(pool)); _inner = inner; }