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.Pages[0]; // Act other.MoveTo(original); // Assert Assert.Empty(other.Pages); // Page was taken Assert.Same(page, Assert.Single(original.Pages)); }
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]); }
public void MoveTo_FlattensAndClears() { // Arrange var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4); var nestedItems = new List <object>(); var nested = new HtmlContentBuilder(nestedItems); nested.AppendHtml("Hello"); buffer.AppendHtml(nested); var destinationItems = new List <object>(); var destination = new HtmlContentBuilder(destinationItems); // Act buffer.MoveTo(destination); // Assert Assert.Empty(nestedItems); Assert.Empty(buffer.Pages); Assert.Equal("Hello", Assert.IsType <HtmlEncodedString>(destinationItems[0]).Value); }
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)); }