public void PagingPastEndSkippingLastPageKnownTotalItemCount() { Catalog context = new Catalog(); EnqueueCallback(() => { this._dds.PageSize = 5; this._dds.QueryName = "GetPurchaseOrdersQuery"; this._dds.DomainContext = context; this._dds.Load(); }); this.AssertLoadingData(); this.AssertPageChanged(); int totalItemCount = 0; EnqueueCallback(() => { this.ResetLoadState(); this.ResetPageChanged(); Assert.AreEqual(5, this._view.Count, "Count after the initial load"); Assert.AreEqual(0, this._view.PageIndex, "PageIndex after the initial load"); Assert.IsTrue(this._view.TotalItemCount > this._view.Count, "After the initial load, TotalItemCount is expected to be greater than the Count"); Assert.IsTrue(this._view.PageCount > 0, "After the initial load, PageCount is expected to be greater than 0"); totalItemCount = this._view.TotalItemCount; // Move well beyond the end this._view.MoveToPage(this._view.PageCount + 100); }); this.AssertLoadingData(2); this.AssertPageChanged(); EnqueueCallback(() => { this.ResetLoadState(); this.ResetPageChanged(); int countOnLastPage = this._view.TotalItemCount % this._view.PageSize; if (countOnLastPage == 0) { countOnLastPage = this._view.PageSize; } Assert.AreEqual(countOnLastPage, this._view.Count, "Count after changing page"); Assert.AreEqual(PagingHelper.CalculatePageCount(this._view.TotalItemCount, this._view.PageSize) - 1, this._view.PageIndex, "PageIndex after changing page"); Assert.AreEqual(totalItemCount, this._view.TotalItemCount, "TotalItemCount after changing page"); }); EnqueueTestComplete(); }
public void PageCount() { DomainDataSource dds = new DomainDataSource(); dds.QueryName = "GetPurchaseOrdersQuery"; dds.DomainContext = new Catalog(); int pageCountChanged = 0; ((INotifyPropertyChanged)dds.DataView).PropertyChanged += (sender, e) => { if (e.PropertyName == "PageCount") { pageCountChanged++; } }; Assert.AreEqual(0, dds.DataView.PageCount, "Page count should be 0 by default"); dds.PageSize = 5; Assert.AreEqual(1, dds.DataView.PageCount, "Page count should be 1 once PageSize is set"); Assert.AreEqual(1, pageCountChanged, "The PageCount should have changed."); pageCountChanged = 0; bool loaded = false; dds.Load(); dds.LoadedData += (sender, e) => loaded = true; this.EnqueueConditional(() => loaded); this.EnqueueCallback(() => { Assert.AreEqual(5, dds.DataView.Count, "Count after the initial load"); Assert.AreEqual(0, dds.DataView.PageIndex, "PageIndex after the initial load"); Assert.IsTrue(dds.DataView.TotalItemCount > dds.DataView.Count, "After the initial load, TotalItemCount should be greater than Count"); Assert.AreEqual(PagingHelper.CalculatePageCount(dds.DataView.TotalItemCount, dds.DataView.PageSize), dds.DataView.PageCount, "PageCount after the initial load"); Assert.AreEqual(1, pageCountChanged, "The PageCount should have changed."); }); this.EnqueueTestComplete(); }