public void Test_Index_Default() { TestRecord record1 = new TestRecord(); record1.ID = Guid.NewGuid(); record1.Text = "Record 1"; TestRecord record2 = new TestRecord(); record2.ID = Guid.NewGuid(); record2.Text = "Record 2"; TestRecord record3 = new TestRecord(); record3.ID = Guid.NewGuid(); record3.Text = "Record 3"; TestRecord record4 = new TestRecord(); record4.ID = Guid.NewGuid(); record4.Text = "Record 4"; if (DataAccess.Data == null) { throw new InvalidOperationException("Data provider has not been initialized. Run setup."); } DataAccess.Data.Saver.Save(record1); DataAccess.Data.Saver.Save(record2); DataAccess.Data.Saver.Save(record3); DataAccess.Data.Saver.Save(record4); // Check that the records do exist int count = DataAccess.Data.Indexer.GetEntities <TestRecord>().Length; Assert.AreEqual(4, count, "Invalid number of TestRecord objects found."); BaseIndexProjection page = new BaseIndexProjection("Index", typeof(TestRecord), false); // Disable authorisation requirements for test page.RequireAuthorisation = false; IndexController controller = IndexController.New(page, false); if (controller == null) { throw new Exception("Controller is null."); } controller.Index(); Assert.IsNotNull(controller.DataSource, "The DataSource property on the controller wasn't set."); Assert.AreEqual(4, controller.DataSource.Length, "Item count mismatch."); foreach (TestRecord record in DataAccess.Data.Indexer.GetEntities <TestRecord>()) { DataAccess.Data.Deleter.Delete(record); } }
/// <summary> /// Initializes the page and the controller for the specified type. /// </summary> /// <param name="type"></param> /// <param name="isPaged"></param> public void Initialize(Type type, IndexGrid indexGrid, bool isPaged) { Command = new IndexCommandInfo(type.Name); Grid = indexGrid; controller = IndexController.New(this, new PagingLocation(Grid.CurrentPageIndex, Grid.PageSize)); Grid.SortCommand += new DataGridSortCommandEventHandler(Grid_SortCommand); Grid.PageIndexChanged += new DataGridPageChangedEventHandler(Grid_PageIndexChanged); SortExpression = indexGrid.CurrentSort; }
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); } }
/// <summary> /// Initializes the page and the controller for the specified type. /// </summary> /// <param name="type"></param> /// <param name="isPaged"></param> public void Initialize(Type type, bool isPaged) { Command = new IndexCommandInfo(type.Name); controller = IndexController.New(this); }