public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLevy() { _source.TransferSenderId = "test"; _result = await _mapper.Map(TestHelper.Clone(_source)); _result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes); }
public void Arrange() { var fixture = new Fixture(); var birthDate = fixture.Create <DateTime?>(); var startDate = fixture.Create <DateTime?>(); var endDate = fixture.Create <DateTime?>(); _cohortId = fixture.Create <long>(); _mapper = new AddDraftApprenticeshipRequestMapper(); _source = fixture.Build <AddDraftApprenticeshipViewModel>() .With(x => x.CohortId, _cohortId) .With(x => x.BirthDay, birthDate?.Day) .With(x => x.BirthMonth, birthDate?.Month) .With(x => x.BirthYear, birthDate?.Year) .With(x => x.EndMonth, endDate?.Month) .With(x => x.EndYear, endDate?.Year) .With(x => x.StartMonth, startDate?.Month) .With(x => x.StartYear, startDate?.Year) .Without(x => x.StartDate) .Without(x => x.Courses) .Create(); _act = async() => await _mapper.Map(TestHelper.Clone(_source)); }
public void Arrange() { var fixture = new Fixture(); _accountLegalEntityId = fixture.Create <long>(); _accountLegalEntityResponse = fixture.Create <AccountLegalEntityResponse>(); _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>(); _mockCommitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_accountLegalEntityId, It.IsAny <CancellationToken>())) .ReturnsAsync(_accountLegalEntityResponse); var birthDate = fixture.Create <DateTime?>(); var startDate = fixture.Create <DateTime?>(); var endDate = fixture.Create <DateTime?>(); var accountLegalEntityPublicHashedId = fixture.Create <string>(); _mapper = new CreateCohortRequestMapper(_mockCommitmentsApiClient.Object); _source = fixture.Build <AddDraftApprenticeshipViewModel>() .With(x => x.EmployerAccountLegalEntityPublicHashedId, accountLegalEntityPublicHashedId) .With(x => x.AccountLegalEntityId, _accountLegalEntityId) .With(x => x.BirthDay, birthDate?.Day) .With(x => x.BirthMonth, birthDate?.Month) .With(x => x.BirthYear, birthDate?.Year) .With(x => x.EndMonth, endDate?.Month) .With(x => x.EndYear, endDate?.Year) .With(x => x.StartMonth, startDate?.Month) .With(x => x.StartYear, startDate?.Year) .Without(x => x.StartDate) .Without(x => x.Courses) .Create(); _act = () => _mapper.Map(TestHelper.Clone(_source)); }
public void Validate_FinishDate_ShouldBeValidated(int?month, int?year, bool expectedValid) { var model = new AddDraftApprenticeshipViewModel { EndMonth = month, EndYear = year }; AssertValidationResult(request => request.EndDate, model, expectedValid); }
public void Validate_DoB_ShouldBeValidated(int?day, int?month, int?year, bool expectedValid) { var model = new AddDraftApprenticeshipViewModel { BirthDay = day, BirthMonth = month, BirthYear = year }; AssertValidationResult(request => request.DateOfBirth, model, expectedValid); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var addDraftApprenticeshipRequest = await _modelMapper.Map <CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(model); await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, addDraftApprenticeshipRequest); return(RedirectToAction("Details", "Cohort", new { model.AccountHashedId, model.CohortReference })); }
public WhenGettingACohortWithDraftApprenticeFixture() { _request = new CreateCohortWithDraftApprenticeshipRequest(); _viewModel = new AddDraftApprenticeshipViewModel(); _modelMapper = new Mock <IModelMapper>(); _modelMapper.Setup(x => x.Map <AddDraftApprenticeshipViewModel>(_request)).ReturnsAsync(_viewModel); Sut = new CohortController(Mock.Of <IMediator>(), _modelMapper.Object, Mock.Of <ILinkGenerator>(), Mock.Of <ICommitmentsApiClient>()); }
public async Task CoursesAreMappedCorrectlyWithoutLevy(long?transferSenderId) { _cohort.LevyStatus = ApprenticeshipEmployerType.NonLevy; _cohort.TransferSenderId = transferSenderId; _result = await _mapper.Map(_source); Assert.AreEqual(_standardTrainingProgrammes, _result.Courses); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var addDraftApprenticeshipRequest = await _modelMapper.Map <CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(model); var response = await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, addDraftApprenticeshipRequest); var draftApprenticeshipHashedId = _encodingService.Encode(response.DraftApprenticeshipId, EncodingType.ApprenticeshipId); return(RedirectToAction("SelectOption", "DraftApprenticeship", new { model.AccountHashedId, model.CohortReference, draftApprenticeshipHashedId })); }
public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStatus(string transferSenderId) { _source.TransferSenderId = transferSenderId; _accountLegalEntityResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy; _result = await _mapper.Map(TestHelper.Clone(_source)); _result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var request = await _modelMapper.Map <CreateCohortRequest>(model); var response = await _mediator.Send(request); var cohortDetailsUrl = $"{model.ProviderId}/apprentices/{response.CohortReference}/Details"; var url = _urlHelper.ProviderApprenticeshipServiceLink(cohortDetailsUrl); return(Redirect(url)); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var request = await _modelMapper.Map <AddDraftApprenticeshipRequest>(model); request.UserId = User.Upn(); await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, request); var cohortDetailsUrl = $"{model.ProviderId}/apprentices/{model.CohortReference}/Details"; var url = _urlHelper.ProviderApprenticeshipServiceLink(cohortDetailsUrl); return(Redirect(url)); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var request = await _modelMapper.Map <CreateCohortRequest>(model); var response = await _mediator.Send(request); if (response.DraftApprenticeshipId.HasValue) { var draftApprenticeshipHashedId = _encodingService.Encode(response.DraftApprenticeshipId.Value, EncodingType.ApprenticeshipId); return(RedirectToAction("SelectOptions", "DraftApprenticeship", new { model.ProviderId, DraftApprenticeshipHashedId = draftApprenticeshipHashedId, response.CohortReference })); } return(RedirectToAction(nameof(Details), new { model.ProviderId, response.CohortReference })); }
public async Task <IActionResult> AddDraftApprenticeship(ReservationsAddDraftApprenticeshipRequest request) { var model = new AddDraftApprenticeshipViewModel { ProviderId = request.ProviderId, CohortReference = request.CohortReference, CohortId = request.CohortId, StartDate = new MonthYearModel(request.StartMonthYear), ReservationId = request.ReservationId, CourseCode = request.CourseCode }; await AddLegalEntityAndCoursesToModel(model); return(View(model)); }
public UnapprovedControllerTestFixture() { _autoFixture = new Fixture(); _draftApprenticeshipHashedId = _autoFixture.Create <string>(); _mediator = new Mock <IMediator>(); _mockModelMapper = new Mock <IModelMapper>(); _linkGenerator = new Mock <ILinkGenerator>(); _encodingService = new Mock <IEncodingService>(); _model = new AddDraftApprenticeshipViewModel { ProviderId = _autoFixture.Create <int>(), EmployerAccountLegalEntityPublicHashedId = _autoFixture.Create <string>(), AccountLegalEntityId = _autoFixture.Create <long>(), ReservationId = _autoFixture.Create <Guid>() }; _createCohortRequest = new CreateCohortRequest(); _mockModelMapper .Setup(x => x.Map <CreateCohortRequest>(It.IsAny <AddDraftApprenticeshipViewModel>())) .ReturnsAsync(_createCohortRequest); _createCohortResponse = new CreateCohortResponse { CohortId = _autoFixture.Create <long>(), CohortReference = _autoFixture.Create <string>(), DraftApprenticeshipId = null }; _mediator.Setup(x => x.Send(It.IsAny <CreateCohortRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_createCohortResponse); _linkGeneratorRedirectUrl = _autoFixture.Create <string>(); _linkGenerator.Setup(x => x.ProviderApprenticeshipServiceLink(It.IsAny <string>())) .Returns(_linkGeneratorRedirectUrl) .Callback((string value) => _linkGeneratorParameter = value); _controller = new CohortController(_mediator.Object, _mockModelMapper.Object, _linkGenerator.Object, Mock.Of <ICommitmentsApiClient>(), Mock.Of <IFeatureTogglesService <ProviderFeatureToggle> >(), _encodingService.Object); }
public async Task Arrange() { var autoFixture = new Fixture(); _allTrainingProgrammes = autoFixture.CreateMany <TrainingProgramme>().ToList(); _standardTrainingProgrammes = autoFixture.CreateMany <TrainingProgramme>().ToList(); _cohort = autoFixture.Create <GetCohortResponse>(); _cohort.WithParty = Party.Employer; _commitmentsApiClient = new Mock <ICommitmentsApiClient>(); _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_cohort); _commitmentsApiClient .Setup(x => x.GetAllTrainingProgrammeStandards(It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse { TrainingProgrammes = _standardTrainingProgrammes }); _commitmentsApiClient .Setup(x => x.GetAllTrainingProgrammes(It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAllTrainingProgrammesResponse { TrainingProgrammes = _allTrainingProgrammes }); _encodedTransferSenderId = autoFixture.Create <string>(); _encodingService = new Mock <IEncodingService>(); _encodingService .Setup(x => x.Encode(It.IsAny <long>(), It.Is <EncodingType>(e => e == EncodingType.PublicAccountId))) .Returns(_encodedTransferSenderId); _mapper = new AddDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object); _source = autoFixture.Create <AddDraftApprenticeshipRequest>(); _source.StartMonthYear = "092020"; _result = await _mapper.Map(TestHelper.Clone(_source)); }
public AddDraftApprenticeshipViewModelToAddDraftApprenticeshipRequestMapperTestsFixture() { ViewModel = new AddDraftApprenticeshipViewModel { FirstName = "John", LastName = "Doe", BirthDay = 1, BirthMonth = 2, BirthYear = 2000, Uln = "AAA000", CourseCode = "BBB111", Cost = 3, StartMonth = 8, StartYear = 2019, EndMonth = 9, EndYear = 2020, Reference = "CCC222", ReservationId = Guid.NewGuid() }; Mapper = new AddDraftApprenticeshipRequestMapper(); }
public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model) { var request = await _modelMapper.Map <AddDraftApprenticeshipRequest>(model); request.UserId = User.Upn(); var response = await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, request); if (string.IsNullOrEmpty(model.CourseCode)) { return(RedirectToAction("Details", "Cohort", new { model.ProviderId, model.CohortReference })); } var draftApprenticeship = await _commitmentsApiClient.GetDraftApprenticeship(model.CohortId.Value, response.DraftApprenticeshipId); if (draftApprenticeship.HasStandardOptions) { var draftApprenticeshipHashedId = _encodingService.Encode(draftApprenticeship.Id, EncodingType.ApprenticeshipId); return(RedirectToAction("SelectOptions", "DraftApprenticeship", new { model.ProviderId, draftApprenticeshipHashedId, model.CohortReference })); } return(RedirectToAction("Details", "Cohort", new { model.ProviderId, model.CohortReference })); }
public async Task Arrange() { var autoFixture = new Fixture(); _standardTrainingProgrammes = autoFixture.CreateMany <TrainingProgramme>().ToList(); _allTrainingProgrammes = autoFixture.CreateMany <TrainingProgramme>().ToList(); _providerResponse = autoFixture.Create <GetProviderResponse>(); _accountLegalEntityResponse = autoFixture.Build <AccountLegalEntityResponse>().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); _source = autoFixture.Build <ApprenticeRequest>() .With(x => x.StartMonthYear, "062020") .With(x => x.AccountId, 12345) .Without(x => x.TransferSenderId).Create(); _commitmentsApiClient = new Mock <ICommitmentsApiClient>(); _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny <long>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_providerResponse); _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny <CancellationToken>())) .ReturnsAsync(_accountLegalEntityResponse); _commitmentsApiClient .Setup(x => x.GetAllTrainingProgrammeStandards(It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse() { TrainingProgrammes = _standardTrainingProgrammes }); _commitmentsApiClient .Setup(x => x.GetAllTrainingProgrammes(It.IsAny <CancellationToken>())) .ReturnsAsync(new GetAllTrainingProgrammesResponse { TrainingProgrammes = _allTrainingProgrammes }); _mapper = new AddDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); }
public AddDraftApprenticeshipTestsFixture() { Cohort = new CohortDetails { CohortId = 1, ProviderName = "Foobar", WithParty = Party.Employer }; Request = new AddDraftApprenticeshipRequest { AccountHashedId = "AAA000", CohortReference = "BBB111", CohortId = Cohort.CohortId, AccountLegalEntityHashedId = "CCC222", AccountLegalEntityId = 2, ReservationId = Guid.NewGuid(), StartMonthYear = "092019", CourseCode = "DDD333" }; ViewModel = new AddDraftApprenticeshipViewModel { AccountHashedId = Request.AccountHashedId, CohortReference = Request.CohortReference, CohortId = Request.CohortId, AccountLegalEntityHashedId = Request.AccountLegalEntityHashedId, AccountLegalEntityId = Request.AccountLegalEntityId, ReservationId = Request.ReservationId, StartDate = new MonthYearModel(Request.StartMonthYear), CourseCode = Request.CourseCode }; AddDraftApprenticeshipRequest = new CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest(); StandardCourses = new List <TrainingProgramme>(); Courses = new List <TrainingProgramme>(); CohortDetailsUrl = $"accounts/{Request.AccountHashedId}/apprentices/{Request.CohortReference}/details"; CommitmentsApiModelException = new CommitmentsApiModelException(new List <ErrorDetail> { new ErrorDetail("Foo", "Bar") }); CommitmentsApiClient = new Mock <ICommitmentsApiClient>(); ModelMapper = new Mock <IModelMapper>(); LinkGenerator = new Mock <ILinkGenerator>(); AuthorizationService = new Mock <IAuthorizationService>(); AuthorizationService.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(false); Controller = new DraftApprenticeshipController( ModelMapper.Object, CommitmentsApiClient.Object, AuthorizationService.Object ); CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammes(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammesResponse { TrainingProgrammes = Courses }); CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammeStandards(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse { TrainingProgrammes = StandardCourses }); ModelMapper.Setup(m => m.Map <CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(ViewModel)).Returns(Task.FromResult(AddDraftApprenticeshipRequest)); ModelMapper.Setup(m => m.Map <AddDraftApprenticeshipViewModel>(It.IsAny <AddDraftApprenticeshipRequest>())).ReturnsAsync(ViewModel); }
public DraftApprenticeshipControllerTestFixture() { var autoFixture = new Fixture(); _cohortId = autoFixture.Create <long>(); _draftApprenticeshipId = autoFixture.Create <long>(); _providerId = autoFixture.Create <int>(); _cohortReference = autoFixture.Create <string>(); _draftApprenticeshipHashedId = autoFixture.Create <string>(); _editDraftApprenticeshipRequest = autoFixture.Build <EditDraftApprenticeshipRequest>() .With(x => x.CohortId, _cohortId) .With(x => x.DraftApprenticeshipId, _draftApprenticeshipId) .Create(); _editDraftApprenticeshipDetails = autoFixture.Build <GetDraftApprenticeshipResponse>() .Create(); _createAddDraftApprenticeshipRequest = new AddDraftApprenticeshipRequest(); _updateDraftApprenticeshipRequest = new UpdateDraftApprenticeshipRequest(); _reservationsAddDraftApprenticeshipRequest = autoFixture.Build <ReservationsAddDraftApprenticeshipRequest>() .With(x => x.ProviderId, _providerId) .With(x => x.CohortId, _cohortId) .With(x => x.CohortReference, _cohortReference) .With(x => x.StartMonthYear, "012019") .Create(); _courseResponse = new GetTrainingCoursesQueryResponse { TrainingCourses = new TrainingProgramme[0] }; _addModel = new AddDraftApprenticeshipViewModel { ProviderId = _providerId, CohortId = _cohortId, CohortReference = _cohortReference }; _editModel = new EditDraftApprenticeshipViewModel { ProviderId = _providerId, CohortId = _cohortId, CohortReference = _cohortReference, DraftApprenticeshipId = _draftApprenticeshipId, DraftApprenticeshipHashedId = _draftApprenticeshipHashedId }; _cohortResponse = autoFixture.Build <GetCohortResponse>() .With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy) .With(x => x.ChangeOfPartyRequestId, default(long?)) .Create(); _apiModelException = new CommitmentsApiModelException(new List <ErrorDetail>() { new ErrorDetail("Name", "Cannot be more than...") }); _mediator = new Mock <IMediator>(); _mediator.Setup(x => x.Send(It.IsAny <GetTrainingCoursesQueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_courseResponse); _modelMapper = new Mock <IModelMapper>(); _modelMapper.Setup(x => x.Map <AddDraftApprenticeshipRequest>(It.IsAny <AddDraftApprenticeshipViewModel>())) .ReturnsAsync(_createAddDraftApprenticeshipRequest); _modelMapper.Setup(x => x.Map <EditDraftApprenticeshipViewModel>(It.IsAny <EditDraftApprenticeshipRequest>())) .ReturnsAsync(_editModel); _modelMapper.Setup(x => x.Map <UpdateDraftApprenticeshipRequest>(It.IsAny <EditDraftApprenticeshipViewModel>())) .ReturnsAsync(_updateDraftApprenticeshipRequest); _linkGenerator = new Mock <ILinkGenerator>(); _linkGenerator.Setup(x => x.ProviderApprenticeshipServiceLink(It.IsAny <string>())) .Returns <string>(input => input); _commitmentsApiClient = new Mock <ICommitmentsApiClient>(); _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_cohortResponse); _controller = new DraftApprenticeshipController(_mediator.Object, _linkGenerator.Object, _commitmentsApiClient.Object, _modelMapper.Object); }
private void AssertValidationResult <T>(Expression <Func <AddDraftApprenticeshipViewModel, T> > property, AddDraftApprenticeshipViewModel instance, bool expectedValid) { var validator = new AddDraftApprenticeshipViewModelValidator(); if (expectedValid) { validator.ShouldNotHaveValidationErrorFor(property, instance); } else { validator.ShouldHaveValidationErrorFor(property, instance); } }