コード例 #1
0
        public void Create_Get_AsksForCreateView()
        {
            LeaveScheduleController controller = GetNewLeaveScheduleController(null);

            ViewResult result = controller.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
コード例 #2
0
        public async Task DeleteAllConfirmed_Post_RedirectToIndex()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

            RedirectToRouteResult result = (await controller.DeleteAllConfirmed()) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #3
0
        public void DeleteAll_Get_AsksForDeleteAllView()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = controller.DeleteAll() as ViewResult;

            Assert.AreEqual("DeleteAll", result.ViewName);
        }
コード例 #4
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);
        }
コード例 #5
0
        public async Task Delete_Get_ModelIsValid_AsksForDeleteView()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Delete(7)) as ViewResult;

            Assert.AreEqual("Delete", result.ViewName);
        }
コード例 #6
0
        public async Task Edit_Post_ModelIsValid_RedirectToIndex()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

            RedirectToRouteResult result = (await controller.Edit(new LeaveScheduleViewModel())) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #7
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);
        }
コード例 #8
0
        public async Task DeleteConfirmed_Post_DeleteAsyncMethodThrowsException_AsksForErrorView()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.DeleteAsync(It.IsAny <int>())).Throws(new ValidationException("DeleteAsync method throws Exception", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.DeleteConfirmed(7)) as ViewResult;

            Assert.AreEqual("Error", result.ViewName);
        }
コード例 #9
0
        public async Task Delete_Get_ModelIsInvalid_AsksForErrorView()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.FindByIdAsync(It.IsAny <int?>())).Throws(new ValidationException("FindByIdAsync method throws Exception", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Delete(1)) as ViewResult;

            Assert.AreEqual("Error", result.ViewName);
        }
コード例 #10
0
        public async Task Edit_Post_ModelIsInvalid_AsksForEditView()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.EditAsync(It.IsAny <LeaveScheduleDTO>())).Throws(new ValidationException("", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Edit(new LeaveScheduleViewModel())) as ViewResult;

            Assert.AreEqual("Edit", result.ViewName);
        }
コード例 #11
0
        public async Task ExportJson_RedirectToIndex()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleControllerWithControllerContext(mock.Object);

            FilePathResult result = (await controller.ExportJson()) as FilePathResult;

            Assert.AreEqual("application/json", result.ContentType);
            Assert.AreEqual("LeaveSchedules.json", result.FileDownloadName);
            Assert.AreEqual("./DiplomMSSQLApp.WEB/Results/LeaveSchedules.json", result.FileName);
        }
コード例 #12
0
        public async Task DeleteConfirmed_Post_DeleteAsyncMethodThrowsException_RetrievesExceptionMessageFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.DeleteAsync(It.IsAny <int>())).Throws(new ValidationException("DeleteAsync method throws Exception", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.DeleteConfirmed(7)) as ViewResult;

            string[] model = result.ViewData.Model as string[];
            Assert.AreEqual("DeleteAsync method throws Exception", model[0]);
        }
コード例 #13
0
        public async Task Edit_Get_ModelIsInvalid_RetrievesExceptionMessageFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.FindByIdAsync(It.IsAny <int?>())).Throws(new ValidationException("FindByIdAsync method throws Exception", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Edit(1)) as ViewResult;

            string[] model = result.ViewData.Model as string[];
            Assert.AreEqual("FindByIdAsync method throws Exception", model[0]);
        }
コード例 #14
0
        public async Task Edit_Post_ModelIsInvalid_RetrievesLeaveScheduleFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.EditAsync(It.IsAny <LeaveScheduleDTO>())).Throws(new ValidationException("", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Edit(new LeaveScheduleViewModel {
                Id = 7,
                Year = 2018
            })) as ViewResult;

            LeaveScheduleViewModel model = result.ViewData.Model as LeaveScheduleViewModel;

            Assert.AreEqual(7, model.Id);
            Assert.AreEqual(2018, model.Year);
        }
コード例 #15
0
        public async Task Delete_Get_ModelIsValid_RetrievesLeaveScheduleFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.FindByIdAsync(It.IsAny <int?>())).ReturnsAsync((int?_id) => new LeaveScheduleDTO {
                Id   = _id.Value,
                Year = 2018
            });
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Delete(7)) as ViewResult;

            LeaveScheduleViewModel model = result.ViewData.Model as LeaveScheduleViewModel;

            Assert.AreEqual(7, model.Id);
            Assert.AreEqual(2018, model.Year);
        }
コード例 #16
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);
        }
コード例 #17
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);
        }
コード例 #18
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);
        }