Пример #1
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"]);
        }
Пример #2
0
        public async Task Edit_Get_ModelIsValid_AsksForEditView()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

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

            Assert.AreEqual("Edit", result.ViewName);
        }
Пример #3
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);
        }
Пример #4
0
        public async Task Edit_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.Edit(7)) as ViewResult;

            Assert.AreEqual("Error", result.ViewName);
        }
Пример #5
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]);
        }
Пример #6
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);
        }
Пример #7
0
        public async Task Edit_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.Edit(7)) as ViewResult;

            LeaveScheduleViewModel model = result.ViewData.Model as LeaveScheduleViewModel;

            Assert.AreEqual(7, model.Id);
            Assert.AreEqual(2018, model.Year);
        }