public void GivenAPublicField_WhenGettingTableData_ThenActionColumnDataContainsIdAndName()
        {
            var request = new DataTableRequestModel();
            var expected = new DataTableResultModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(request), Arg<IClientDataTable<CustomField>>.Is.NotNull)).Return(expected);

            var result = Target.DataTableAjaxHandler(request) as JsonResult;

            result.AssertGetData(expected);
        }
        public void GivenLogicManagerGeneratesViewModel_WhenDataTableAjaxHandler_ThenJsonResultContainsViewModel()
        {
            DataTableResultModel expected = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(requestModel), Arg<IClientDataTable<CustomField>>.Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(requestModel);

            result.AssertGetData(expected);
        }
        public void GivenAProvider_WhenGettingTableData_ThenJsonResultContainsViewModelFromLogicManager()
        {
            var request = new DataTableRequestModel();
            var expected = new DataTableResultModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(request), Arg<IClientDataTable<Provider>>.Is.NotNull)).Return(expected);

            var result = Target.DataTableAjaxHandler(request) as JsonResult;

            result.AssertGetData(expected);
        }
        public void GivenBinderCreatesResult_WhenGenerateDataTableResultViewModel_ThenReturnBindResult()
        {
            DataTableResultModel expected = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();
            IClientDataTable<ServiceAttendance> dataTable = MockRepository.GenerateMock<IClientDataTable<ServiceAttendance>>();
            MockDataTableBinder.Expect(m => m.Bind(Repositories.MockServiceAttendanceRepository.Items, dataTable, requestModel)).Return(expected);

            DataTableResultModel actual = Target.GenerateDataTableResultViewModel(requestModel, dataTable);

            Assert.AreEqual(expected, actual);
        }
        public void GivenBinderCreatesResult_WhenGenerateDataTableResultViewModel_ThenReturnBindResult()
        {
            DataTableResultModel expected = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();
            IClientDataTable<CustomField> dataTable = MockRepository.GenerateMock<IClientDataTable<CustomField>>();
            MockDataTableBinder.Expect(m => m.Bind(Arg<IQueryable<CustomField>>.List.ContainsAll(Repositories.MockCustomFieldRepository.Items.OfType<PrivateHealthField>()), Arg.Is(dataTable), Arg.Is(requestModel))).Return(expected);

            DataTableResultModel actual = Target.GenerateDataTableResultViewModel(requestModel, dataTable);

            Assert.AreEqual(expected, actual);
        }
        public void GivenBinderCreatesResult_WhenGenerateDataTableResultViewModel_ThenReturnBindResult()
        {
            DataTableResultModel expected = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();
            IClientDataTable<Program> dataTable = MockRepository.GenerateMock<IClientDataTable<Program>>();
            var expectedQuery = Data.Programs.Where(p => p.IsActive);
            MockDataTableBinder.Expect(m => m.Bind(Arg<IQueryable<Program>>.Matches(p => p.Where(pr => pr.IsActive).SequenceEqual(expectedQuery)), Arg.Is(dataTable), Arg.Is(requestModel))).Return(expected);

            DataTableResultModel actual = Target.GenerateDataTableResultViewModel(requestModel, dataTable);

            Assert.AreEqual(expected, actual);
        }
        public void GivenInitialRecords_WhenBind_ThenResultTotalRecordsMatches()
        {
            IQueryable <Program> originalItems = new List <Program> {
                new Program(), new Program(), new Program()
            }.AsQueryable();
            IQueryable <Program> sortedItems = new List <Program>().AsQueryable().OrderBy(p => p);

            DataTable.Expect(m => m.ApplySort(null)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast <object>().ToList());

            DataTableResultModel actual = Target.Bind <Program>(originalItems, DataTable, RequestModel);

            Assert.AreEqual(originalItems.Count(), actual.iTotalRecords);
        }
        public void GivenRequestEchoValue_WhenBind_ThenResultEchoMatches()
        {
            string expected                  = "this is the expected!";
            IQueryable <Program> items       = Enumerable.Empty <Program>().AsQueryable();
            IQueryable <Program> sortedItems = new List <Program>().AsQueryable().OrderBy(p => p);

            RequestModel.sEcho = expected;
            DataTable.Expect(m => m.ApplySort(null)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Cast <object>().ToList());

            DataTableResultModel actual = Target.Bind <Program>(items, DataTable, RequestModel);

            Assert.AreEqual(expected, actual.sEcho);
        }
        public void GivenCreateResultSetReturnsData_WhenBind_ThenResultDataMatches()
        {
            var expected = new List <object>();
            IQueryable <Program> originalItems = new List <Program> {
                new Program(), new Program(), new Program()
            }.AsQueryable();
            IOrderedQueryable <Program> sortedItems = new List <Program> {
                new Program()
            }.AsQueryable().OrderBy(p => p);

            DataTable.Expect(m => m.ApplySort(null)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(expected);

            DataTableResultModel actual = Target.Bind <Program>(originalItems, DataTable, RequestModel);

            Assert.AreEqual(expected, actual.aaData);
        }
        public void GivenFilterLimitsResults_AndResultSetIsPaged_WhenBind_ThenResultTotalDisplayRecordsMatchesFilteredCount()
        {
            IQueryable <Program> originalItems = new List <Program> {
                new Program(), new Program(), new Program()
            }.AsQueryable();
            IQueryable <Program> filteredItems = new List <Program> {
                new Program(), new Program()
            }.AsQueryable();
            IQueryable <Program> sortedItems = filteredItems.OrderBy(p => p.Id);

            DataTable.Expect(m => m.ApplyFilters(originalItems)).Return(filteredItems);
            DataTable.Expect(m => m.ApplySort(filteredItems)).Return(sortedItems);
            DataTable.Expect(m => m.CreateResultSet(sortedItems, RequestModel)).Return(sortedItems.Take(1).Cast <object>().ToList());

            DataTableResultModel actual = Target.Bind <Program>(originalItems, DataTable, RequestModel);

            Assert.AreEqual(filteredItems.Count(), actual.iTotalDisplayRecords);
        }
        private void AssertDataTableAjaxHandler(bool expectedIsAdministrator)
        {
            var expected = new DataTableResultModel();
            var requestModel = new DataTableRequestModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(requestModel, null)).IgnoreArguments().Do(new Func<DataTableRequestModel, IClientDataTable<ServiceType>, DataTableResultModel>((p, r) =>
            {
                ServiceTypeClientDataTable castR = r as ServiceTypeClientDataTable;
                Assert.IsNotNull(castR);
                Assert.AreEqual(expectedIsAdministrator, castR.IsAdministrator);
                return expected;
            }));

            JsonResult result = Target.DataTableAjaxHandler(requestModel);

            result.AssertGetData(expected);
        }
        public void WhenGetDataTableAjaxHandler_ThenReturnGeneratedViewModel()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            DataTableResultModel expected = new DataTableResultModel();
            MockLogicManager.Expect(m => m.GenerateApprovalDataTableResultViewModel(Arg.Is(model), Arg<IClientDataTable<Student>>.Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(model);

            result.AssertGetData(expected);
        }
        public void WhenDataTableAjaxHandler_ThenJsonContainsGeneratedViewModel()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            DataTableResultModel expected = new DataTableResultModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(model), Arg<IClientDataTable<ServiceOffering>>.Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(model);

            result.AssertGetData(expected);
        }
 private static void AssertDataTableResultModel(DataTableResultModel expected, DataTableResultModel actual)
 {
     Assert.AreEqual(expected.sEcho, actual.sEcho);
     Assert.AreEqual(expected.iTotalDisplayRecords, actual.iTotalDisplayRecords);
     Assert.AreEqual(expected.iTotalRecords, actual.iTotalRecords);
     actual.aaData.Cast<string[]>().ToList().AssertItemsEqual(expected.aaData.Cast<string[]>().ToList());
 }
        public void WhenRequestDataTableAjaxHandler_ThenGenerateListViewModelReceivesCorrectDataTableRequest_AndResultPassedToJson()
        {
            DataTableResultModel expected = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();
            MockAccountManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(requestModel), Arg<IClientDataTable<User>>.Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(requestModel);

            result.AssertGetData(expected);
        }
        public void WhenDataTableAjaxHandler_ThenReturnViewModelFromLogicManager()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            var expected = new DataTableResultModel();
            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(model), Arg<IClientDataTable<Student>>.Is.NotNull)).Return(expected);
            MockLogicManager.Expect(m => m.FindStudentProperties()).Return(Enumerable.Empty<Property>().ToList());

            var result = Target.DataTableAjaxHandler(model);

            result.AssertGetData(expected);
        }