public void Arrange() { _now = new DateTime(2018, 3, 1); _currentDateTime = new Mock <ICurrentDateTime>(); _currentDateTime.Setup(x => x.Now).Returns(_now); _academicYearDateProvider = new Mock <IAcademicYearDateProvider>(); _academicYearDateProvider.Setup(x => x.CurrentAcademicYearStartDate).Returns(new DateTime(2017, 8, 1)); _validationApi = new Mock <IValidationApi>(); _validationApi.Setup(x => x.ValidateOverlapping(It.IsAny <ApprenticeshipOverlapValidationRequest>())) .ReturnsAsync(new ApprenticeshipOverlapValidationResult()); _hashingService = new Mock <IHashingService>(); _hashingService.Setup(x => x.DecodeValue(It.IsAny <string>())).Returns(123); _validator = new EditApprenticeshipStopDateViewModelValidator(_currentDateTime.Object, _academicYearDateProvider.Object, _validationApi.Object, _hashingService.Object); _viewModel = new EditApprenticeshipStopDateViewModel { ApprenticeshipName = "Test Apprenticeship", ApprenticeshipULN = "1234567890", ApprenticeshipStartDate = new DateTime(2017, 9, 1), CurrentStopDate = new DateTime(2018, 2, 1), AcademicYearRestriction = new DateTime(2017, 8, 1), NewStopDate = new DateTimeViewModel(new DateTime(2017, 9, 1)) }; }
public async Task ThenOrchestratorWillUpdateStopDate() { _owinWrapper.Setup(x => x.GetClaimValue(It.IsAny <string>())).Returns(string.Empty); _orchestrator.Setup(o => o.AuthorizeRole(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Role[]>())).Returns(() => Task.FromResult(true)); _orchestrator.Setup(o => o.GetEditApprenticeshipStopDateViewModel(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(new OrchestratorResponse <EditApprenticeshipStopDateViewModel>())); var response = new OrchestratorResponse <EditApprenticeshipStopDateViewModel> { Data = new EditApprenticeshipStopDateViewModel() }; _orchestrator.Setup(o => o.GetEditApprenticeshipStopDateViewModel(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(response)).Verifiable(); var model = new EditApprenticeshipStopDateViewModel(); await _controller.UpdateApprenticeshipStopDate(AccountId, ApprenticeshipId, model); _orchestrator.Verify(x => x.UpdateStopDate(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <EditApprenticeshipStopDateViewModel>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); }
public EditApprenticeshipStopDateViewModel MapToEditApprenticeshipStopDateViewModel(Apprenticeship apprenticeship) { var result = new EditApprenticeshipStopDateViewModel { ApprenticeshipULN = apprenticeship.ULN, ApprenticeshipName = apprenticeship.ApprenticeshipName, ApprenticeshipHashedId = _hashingService.HashValue(apprenticeship.Id), ApprenticeshipStartDate = apprenticeship.StartDate.Value, AcademicYearRestriction = _currentDateTime.Now > _academicYearDateProvider.LastAcademicYearFundingPeriod ? //if r14 grace period has past for last a.y. _academicYearDateProvider.CurrentAcademicYearStartDate : default(DateTime?), CurrentStopDate = apprenticeship.StopDate.Value, NewStopDate = new DateTimeViewModel() }; result.EarliestDate = result.AcademicYearRestriction.HasValue && result.AcademicYearRestriction.Value > result.ApprenticeshipStartDate ? result.AcademicYearRestriction.Value : result.ApprenticeshipStartDate; return(result); }
public async Task <ActionResult> UpdateApprenticeshipStopDate(string hashedAccountId, string hashedApprenticeshipId, [CustomizeValidator(RuleSet = "default,Date")] EditApprenticeshipStopDateViewModel model) { if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor)) { return(View("AccessDenied")); } var userId = OwinWrapper.GetClaimValue(@"sub"); if (ModelState.IsValid) { await _orchestrator.UpdateStopDate( hashedAccountId, hashedApprenticeshipId, model, userId, OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName), OwinWrapper.GetClaimValue(DasClaimTypes.Email)); SetOkayMessage("New stop date confirmed"); return(Redirect(_linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details"))); } var viewmodel = await _orchestrator.GetEditApprenticeshipStopDateViewModel(hashedAccountId, hashedApprenticeshipId, userId); viewmodel.Data.ApprenticeDetailsV2Link = _linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details"); return(View("editstopdate", new OrchestratorResponse <EditApprenticeshipStopDateViewModel> { Data = viewmodel.Data })); }
public async Task UpdateStopDate(string hashedAccountId, string hashedApprenticeshipId, EditApprenticeshipStopDateViewModel model, string externalUserId, string userName, string userEmail) { var accountId = HashingService.DecodeValue(hashedAccountId); var apprenticeshipId = HashingService.DecodeValue(hashedApprenticeshipId); Logger.Info($"Updating Apprenticeship stop date. AccountId: {accountId}, ApprenticeshipId: {apprenticeshipId}"); await CheckUserAuthorization(async() => { var data = await Mediator.SendAsync(new GetApprenticeshipQueryRequest { AccountId = accountId, ApprenticeshipId = apprenticeshipId }); await Mediator.SendAsync(new UpdateApprenticeshipStopDateCommand { UserId = externalUserId, ApprenticeshipId = apprenticeshipId, EmployerAccountId = accountId, NewStopDate = model.NewStopDate.DateTime.Value, UserEmailAddress = userEmail, UserDisplayName = userName, CommitmentId = data.Apprenticeship.CommitmentId }); }, hashedAccountId, externalUserId); }