public void Test_Index_PageIndex0_Size1() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Title"; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Test Title 2"; DataAccess.Data.Saver.Save(article); DataAccess.Data.Saver.Save(article2); PagingLocation location = new PagingLocation(0, 1); IIndexStrategy strategy = IndexStrategy.New<TestArticle>(location, "TitleAscending", false); strategy.TypeName = "TestArticle"; strategy.EnablePaging = true; TestArticle[] foundArticles = Collection<TestArticle>.ConvertAll(strategy.Index()); Assert.IsNotNull(foundArticles); Assert.AreEqual(2, location.AbsoluteTotal, "Absolute total invalid."); Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found."); }
public void Test_GetPageOfEntitiesWithReference_Page1_PageSize1_SortAscending() { TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); category.Name = "Test Category"; TestArticle article1 = new TestArticle(); article1.ID = Guid.NewGuid(); article1.Title = "Article C"; article1.Categories = new TestCategory[]{category}; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Article B"; article2.Categories = new TestCategory[]{category}; TestArticle article3 = new TestArticle(); article3.ID = Guid.NewGuid(); article3.Title = "Article A"; article3.Categories = new TestCategory[]{category}; DataAccess.Data.Saver.Save(category); DataAccess.Data.Saver.Save(article3); DataAccess.Data.Saver.Save(article2); DataAccess.Data.Saver.Save(article1); string[] titles = new String[] { article1.Title, article2.Title, article3.Title }; PagingLocation pagingLocation = new PagingLocation(0, 1); string sortExpression = "TitleAscending"; TestArticle[] entities = DataAccess.Data.Indexer.GetPageOfEntitiesWithReference<TestArticle>("Categories", typeof(TestCategory), category.ID, pagingLocation, sortExpression); Assert.IsNotNull(entities); foreach (TestArticle a in entities) { Assert.Greater(Array.IndexOf(titles, a.Title), -1, "The title of one of the retrieved entities doesn't match any of those expected."); } Assert.AreEqual(1, entities.Length, "Invalid number found."); Assert.AreEqual(article3.Title, entities[0].Title, "Sorting failed #1."); //Assert.AreEqual(article2.Title, entities[1].Title, "Sorting failed #2."); //Assert.AreEqual(article1.Title, entities[1].Title, "Sorting failed #3."); Assert.AreEqual(3, pagingLocation.AbsoluteTotal, "Invalid total"); }
public virtual void Test_GetPageOfEntitiesWithReference_EmptyReferencedEntityID_NotFound() { using (LogGroup logGroup = LogGroup.Start("Testing the index retrieval of entities that don't have any references on a particular property.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); Guid userID = user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; TestRole role = new TestRole(); Guid roleID = role.ID = Guid.NewGuid(); role.Name = "Test Role"; // Assign a user to the role role.Users = new TestUser[] {user}; DataAccess.Data.Saver.Save(user); DataAccess.Data.Saver.Save(role); PagingLocation location = new PagingLocation(0, 10); string sortExpression = "UsernameAscending"; TestRole[] foundRoles = DataAccess.Data.Indexer.GetPageOfEntitiesWithReference<TestRole>("Users", typeof(TestUser), Guid.Empty, location, sortExpression); Assert.IsNotNull(foundRoles, "The found roles object returned was null."); Assert.AreEqual(0, foundRoles.Length, "Invalid number of roles found."); } }
public void Test_GetEntitiesPage_Page1_PageSize2_SortDescending() { TestArticle article1 = new TestArticle(); article1.ID = Guid.NewGuid(); article1.Title = "Article C"; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Article B"; TestArticle article3 = new TestArticle(); article3.ID = Guid.NewGuid(); article3.Title = "Article A"; List<string> titles = new List<string>(); titles.Add(article1.Title); titles.Add(article2.Title); titles.Add(article3.Title); List<Guid> ids = new List<Guid>(); ids.Add(article1.ID); ids.Add(article2.ID); ids.Add(article3.ID); DataAccess.Data.Saver.Save(article1); DataAccess.Data.Saver.Save(article2); DataAccess.Data.Saver.Save(article3); PagingLocation pagingLocation = new PagingLocation(0, 2); string sortExpression = "TitleDescending"; TestArticle[] entities = DataAccess.Data.Indexer.GetPageOfEntities<TestArticle>(pagingLocation, sortExpression); Assert.IsNotNull(entities); List<string> titlesFound = new List<string>(); List<Guid> idsFound = new List<Guid>(); foreach (TestArticle a in entities) { Assert.IsFalse(idsFound.Contains(a.ID), "The returned entities list includes more than one entity with the same ID'."); Assert.IsFalse(titlesFound.Contains(a.Title), "The returned entities list includes more than one entity with the same title: '" + a.Title + "'."); Assert.IsTrue(titles.Contains(a.Title), "The title of one of the retrieved entities doesn't match any of those expected."); Assert.IsTrue(ids.Contains(a.ID), "The ID of one of the retrieved entities doesn't match any of those expected."); titlesFound.Add(a.Title); idsFound.Add(a.ID); } Assert.AreEqual(2, entities.Length, "Invalid number found."); Assert.AreEqual(article1.Title, entities[0].Title, "Sorting failed #1."); Assert.AreEqual(article2.Title, entities[1].Title, "Sorting failed #2."); }
public virtual void Test_GetEntitiesPageMatchReference() { using (LogGroup logGroup = LogGroup.Start("Testing the GetEntitiesPageMatchReference function to ensure it finds entities properly.", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Article"; TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); category.Name = "Test Category"; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Test Article 2"; TestCategory category2 = new TestCategory(); category2.ID = Guid.NewGuid(); category2.Name = "Test Category 2"; article.Categories = new TestCategory[] { category, category2 }; article2.Categories = new TestCategory[] { category, category2 }; DataAccess.Data.Saver.Save(category2); DataAccess.Data.Saver.Save(category); DataAccess.Data.Saver.Save(article); DataAccess.Data.Saver.Save(article2); PagingLocation location = new PagingLocation(0, 10); IEntity[] results = DataAccess.Data.Indexer.GetPageOfEntitiesWithReference<TestArticle>("Categories", typeof(TestCategory), category.ID, location, "TitleAscending"); Assert.IsNotNull(results, "The results were null."); Assert.AreEqual(2, location.AbsoluteTotal, "The absolute total count is incorrect."); if (results != null) { Assert.AreEqual(2, results.Length, "Incorrect number of results found."); IEntity entity = results[0]; Assert.AreEqual(article.GetType().FullName, entity.GetType().FullName, "The types don't match."); } } }
public void Test_Index_Paged_Page1() { List<TestRecord> list = new List<TestRecord>(); for (int i = 0; i < 30; i++) { TestRecord record = new TestRecord(); record.ID = Guid.NewGuid(); record.Text = "Record " + i; DataAccess.Data.Saver.Save(record); list.Add(record); } if (DataAccess.Data == null) throw new InvalidOperationException("Data provider has not been initialized. Run setup."); BaseIndexProjection page = new BaseIndexProjection("Index", typeof(TestRecord), false); PagingLocation location = new PagingLocation(0, 20); IndexController controller = IndexController.New(page, location); if (controller == null) throw new Exception("Controller is null."); controller.CurrentPageIndex = 0; controller.Index(); Assert.IsNotNull(controller.DataSource, "The DataSource of the controller wasn't set."); IEntity[] entities = (IEntity[])controller.DataSource; Assert.AreEqual(20, entities.Length, "DataSource count mismatch."); foreach (TestRecord record in list) DataAccess.Data.Deleter.Delete(record); }
public void Test_Index_PrepareIndex() { List<TestRecord> list = new List<TestRecord>(); for (int i = 0; i < 30; i++) { TestRecord record = new TestRecord(); record.ID = Guid.NewGuid(); record.Name = "Record " + i; record.Text = "Record " + i; DataAccess.Data.Saver.Save(record); list.Add(record); } if (DataAccess.Data == null) throw new InvalidOperationException("Data provider has not been initialized. Run setup."); BaseIndexProjection page = new BaseIndexProjection("Index", typeof(TestRecord), false); PagingLocation location = new PagingLocation(0, 20); IndexController controller = IndexController.New(page, location); if (controller == null) throw new Exception("Controller is null."); controller.SortExpression = "NameAscending"; IEntity[] entities = controller.PrepareIndex(); Assert.IsNotNull(entities, "entities == null"); Assert.AreEqual(20, entities.Length, "Entity count mismatch."); Assert.AreEqual(30, controller.AbsoluteTotal, "Absolute count mismatch."); foreach (TestRecord record in list) DataAccess.Data.Deleter.Delete(record); }
public void Test_Index_PageIndex1_Size2() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Title"; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Test Title 2"; DataAccess.Data.Saver.Save(article); DataAccess.Data.Saver.Save(article2); PagingLocation location = new PagingLocation(1, 2); IIndexStrategy strategy = IndexStrategy.New<TestArticle>(location, "TitleAscending", false); strategy.TypeName = "TestArticle"; strategy.EnablePaging = true; TestArticle[] foundArticles = Collection<TestArticle>.ConvertAll(strategy.Index()); Assert.IsNotNull(foundArticles); // There should be no articles found because it's requesting a page outside the available range Assert.AreEqual(0, foundArticles.Length, "Invalid number of test articles found."); }
public static IndexController New(IControllable container, PagingLocation location) { container.CheckCommand(); IndexController controller = ControllerState.Controllers.Creator.NewIndexer(container.Command.TypeName); controller.Container = container; controller.EnablePaging = true; controller.Indexer.Location = location; return controller; }