public void Create_Get_AsksForCreateView() { LeaveScheduleController controller = GetNewLeaveScheduleController(null); ViewResult result = controller.Create() as ViewResult; Assert.AreEqual("Create", result.ViewName); }
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"]); }
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); }
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); }