예제 #1
0
        public void MoveTo_ViewBuffer_TakesPage_IfCurrentPageDoesNotHaveCapacity()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            for (var i = 0; i < 3; i++)
            {
                original.AppendHtml($"original-{i}");
            }

            // With two items, we'd try to copy the items, but there's no room in the current page.
            // So we just take over the page.
            for (var i = 0; i < 2; i++)
            {
                other.AppendHtml($"other-{i}");
            }

            var page = other[0];

            // Act
            other.MoveTo(original);

            // Assert
            Assert.Equal(0, other.Count); // Page was taken
            Assert.Equal(2, original.Count);
            Assert.Same(page, original[1]);
        }
예제 #2
0
        public void MoveTo_ViewBuffer_TakesPage_IfCurrentPageInOriginalIsFull()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            for (var i = 0; i < 4; i++)
            {
                original.AppendHtml($"original-{i}");
            }

            other.AppendHtml("Hi");

            var page = other[0];

            // Act
            other.MoveTo(original);

            // Assert
            Assert.Equal(0, other.Count); // Page was taken
            Assert.Equal(2, original.Count);
            Assert.Same(page, original[1]);
        }
예제 #3
0
        public void MoveTo_ViewBuffer_MultiplePages()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            for (var i = 0; i < 2; i++)
            {
                original.AppendHtml($"original-{i}");
            }

            for (var i = 0; i < 9; i++)
            {
                other.AppendHtml($"other-{i}");
            }

            var pages = new List <ViewBufferPage>();

            for (var i = 0; i < other.Count; i++)
            {
                pages.Add(other[i]);
            }

            // Act
            other.MoveTo(original);

            // Assert
            Assert.Equal(0, other.Count); // Other is cleared

            Assert.Equal(4, original.Count);
            Assert.Collection(
                original[0].Buffer,
                item => Assert.Equal("original-0", item.Value),
                item => Assert.Equal("original-1", item.Value),
                item => Assert.Null(item.Value),
                item => Assert.Null(item.Value));
            Assert.Collection(
                original[1].Buffer,
                item => Assert.Equal("other-0", item.Value),
                item => Assert.Equal("other-1", item.Value),
                item => Assert.Equal("other-2", item.Value),
                item => Assert.Equal("other-3", item.Value));
            Assert.Collection(
                original[2].Buffer,
                item => Assert.Equal("other-4", item.Value),
                item => Assert.Equal("other-5", item.Value),
                item => Assert.Equal("other-6", item.Value),
                item => Assert.Equal("other-7", item.Value));
            Assert.Collection(
                original[3].Buffer,
                item => Assert.Equal("other-8", item.Value),
                item => Assert.Null(item.Value),
                item => Assert.Null(item.Value),
                item => Assert.Null(item.Value));
        }
예제 #4
0
        public void MoveTo_ViewBuffer_CanAddToTakenPage()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            for (var i = 0; i < 3; i++)
            {
                original.AppendHtml($"original-{i}");
            }

            // More than half full, so we take the page
            for (var i = 0; i < 3; i++)
            {
                other.AppendHtml($"other-{i}");
            }

            var page = other[0];

            other.MoveTo(original);

            // Act
            original.AppendHtml("after-merge");

            // Assert
            Assert.Equal(0, other.Count); // Other is cleared

            Assert.Equal(2, original.Count);
            Assert.Collection(
                original[0].Buffer,
                item => Assert.Equal("original-0", item.Value),
                item => Assert.Equal("original-1", item.Value),
                item => Assert.Equal("original-2", item.Value),
                item => Assert.Null(item.Value));
            Assert.Collection(
                original[1].Buffer,
                item => Assert.Equal("other-0", item.Value),
                item => Assert.Equal("other-1", item.Value),
                item => Assert.Equal("other-2", item.Value),
                item => Assert.Equal("after-merge", item.Value));
        }
예제 #5
0
        public void MoveTo_ViewBuffer_TakesPage_IfOriginalIsEmpty()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            other.AppendHtml("Hi");

            var page = other[0];

            // Act
            other.MoveTo(original);

            // Assert
            Assert.Equal(0, other.Count); // Page was taken
            Assert.Equal(1, original.Count);
            Assert.Same(page, original[0]);
        }
예제 #6
0
        public void MoveTo_ViewBuffer_CopiesItems_IfCurrentPageHasRoom()
        {
            // Arrange
            var scope = new TestViewBufferScope();

            var original = new ViewBuffer(scope, "original", pageSize: 4);
            var other    = new ViewBuffer(scope, "other", pageSize: 4);

            for (var i = 0; i < 2; i++)
            {
                original.AppendHtml($"original-{i}");
            }

            // With two items, this is half full so we try to copy the items.
            for (var i = 0; i < 2; i++)
            {
                other.AppendHtml($"other-{i}");
            }

            var page = other[0];

            // Act
            other.MoveTo(original);

            // Assert
            Assert.Equal(0, other.Count);                        // Other is cleared
            Assert.Contains(page.Buffer, scope.ReturnedBuffers); // Buffer was returned

            Assert.Equal(1, original.Count);
            Assert.Collection(
                original[0].Buffer,
                item => Assert.Equal("original-0", item.Value),
                item => Assert.Equal("original-1", item.Value),
                item => Assert.Equal("other-0", item.Value),
                item => Assert.Equal("other-1", item.Value));
        }