public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(Request);
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
        public void GivenIdRequestParameter_AndServiceAttendanceMatchesStudentAssignedOfferingId_WhenInvokeFilterPredicate_ThenReturnTrue()
        {
            ServiceAttendance attendance = new ServiceAttendance { StudentAssignedOfferingId = 1 };
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(attendance));
        }
        public void GivenISortByDuration_WhenSortSelector_ThenSortsByDuration()
        {
            PrepareDataTableRequestParameters("2", "asc");
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);
            string expected = TestData.ServiceAttendances[0].Duration.ToString();

            var actual = Target.SortSelector.Compile().Invoke(TestData.ServiceAttendances[0]);

            Assert.AreEqual(expected, actual);
        }
        public void GivenISortByDate_WhenSortSelector_ThenSortsByDate()
        {
            PrepareDataTableRequestParameters("0", "asc");
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);
            string expected = ((int)TimeSpan.FromTicks(TestData.ServiceAttendances[0].DateAttended.Ticks).TotalMinutes).ToString();

            var actual = Target.SortSelector.Compile().Invoke(TestData.ServiceAttendances[0]);

            Assert.AreEqual(expected, actual);
        }
        public void GivenSort_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();

            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();
            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);
            ServiceAttendance attendance = new ServiceAttendance
            {
                DateAttended = DateTime.Now.AddYears(100),
                StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(),
                Subject = EducationContext.Subjects.First(),
                CreatingUser = User.Identity.User
            };
            EducationContext.ServiceAttendances.Add(attendance);
            EducationContext.SaveChanges();

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();

            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);
            ServiceAttendance attendance = new ServiceAttendance
            {
                DateAttended            = DateTime.Now.AddYears(100),
                StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(),
                Subject      = EducationContext.Subjects.First(),
                CreatingUser = User.Identity.User
            };

            EducationContext.ServiceAttendances.Add(attendance);
            EducationContext.SaveChanges();

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void GivenServiceAttendance_WhenInvokeDataSelector_ThenPropertiesMatch()
        {
            ServiceAttendance expectedState = new ServiceAttendance
            {
                DateAttended = new DateTime(2003, 4, 5),
                Duration = 45,
                Id = 35,
                Notes = "blkah",
                Subject = new Subject { Name = "disojfw" }
            };
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);

            dynamic actual = Target.DataSelector.Compile().Invoke(expectedState);

            Assert.AreEqual(expectedState.DateAttended, actual.DateAttended);
            Assert.AreEqual(expectedState.Duration, actual.Duration);
            Assert.AreEqual(expectedState.Id, actual.Id);
            Assert.AreEqual(expectedState.Notes, actual.Notes);
            Assert.AreEqual(expectedState.Subject.Name, actual.Subject);
        }
 public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
 {
     ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(Request);
     var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);
     return Json(viewModel, JsonRequestBehavior.AllowGet);
 }
        public void GivenSort_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();
            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }