Exemple #1
0
        public async Task Index_SyncRequest_AsksForIndexView()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object);

            ViewResult result = (await controller.Index()) as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
Exemple #2
0
        public async Task Index_AsyncRequest_JsonRequestBehaviorEqualsAllowGet()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object, true);

            JsonResult result = (await controller.Index()) as JsonResult;

            Assert.AreEqual(JsonRequestBehavior.AllowGet, result.JsonRequestBehavior);
        }
Exemple #3
0
        public async Task Index_SyncRequest_RetrievesPageInfoPropertyFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.PageInfo).Returns(new PageInfo()
            {
                TotalItems = 9, PageSize = 3, PageNumber = 3
            });
            LeaveScheduleController controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object);

            ViewResult result = (await controller.Index()) as ViewResult;

            LeaveScheduleListViewModel model = result.ViewData.Model as LeaveScheduleListViewModel;

            Assert.AreEqual(9, model.PageInfo.TotalItems);
            Assert.AreEqual(3, model.PageInfo.PageSize);
            Assert.AreEqual(3, model.PageInfo.PageNumber);
            Assert.AreEqual(3, model.PageInfo.TotalPages);
        }
Exemple #4
0
        public async Task Index_SyncRequest_RetrievesLeaveSchedulesPropertyFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <LeaveScheduleDTO> >(), It.IsAny <int>())).Returns(new LeaveScheduleDTO[] {
                new LeaveScheduleDTO {
                    Id   = 7,
                    Year = 2018
                }
            });
            LeaveScheduleController controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object);

            ViewResult result = (await controller.Index()) as ViewResult;

            LeaveScheduleListViewModel model = result.ViewData.Model as LeaveScheduleListViewModel;

            Assert.AreEqual(1, model.LeaveSchedules.Count());
            Assert.AreEqual(7, model.LeaveSchedules.FirstOrDefault().Id);
            Assert.AreEqual(2018, model.LeaveSchedules.FirstOrDefault().Year);
        }
Exemple #5
0
        public async Task Index_AsyncRequest_RetrievesLeaveSchedulesPropertyFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <LeaveScheduleDTO> >(), It.IsAny <int>())).Returns(new LeaveScheduleDTO[] {
                new LeaveScheduleDTO {
                    Id   = 7,
                    Year = 2018
                }
            });
            LeaveScheduleController controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object, true);

            JsonResult result        = (await controller.Index()) as JsonResult;
            object     LeaveSchedule = (result.Data.GetType().GetProperty("LeaveSchedules").GetValue(result.Data) as object[])[0];
            int        id            = (int)LeaveSchedule.GetType().GetProperty("Id").GetValue(LeaveSchedule);
            int        year          = (int)LeaveSchedule.GetType().GetProperty("Year").GetValue(LeaveSchedule);

            Assert.AreEqual(7, id);
            Assert.AreEqual(2018, year);
        }