1. 程式人生 > >應用程式框架實戰二十四:基礎查詢擴充套件

應用程式框架實戰二十四:基礎查詢擴充套件

using Microsoft.VisualStudio.TestTools.UnitTesting; using Util.Domains.Repositories; namespace Util.Domains.Tests.Repositories { /// <summary> /// 分頁測試 /// </summary> [TestClass] public class PagerTest { #region 測試初始化 /// <summary> /// 分頁
/// </summary> private Pager _pager; /// <summary> /// 測試初始化 /// </summary> [TestInitialize] public void TestInit() { _pager = new Pager(); } #endregion #region 預設值 /// <summary> ///
分頁預設值 /// </summary> [TestMethod] public void Test_Default() { Assert.AreEqual( 1, _pager.Page ); Assert.AreEqual( 20, _pager.PageSize ); Assert.AreEqual( 0, _pager.TotalCount ); Assert.AreEqual( 0, _pager.PageCount ); }
#endregion #region PageCount(總頁數) /// <summary> /// 總行數為0,每頁20行,頁數為0 /// </summary> [TestMethod] public void TestPageCount_TotalCountIs0() { _pager.TotalCount = 0; Assert.AreEqual( 0, _pager.PageCount ); } /// <summary> /// 總行數為100,每頁20行,頁數為5 /// </summary> [TestMethod] public void TestPageCount_TotalCountIs100() { _pager.TotalCount = 100; Assert.AreEqual( 5, _pager.PageCount ); } /// <summary> /// 總行數為1,每頁20行,頁數為1 /// </summary> [TestMethod] public void TestPageCount_TotalCountIs1() { _pager.TotalCount = 1; Assert.AreEqual( 1, _pager.PageCount ); } /// <summary> /// 總行數為100,每頁10行,頁數為10 /// </summary> [TestMethod] public void TestPageCount_PageSizeIs10_TotalCountIs100() { _pager.PageSize = 10; _pager.TotalCount = 100; Assert.AreEqual( 10, _pager.PageCount ); } #endregion #region Page(頁索引) /// <summary> /// 頁索引小於1,則修正為1 /// </summary> [TestMethod] public void TestPage_Less1() { _pager.Page = 0; Assert.AreEqual( 1, _pager.Page ); _pager.Page = -1; Assert.AreEqual( 1, _pager.Page ); } #endregion #region SkipCount(跳過的行數) /// <summary> /// 跳過的行數 /// </summary> [TestMethod] public void TestSkipCount() { _pager.TotalCount = 100; _pager.Page = 0; Assert.AreEqual( 0, _pager.SkipCount ); _pager.Page = 1; Assert.AreEqual( 0, _pager.SkipCount ); _pager.Page = 2; Assert.AreEqual( 20, _pager.SkipCount ); _pager.Page = 3; Assert.AreEqual( 40, _pager.SkipCount ); _pager.Page = 4; Assert.AreEqual( 60, _pager.SkipCount ); _pager.Page = 5; Assert.AreEqual( 80, _pager.SkipCount ); _pager.Page = 6; Assert.AreEqual( 80, _pager.SkipCount ); } /// <summary> /// 跳過的行數 /// </summary> [TestMethod] public void TestSkipCount_2() { _pager.TotalCount = 99; _pager.Page = 0; Assert.AreEqual( 0, _pager.SkipCount ); _pager.Page = 1; Assert.AreEqual( 0, _pager.SkipCount ); _pager.Page = 2; Assert.AreEqual( 20, _pager.SkipCount ); _pager.Page = 3; Assert.AreEqual( 40, _pager.SkipCount ); _pager.Page = 4; Assert.AreEqual( 60, _pager.SkipCount ); _pager.Page = 5; Assert.AreEqual( 80, _pager.SkipCount ); _pager.Page = 6; Assert.AreEqual( 80, _pager.SkipCount ); } /// <summary> /// 跳過的行數 /// </summary> [TestMethod] public void TestSkipCount_3() { _pager.TotalCount = 0; _pager.Page = 1; Assert.AreEqual( 0, _pager.SkipCount ); } #endregion } }