示例#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 Create_Post_ModelIsValid_RedirectToIndex()
        {
            Mock <LeaveScheduleService> mock       = new Mock <LeaveScheduleService>();
            LeaveScheduleController     controller = GetNewLeaveScheduleController(mock.Object);

            RedirectToRouteResult result = (await controller.Create(null)) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
示例#3
0
        public async Task Create_Post_ModelIsInvalid_AsksForCreateView()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

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

            ViewResult result = (await controller.Create(null)) as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
示例#4
0
        public async Task Create_Post_ModelIsInvalid_RetrievesLeaveScheduleFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

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

            ViewResult result = (await controller.Create(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);
        }