public void PagingWithSortingToManyTest() { // doesnt pass with sqlite Type type = typeof(Item); SearchOptions so = new SearchOptions(type); so.Distinct = true; so.Conditions.Include("PersonItemList", "pi"); so.Conditions.Include("pi", "Person", "p", JoinMode.InnerJoin); so.Conditions.Include(string.Empty, "Category", "c", JoinMode.LeftJoin); so.Sorting.Add("p", Person.Properties.Name); so.Sorting.Add("c", Category.Properties.Name); so.Sorting.Add(Item.Properties.Description); bool exceptionHappened = false; try { so.ExecutePaged(0, 2); } catch (InvalidSortException) { exceptionHappened = true; } if (!exceptionHappened) { Assert.Fail("An InvalidSortException should have been thrown. Sorting by collection association fields is not allowed."); } }
/// <summary> /// Base to paging tests with department/person /// </summary> /// <param name="page">Desired page (zero-based)</param> /// <param name="pageSize">Page size</param> /// <param name="so">Search options</param> private void PagingTestBase(int pageSize, SearchOptions so, Type type) { EntityBase[] allItems = so.Execute(); int pages = (int)System.Math.Ceiling((double)allItems.Length / (double)pageSize); for (int page = 0; page < pages; page++) { EntityBase[] pagedInMemory = allItems.Skip(page * pageSize).Take(pageSize).ToArray(); EntityBase[] items = so.ExecutePaged(page, pageSize); Assert.AreEqual(pagedInMemory.Length, items.Length, string.Format("Page {0} should have {1} items and has {2}.", page + 1, pagedInMemory.Length, items.Length)); for (int i = 0; i < items.Length; i++) { PagingTestObjectComparison(items[i], pagedInMemory[i], type); } } }