public void LinqSelectToLower() { string filterQuery = "j"; //testing using linq lambda. IQueryable <Person> so = Tenor.Linq.SearchOptions <Person> .CreateQuery(); so = so.Where(p => p.Active && p.Email.ToLower() == filterQuery); //so = so.Where(p => p.DepartmentList.Any(e => e.Name == "blah")); //so = so.Where(p => p.DepartmentList.Any(e => e.Name == "bleh")); so = so.OrderBy(p => p.Name); so = so.OrderByDescending(p => p.Active); so = so.Distinct(); //so = so.Take(10); so = so.LoadAlso(p => p.DepartmentList); Person[] persons = so.ToArray(); //testing using classic way. SearchOptions search = new SearchOptions(typeof(Person)); search.Conditions.Add(Person.Properties.Active, true); search.Conditions.And(Person.Properties.Email, filterQuery, CompareOperator.EqualLower); search.Sorting.Add(Person.Properties.Name); search.Sorting.Add(Person.Properties.Active, SortOrder.Descending); search.Distinct = true; search.LoadAlso("DepartmentList"); Person[] persons4 = (Person[])search.Execute(); CollectionAssert.AreEqual(persons4, persons); }
public void EagerLoadingTest() { #if DEBUG EntityBase.LastSearches.Clear(); #endif SearchOptions so = new SearchOptions(typeof(Item)); so.Conditions.Add("Name", "First category", "c"); so.Conditions.Include("Category", "c"); so.LoadAlso("PersonItemList"); so.LoadAlso("Category"); Item[] items = (Item[])so.Execute(); if (items.Length == 0) { Assert.Inconclusive("No query results."); } foreach (Item item in items) { Category cat = item.Category; IList <PersonItem> list = item.PersonItemList; } #if DEBUG Assert.AreEqual(1, EntityBase.LastSearches.Count, "Tenor has generated more than one query."); #else Assert.Inconclusive("Can only check generated queries on debug mode."); #endif }
/// <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); } } }
public void LinqSelectStartsWith() { string filterQuery = "j"; //testing using linq lambda. IQueryable <Person> so = Tenor.Linq.SearchOptions <Person> .CreateQuery(); so = so.Where(p => p.Active && p.Email.StartsWith(filterQuery)); //so = so.Where(p => p.DepartmentList.Any(e => e.Name == "blah")); //so = so.Where(p => p.DepartmentList.Any(e => e.Name == "bleh")); so = so.OrderBy(p => p.Name); so = so.OrderByDescending(p => p.Active); so = so.Distinct(); //so = so.Take(10); so = so.LoadAlso(p => p.DepartmentList); Person[] persons = so.ToArray(); //testing using linq query var query = ( from person in Tenor.Linq.SearchOptions <Person> .CreateQuery() where person.Active && person.Email.StartsWith(GetFilterTest(0, filterQuery)) orderby person.Name, person.Active descending select person ) .Distinct() .LoadAlso(p => p.DepartmentList); Person[] persons2 = query.ToArray(); var valueInAEntity = new { Value = GetFilterTest(0, filterQuery) }; //testing using linq query var query2 = ( from person in Tenor.Linq.SearchOptions <Person> .CreateQuery() where person.Active && person.Email.StartsWith(valueInAEntity.Value) orderby person.Name, person.Active descending select person ) .Distinct() .LoadAlso(p => p.DepartmentList); Person[] persons3 = query2.ToArray(); //testing using classic way. SearchOptions search = new SearchOptions(typeof(Person)); search.Conditions.Add(Person.Properties.Active, true); search.Conditions.And(Person.Properties.Email, filterQuery + "%", CompareOperator.Like); search.Sorting.Add(Person.Properties.Name); search.Sorting.Add(Person.Properties.Active, SortOrder.Descending); search.Distinct = true; search.LoadAlso("DepartmentList"); Person[] persons4 = (Person[])search.Execute(); CollectionAssert.AreEqual(persons2, persons); CollectionAssert.AreEqual(persons3, persons); CollectionAssert.AreEqual(persons4, persons); }