public void WhenStopDateIsBeforeStartDate_ThenValidationFails(int?month, int?year)
        {
            var model = new StopRequestViewModel {
                StopMonth = month, StopYear = year, StartDate = _startDate
            };

            AssertValidationResult(x => x.StopDate, model, false, StopDateBeforeStartDateError);
        }
        public void WhenStopDateIsEqualToStartDate_ThenValidates(int?month, int?year)
        {
            var model = new StopRequestViewModel {
                StopMonth = month, StopYear = year, StartDate = _startDate
            };

            AssertValidationResult(x => x.StopDate, model, true);
        }
        public void WhenInvalidMonthOrYearIsEntered_ThenValidationFails(int month, int year)
        {
            var model = new StopRequestViewModel {
                StopMonth = month, StopYear = year
            };

            AssertValidationResult(x => x.StopDate, model, false, NotARealDateError);
        }
        public void WhenYearIsEnteredButMonthIsNot_ThenValidationFails()
        {
            var model = new StopRequestViewModel {
                StopMonth = null, StopYear = 2021
            };

            AssertValidationResult(x => x.StopDate, model, false, MonthNotEnteredError);
        }
        public void WhenNeitherMonthOrYearAreEntered_ThenValidationFails()
        {
            var model = new StopRequestViewModel {
                StopMonth = null, StopYear = null
            };

            AssertValidationResult(x => x.StopDate, model, false, NoDateEnteredError);
        }
        public void WhenStopDateIsInFuture_ThenValidationFails()
        {
            var futureStopDate = DateTime.Now.AddMonths(1);
            var model          = new StopRequestViewModel {
                StopMonth = futureStopDate.Month, StopYear = futureStopDate.Year
            };

            AssertValidationResult(x => x.StopDate, model, false, StopDateIsInFutureError);
        }
        public void AndStopDateIsEntered_ThenRedirectToHasApprenticeBeenMadeRedundantPage()
        {
            StopRequestViewModel viewModel = GetStopRequestViewModel();
            var result = _controller.StopApprenticeship(viewModel);

            var redirect = result.VerifyReturnsRedirectToActionResult();

            Assert.AreEqual(redirect.ActionName, "HasTheApprenticeBeenMadeRedundant");
            Assert.AreEqual(redirect.RouteValues["AccountHashedId"], viewModel.AccountHashedId);
            Assert.AreEqual(redirect.RouteValues["ApprenticeshipHashedId"], viewModel.ApprenticeshipHashedId);
            Assert.AreEqual(redirect.RouteValues["StopMonth"], viewModel.StopMonth);
            Assert.AreEqual(redirect.RouteValues["StopYear"], viewModel.StopYear);
            Assert.AreEqual(redirect.RouteValues["IsCoPJourney"], viewModel.IsCoPJourney);
        }
        public async Task WhenRequesting_WhenDidThisApprenticeshipStop_ThenStopRequestViewModelIsPassedToTheView()
        {
            StopRequestViewModel _viewModel = new StopRequestViewModel {
                StopMonth = 6, StopYear = 2020, ApprenticeshipId = 1, AccountHashedId = "AAXX"
            };

            _mockModelMapper.Setup(m => m.Map <StopRequestViewModel>(It.IsAny <StopRequest>()))
            .ReturnsAsync(_viewModel);

            var viewResult = await _controller.StopApprenticeship(new StopRequest()) as ViewResult;

            var viewModel = viewResult.Model;

            var stopRequestViewModel = (StopRequestViewModel)viewModel;

            Assert.IsInstanceOf <StopRequestViewModel>(viewModel);
            Assert.AreEqual(_viewModel, stopRequestViewModel);
        }
        private void AssertValidationResult <T>(Expression <Func <StopRequestViewModel, T> > property, StopRequestViewModel instance, bool expectedValid, string expectedErrorMessage = null)
        {
            var validator = new StopRequestViewModelValidator();

            if (expectedValid)
            {
                validator.ShouldNotHaveValidationErrorFor(property, instance);
            }
            else
            {
                validator.ShouldHaveValidationErrorFor(property, instance).WithErrorMessage(expectedErrorMessage);
            }
        }
示例#10
0
 public IActionResult StopApprenticeship(StopRequestViewModel viewModel)
 {
     return(RedirectToAction(nameof(HasTheApprenticeBeenMadeRedundant), new { viewModel.AccountHashedId, viewModel.ApprenticeshipHashedId, viewModel.IsCoPJourney, viewModel.StopMonth, viewModel.StopYear }));
 }
示例#11
0
        private void AssertValidationResult <T>(Expression <Func <StopRequestViewModel, T> > property, StopRequestViewModel instance, bool expectedValid, string expectedErrorMessage = null)
        {
            var currentDateMock = new Mock <ICurrentDateTime>();

            currentDateMock.Setup(x => x.UtcNow).Returns(DateTime.UtcNow);
            var validator = new StopRequestViewModelValidator(currentDateMock.Object);

            if (expectedValid)
            {
                validator.ShouldNotHaveValidationErrorFor(property, instance);
            }
            else
            {
                validator.ShouldHaveValidationErrorFor(property, instance).WithErrorMessage(expectedErrorMessage);
            }
        }