public GetChangeEmployerPageFixture() { _providerId = 123; _apprenticeshipId = 345; _apprenticeshipHashedId = "DS23JF3"; _request = new ChangeEmployerRequest { ProviderId = _providerId, ApprenticeshipHashedId = _apprenticeshipHashedId, ApprenticeshipId = _apprenticeshipId }; _informViewModel = new InformViewModel { ProviderId = _providerId, ApprenticeshipHashedId = _apprenticeshipHashedId, ApprenticeshipId = _apprenticeshipId }; _changeEmployerRequestDetailsViewModel = new ChangeEmployerRequestDetailsViewModel(); _modelMapper = new Mock <IModelMapper>(); _modelMapper .Setup(x => x.Map <IChangeEmployerViewModel>(_request)) .ReturnsAsync(_informViewModel); ITempDataProvider tempDataProvider = Mock.Of <ITempDataProvider>(); TempDataDictionaryFactory tempDataDictionaryFactory = new TempDataDictionaryFactory(tempDataProvider); ITempDataDictionary tempData = tempDataDictionaryFactory.GetTempData(new DefaultHttpContext()); _sut = new ApprenticeController(_modelMapper.Object, Mock.Of <ICookieStorageService <IndexRequest> >(), Mock.Of <ICommitmentsApiClient>()) { TempData = tempData }; }
public void Validate_ProviderId_ShouldBeValidated(int providerId, bool expectedValid) { var model = new ChangeEmployerRequest { ProviderId = providerId }; AssertValidationResult(request => request.ProviderId, model, expectedValid); }
public void Validate_ApprenticeshipHashedId_ShouldBeValidated(string apprenticeshipHashedId, bool expectedValid) { var model = new ChangeEmployerRequest() { ApprenticeshipHashedId = apprenticeshipHashedId }; AssertValidationResult(request => request.ApprenticeshipHashedId, model, expectedValid); }
public async Task <IActionResult> ChangeEmployer(ChangeEmployerRequest request) { var viewModel = await _modelMapper.Map <IChangeEmployerViewModel>(request); TempData["ChangeEmployerModel"] = JsonConvert.SerializeObject(viewModel); return(RedirectToRoute(viewModel is InformViewModel ? RouteNames.ChangeEmployerInform : RouteNames.ChangeEmployerDetails)); }
public IChangeEmployerViewModelMapperTestsFixture() { AutoFixture = new Fixture(); ProviderId = 123; ApprenticeshipId = 234; ApprenticeshipHashedId = "SD23DS24"; EmployerName = AutoFixture.Create <string>(); StartDate = AutoFixture.Create <DateTime>(); EndDate = AutoFixture.Create <DateTime>(); Price = AutoFixture.Create <int>(); CohortReference = AutoFixture.Create <string>(); EncodedNewApprenticeshipId = AutoFixture.Create <string>(); _changeEmployerRequest = new ChangeEmployerRequest { ApprenticeshipId = ApprenticeshipId, ProviderId = ProviderId, ApprenticeshipHashedId = ApprenticeshipHashedId }; Apprenticeship = new GetApprenticeshipResponse { EmployerName = AutoFixture.Create <string>(), StartDate = AutoFixture.Create <DateTime>() }; PriceEpisodes = new GetPriceEpisodesResponse { PriceEpisodes = new List <GetPriceEpisodesResponse.PriceEpisode> { new GetPriceEpisodesResponse.PriceEpisode { FromDate = DateTime.MinValue, Cost = AutoFixture.Create <int>() } } }; ChangeOfPartyRequests = new GetChangeOfPartyRequestsResponse { ChangeOfPartyRequests = new List <GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest>() }; _commitmentsApiClient = new Mock <ICommitmentsApiClient>(); _commitmentsApiClient .Setup(x => x.GetChangeOfPartyRequests(It.Is <long>(a => a == ApprenticeshipId), It.IsAny <CancellationToken>())).ReturnsAsync(ChangeOfPartyRequests); _commitmentsApiClient.Setup(x => x.GetApprenticeship(It.Is <long>(a => a == ApprenticeshipId), It.IsAny <CancellationToken>())).ReturnsAsync(Apprenticeship); _commitmentsApiClient.Setup(x => x.GetPriceEpisodes(It.Is <long>(a => a == ApprenticeshipId), It.IsAny <CancellationToken>())).ReturnsAsync(PriceEpisodes); _encodingService = new Mock <IEncodingService>(); _encodingService.Setup(x => x.Encode(It.IsAny <long>(), EncodingType.CohortReference)) .Returns(CohortReference); _encodingService.Setup(x => x.Encode(It.IsAny <long>(), EncodingType.ApprenticeshipId)) .Returns(EncodedNewApprenticeshipId); _sut = new IChangeEmployerViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object); }
private void AssertValidationResult <T>(Expression <Func <ChangeEmployerRequest, T> > property, ChangeEmployerRequest instance, bool expectedValid) { var validator = new ApprenticeInformRequestValidator(); if (expectedValid) { validator.ShouldNotHaveValidationErrorFor(property, instance); } else { validator.ShouldHaveValidationErrorFor(property, instance); } }