public void StepTwoPostAction_ReturnsRedirectToAction() { var mockDataAccessor = new Mock <IVacationPlannerDataAccessor>(); var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); var httpCtx = new Mock <IHttpContextAccessor>(); mockDataAccessor.Setup(m => m.Locations).Returns(new Mock <IRepository <Location> >().Object); mockDataAccessor.Setup(m => m.Accommodations).Returns(new Mock <IRepository <Accommodation> >().Object); mockDataAccessor.Setup(m => m.Activities).Returns(new Mock <IRepository <Activity> >().Object); mockDataAccessor.Setup(m => m.Vacations).Returns(new Mock <IRepository <Vacation> >().Object); mockDataAccessor.Setup(m => m.Locations.Get(It.IsAny <int>())).Returns(new Location()); var controller = new VacationController(mockDataAccessor.Object, httpCtx.Object) { TempData = tempData }; var result = controller.StepTwo(new VacationStepTwoViewModel() { Vacation = new Vacation() { Location = new Location() }, Activities = new List <Activity>() }); Assert.IsType <RedirectToActionResult>(result); }
public void AddTrip_ReturnsRedirectToAction() { var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var tempData = new TempDataDictionary(httpContextAccessor.Object.HttpContext, Mock.Of <ITempDataProvider>()); var controller = new VacationController(unitOfWork.Object, httpContextAccessor.Object); controller.TempData = tempData; var trip = new Trip { Id = 1, DestinationId = 6, AccommodationId = 4, StartDate = new DateTime(2020, 12, 20), EndDate = new DateTime(2021, 1, 2) }; controller.TempData["trip_dest"] = trip.DestinationId; controller.TempData["trip_acc"] = trip.AccommodationId; controller.TempData["trip_start"] = trip.StartDate; controller.TempData["trip_end"] = trip.EndDate; var result = controller.AddTrip(new[] { 1, 2 }) as RedirectToActionResult; Assert.IsType <RedirectToActionResult>(result); }
public void PostDeleteVacationNotNullEmployeeUnpaidVacation_true() { //Arrange VacationController controller = new VacationController(mock.Object); DateTime fromDate = DateTime.ParseExact("12.03.2014", "dd.MM.yyyy", null); DateTime toDate = DateTime.ParseExact("28.03.2014", "dd.MM.yyyy", null); Vacation vacation = (from vac in mock.Object.Vacations where vac.EmployeeID == 2 && vac.Type == VacationType.UnpaidVacation && vac.From == fromDate && vac.To == toDate select vac).FirstOrDefault(); //Act int id = 2; string type = "UnpaidVacation"; bool result = controller.Delete(id, "12.03.2014", "28.03.2014", type); //Assert Assert.IsTrue(result); mock.Verify(m => m.DeleteVacation(vacation.VacationID), Times.Once); }
public async Task VacationIndex() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); ViewResult result = await controller.Index() as ViewResult; IEnumerable <VacationDto> model = result.Model as IEnumerable <VacationDto>; Assert.IsNotNull(model); }
public async Task VacationDetails() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); ViewResult result = await controller.Details(1) as ViewResult; VacationDto model = result.Model as VacationDto; Assert.IsTrue(model.EmployeeID == 1); }
public async Task VacationEdit() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto model = await EditVacation(controller); model.DateTo = model.DateTo.Value.AddDays(1); ActionResult result = await controller.Edit(model); Assert.IsTrue(result is RedirectToRouteResult); }
public void AddTripStep1_ReturnsViewResult() { var accessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var controller = new VacationController(unitOfWork.Object, accessor.Object); var result = controller.AddTripStep1() as ViewResult; Assert.IsType <ViewResult>(result); }
public async Task VacationEditMergeAndDelete() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto model = await EditVacation(controller, 4); model.EmployeeFirstName = "First1"; model.EmployeeLastName = "Last1"; ActionResult result = await controller.Edit(model); Assert.IsTrue(result is RedirectToRouteResult); }
public async Task VacationDelete() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); ViewResult getResult = await controller.Delete(3) as ViewResult; VacationDto model = getResult.Model as VacationDto; ActionResult postResult = await controller.Delete(model); Assert.IsTrue(postResult is RedirectToRouteResult); }
public void PageSize_ReturnsRedirectToActionResult() { var accessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var controller = new VacationController(unitOfWork.Object, accessor.Object); var result = controller.PageSize(1) as RedirectToActionResult; Assert.IsType <RedirectToActionResult>(result); }
public void PostCalculateOverralDays_BadDatesFormat_0() { //Arrange VacationController controller = new VacationController(mock.Object); string fromDate = "123.456.444"; string toDate = "12.34.111"; //Act var result = controller.CalculateOverralDays(fromDate, toDate); //Assert Assert.AreEqual(0, result); }
public void PostCalculateOverralDays_CorrectDates_DifferenceBetweenEndDateAndStartDate() { //Arrange VacationController controller = new VacationController(mock.Object); string fromDate = "01.03.2014"; string toDate = "15.03.2014"; //Act var result = controller.CalculateOverralDays(fromDate, toDate); //Assert Assert.AreEqual(15, result); }
public void PostCalculateOverralDays_EndDateLessThanStartDate_0() { //Arrange VacationController controller = new VacationController(mock.Object); string fromDate = "15.03.2014"; string toDate = "01.03.2014"; //Act var result = controller.CalculateOverralDays(fromDate, toDate); //Assert Assert.AreEqual(0, result); }
public void PostCalculateVacation_CorrectDatesWithHolidays_2() { //Arrange VacationController controller = new VacationController(mock.Object); string fromDate = "30.04.2014"; string toDate = "05.05.2014"; //Act var result = controller.CalculateVacation(fromDate, toDate); //Arrange Assert.AreEqual(2, result); }
public void DeleteTrip_Delete1_ReturnsRedirectToActionResult() { var accessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var tempData = new TempDataDictionary(accessor.Object.HttpContext, Mock.Of <ITempDataProvider>()); var controller = new VacationController(unitOfWork.Object, accessor.Object); controller.TempData = tempData; var result = controller.DeleteTrip(1) as RedirectToActionResult; Assert.IsType <RedirectToActionResult>(result); }
public async Task VacationEditTestDateConstraint() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto model = await EditVacation(controller); DateTime?dateFrom = model.DateFrom; model.DateFrom = model.DateTo; model.DateTo = dateFrom; ViewResult result = await controller.Edit(model) as ViewResult; Assert.IsNotNull(result); Assert.IsFalse(controller.ModelState.IsValid); }
public async Task VacationEditTestDateTrigger() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto model1 = await EditVacation(controller); VacationDto model2 = await EditVacation(controller, 2); Assert.IsTrue(model1.EmployeeID == model2.EmployeeID); model2.DateFrom = model1.DateFrom; ViewResult result = await controller.Edit(model2) as ViewResult; Assert.IsNotNull(result); Assert.IsFalse(controller.ModelState.IsValid); }
public void StepTwoAction_ReturnsRedirectToAction() { var mockDataAccessor = new Mock <IVacationPlannerDataAccessor>(); var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); var httpCtx = new Mock <IHttpContextAccessor>(); var controller = new VacationController(mockDataAccessor.Object, httpCtx.Object) { TempData = tempData }; var result = controller.StepTwo(); Assert.IsType <RedirectToActionResult>(result); }
public async Task VacationCreateForExistingEmployee() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto dto = new VacationDto { EmployeeFirstName = "First1", EmployeeLastName = "Last1", DateFrom = new DateTime(2018, 6, 4), DateTo = new DateTime(2018, 6, 7), VacationType = VacationTypeKind.VacationLeave, }; ActionResult result = await controller.Create(dto); Assert.IsTrue(result is RedirectToRouteResult); }
public async Task VacationEditTestConcurrency() { VacationController controller = DependencyResolver.Current.GetService <VacationController>(); VacationDto model = await EditVacation(controller); model.DateTo = model.DateTo.Value.AddDays(1); ActionResult result1 = await controller.Edit(model); Assert.IsTrue(result1 is RedirectToRouteResult); ViewResult result2 = await controller.Edit(model) as ViewResult; Assert.IsNotNull(result2); Assert.IsFalse(controller.ModelState.IsValid); }
public void PostCreateVacationNotNullEmployeePaidVacation_true() { //Arrange VacationController controller = new VacationController(mock.Object); //Act int id = 1; string fromDate = "01.01.2014"; string toDate = "15.01.2014"; string type = "Paid Vacation"; bool result = controller.Create(id, fromDate, toDate, type); //Assert Assert.IsTrue(result); }
public void PostCreateVacationNotNullEmployeeBadTypeCorrectDate_false() { //Arrange VacationController controller = new VacationController(mock.Object); //Act int id = 1; string fromDate = "01.01.2014"; string toDate = "15.01.2014"; string type = "Bad Type"; bool result = controller.Create(id, fromDate, toDate, type); //Assert Assert.IsFalse(result); }
public void PostDeleteVacationNotNullEmployeeBadTypeBadDate_false() { //Arrange VacationController controller = new VacationController(mock.Object); //Act int id = 1; string fromDate = ""; string toDate = ""; string type = "Bad Type"; bool result = controller.Delete(id, fromDate, toDate, type); //Assert Assert.IsFalse(result); mock.Verify(m => m.DeleteVacation(0), Times.Never); }
public void PostEditVacationNotNullEmployeeUnpaidVacation_true() { //Arrange VacationController controller = new VacationController(mock.Object); //Act int id = 6; string oldFrom = "12.07.2014"; string oldTo = "28.07.2014"; string newFrom = "15.09.2014"; string newTo = "30.09.2014"; string type = "UnpaidVacation"; bool result = controller.Edit(id, oldFrom, oldTo, newFrom, newTo, type); //Assert Assert.IsTrue(result); }
public void AddTripStep2_ModelStateInValid_ReturnsViewResult() { var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var controller = new VacationController(unitOfWork.Object, httpContextAccessor.Object); controller.ModelState.AddModelError("error", "error"); var trip = new Trip { Id = 1, DestinationId = 6, AccommodationId = 4, StartDate = new DateTime(2020, 12, 20), EndDate = new DateTime(2021, 1, 2) }; var result = controller.AddTripStep2(trip) as ViewResult; Assert.IsType <ViewResult>(result); }
public void DeleteFromManage_ContainsAcc_ContainsDest_ReturnsRedirectToAction() { var accessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var tempData = new TempDataDictionary(accessor.Object.HttpContext, Mock.Of <ITempDataProvider>()); var controller = new VacationController(unitOfWork.Object, accessor.Object); controller.TempData = tempData; var viewmodel = new ManageViewModel { SelectedAccommodationToDelete = 1, SelectedActivityToDelete = 0, SelectedDestinationToDelete = 1 }; var result = controller.DeleteFromManage(viewmodel) as RedirectToActionResult; Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Manage", result.ActionName); }
public void PostEditVacationNotNullEmployeeBadTypeCorrectDate_false() { //Arrange VacationController controller = new VacationController(mock.Object); //Act int id = 1; string oldfrom = "01.01.2014"; string oldTo = "15.01.2014"; string newFrom = "01.02.2014"; string newTo = "15.02.2014"; string type = "Bad Type"; bool result = controller.Edit(id, oldfrom, oldTo, newFrom, newTo, type); //Assert Assert.IsFalse(result); }
public void Manage_ReturnsViewWithNullValues() { var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); var tempData = new TempDataDictionary(httpContextAccessor.Object.HttpContext, Mock.Of <ITempDataProvider>()); var controller = new VacationController(unitOfWork.Object, httpContextAccessor.Object); controller.TempData = tempData; var result = controller.Manage() as ViewResult; Assert.IsType <ViewResult>(result); var model = result.Model as ManageViewModel; Assert.Equal("", model.AccommodationPhone); Assert.Equal("", model.AccommodationEmail); Assert.Equal("", model.AccommodationName); Assert.Equal("", model.ActivityName); Assert.Equal("", model.DestinationName); }
public void SortIsAscending_ByStartDate_ReturnsHomeView() { var accessor = TestHelperLibrary.SetUpHttpContextAccessor(); var unitOfWork = TestHelperLibrary.SetupUnitOfWork(); accessor.Object.HttpContext.Session.SetInt32("page_size", 3); var controller = new VacationController(unitOfWork.Object, accessor.Object); controller.Sort(SortType.SortByStartDate); var result = controller.Home() as ViewResult; var viewModel = result.Model as VacationListViewModel; Assert.Equal(3, viewModel.Trips[0].Id); Assert.Equal(2, viewModel.Trips[1].Id); Assert.Equal(1, viewModel.Trips[2].Id); Assert.IsType <ViewResult>(result); }
public void PostCreateVacationNotNullEmployeeUnpaidVacation_true() { //Arrange VacationController controller = new VacationController(mock.Object); Vacation vacation = new Vacation { EmployeeID = 1, From = new DateTime(2014, 02, 10), To = new DateTime(2014, 02, 15), Type = VacationType.UnpaidVacation }; //Act int id = 1; string fromDate = "10.02.2014"; string toDate = "15.02.2014"; string type = "Unpaid Vacation"; bool result = controller.Create(id, fromDate, toDate, type); //Assert Assert.IsTrue(result); }