public async Task Create_Post_ModelIsInvalid_SetViewBagEmployees() { Mock <BusinessTripService> bmock = new Mock <BusinessTripService>(); bmock.Setup(m => m.CreateAsync(It.IsAny <BusinessTripDTO>())).Throws(new ValidationException("", "")); Mock <EmployeeService> emock = new Mock <EmployeeService>(); emock.Setup(m => m.GetAllAsync()).ReturnsAsync(new EmployeeDTO[] { new EmployeeDTO() { Id = 2, LastName = "Петров", FirstName = "Петр", Patronymic = "Петрович", Post = new PostDTO { Department = new DepartmentDTO { DepartmentName = "IT" } } } }); BusinessTripController controller = GetNewBusinessTripController(bmock.Object, emock.Object); ViewResult result = (await controller.Create(null)) as ViewResult; SelectListItem item = (result.ViewBag.Employees as SelectList).FirstOrDefault(); Assert.AreEqual("Петров Петр Петрович [IT]", item.Text); Assert.AreEqual("2", item.Value); }
public async Task Create_Post_ModelIsValid_RedirectToIndex() { Mock <BusinessTripService> mock = new Mock <BusinessTripService>(); BusinessTripController controller = GetNewBusinessTripController(mock.Object, null); RedirectToRouteResult result = (await controller.Create(null)) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }
public async Task Create_Get_NoEmployees_AsksForErrorView() { Mock <EmployeeService> mock = new Mock <EmployeeService>(); mock.Setup(m => m.CountAsync()).ReturnsAsync(0); BusinessTripController controller = GetNewBusinessTripController(null, mock.Object); ViewResult result = (await controller.Create()) as ViewResult; Assert.AreEqual("Error", result.ViewName); }
public async Task Create_Post_ModelIsInvalid_AsksForCreateView() { Mock <BusinessTripService> bmock = new Mock <BusinessTripService>(); bmock.Setup(m => m.CreateAsync(It.IsAny <BusinessTripDTO>())).Throws(new ValidationException("", "")); Mock <EmployeeService> emock = new Mock <EmployeeService>(); BusinessTripController controller = GetNewBusinessTripController(bmock.Object, emock.Object); ViewResult result = (await controller.Create(null)) as ViewResult; Assert.AreEqual("Create", result.ViewName); }
public async Task Create_Post_ModelIsInvalid_RetrievesBusinessTripFromModel() { Mock <BusinessTripService> bmock = new Mock <BusinessTripService>(); bmock.Setup(m => m.CreateAsync(It.IsAny <BusinessTripDTO>())).Throws(new ValidationException("", "")); Mock <EmployeeService> emock = new Mock <EmployeeService>(); BusinessTripController controller = GetNewBusinessTripController(bmock.Object, emock.Object); ViewResult result = (await controller.Create(new BusinessTripViewModel { Id = 2, Name = "02.09.2018_026" })) as ViewResult; BusinessTripViewModel model = result.ViewData.Model as BusinessTripViewModel; Assert.AreEqual(2, model.Id); Assert.AreEqual("02.09.2018_026", model.Name); }
public async Task Create_Get_ExistsEmployees_SetViewBagEmployees() { Mock <EmployeeService> mock = new Mock <EmployeeService>(); mock.Setup(m => m.CountAsync()).ReturnsAsync(1); mock.Setup(m => m.GetAllAsync()).ReturnsAsync(new EmployeeDTO[] { new EmployeeDTO() { Id = 2, LastName = "Петров", FirstName = "Петр", Patronymic = "Петрович", Post = new PostDTO { Department = new DepartmentDTO { DepartmentName = "IT" } } } }); BusinessTripController controller = GetNewBusinessTripController(null, mock.Object); ViewResult result = (await controller.Create()) as ViewResult; SelectListItem item = (result.ViewBag.Employees as SelectList).FirstOrDefault(); Assert.AreEqual("Петров Петр Петрович [IT]", item.Text); Assert.AreEqual("2", item.Value); }