Пример #1
0
        public void Arrange()
        {
            _autoFixture = new Fixture();
            _fixture     = new WhenPostingEditApprenticeshipDetailsFixture();

            _apprenticeshipResponse = _autoFixture.Build <GetApprenticeshipResponse>()
                                      .With(x => x.CourseCode, _autoFixture.Create <int>().ToString())
                                      .Create();

            _standardVersionResponse = _autoFixture.Build <GetTrainingProgrammeResponse>()
                                       .With(x => x.TrainingProgramme, _autoFixture.Build <TrainingProgramme>()
                                             .With(x => x.Version, "1.0")
                                             .With(x => x.Options, new List <string>())
                                             .Create())
                                       .Create();

            _frameworkResponse = _autoFixture.Create <GetTrainingProgrammeResponse>();
            _frameworkResponse.TrainingProgramme.Version = null;

            _viewModel = _autoFixture.Build <EditApprenticeshipRequestViewModel>()
                         .Without(x => x.StartDate)
                         .Without(x => x.EndDate)
                         .Without(x => x.DateOfBirth)
                         .With(x => x.CourseCode, _apprenticeshipResponse.CourseCode)
                         .Create();

            _viewModel.StartDate = new MonthYearModel(_apprenticeshipResponse.StartDate.ToString("MMyyyy"));

            _fixture.SetUpGetApprenticeship(_apprenticeshipResponse);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _request = _fixture.Create <ChangeVersionRequest>();

            _getApprenticeshipResponse = _fixture.Build <GetApprenticeshipResponse>()
                                         .With(x => x.Version, "1.1")
                                         .With(x => x.StandardUId, "ST0001_1.1")
                                         .Create();

            _getCurrentVersionResponse = _fixture.Create <GetTrainingProgrammeResponse>();

            _getNewerTrainingProgrammeVersionsResponse = GetTrainingProgrammeVersions();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(_request.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getApprenticeshipResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgrammeVersionByStandardUId(_getApprenticeshipResponse.StandardUId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getCurrentVersionResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetNewerTrainingProgrammeVersions(_getApprenticeshipResponse.StandardUId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getNewerTrainingProgrammeVersionsResponse);

            _mapper = new ChangeVersionViewModelMapper(_mockCommitmentsApiClient.Object);
        }
Пример #3
0
            public DetailsViewModelMapperFixture()
            {
                Fixture                = new Fixture();
                Source                 = Fixture.Create <DetailsRequest>();
                ApiResponse            = Fixture.Create <GetApprenticeshipResponse>();
                ApiResponse.ProviderId = Source.ProviderId;
                CohortReference        = Fixture.Create <string>();
                AgreementId            = Fixture.Create <string>();
                URL = Fixture.Create <string>();
                PriceEpisodesApiResponse = new GetPriceEpisodesResponse
                {
                    PriceEpisodes = new List <GetPriceEpisodesResponse.PriceEpisode>
                    {
                        new GetPriceEpisodesResponse.PriceEpisode {
                            Cost = 100, FromDate = DateTime.UtcNow
                        }
                    }
                };

                GetApprenticeshipUpdatesResponse = new GetApprenticeshipUpdatesResponse
                {
                    ApprenticeshipUpdates = new List <GetApprenticeshipUpdatesResponse.ApprenticeshipUpdate>()
                };

                GetDataLocksResponse = new GetDataLocksResponse
                {
                    DataLocks = new List <DataLock>()
                };

                GetChangeOfPartyRequestsResponse = new GetChangeOfPartyRequestsResponse
                {
                    ChangeOfPartyRequests = new List <GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest>()
                };

                GetChangeOfEmployerChainResponse = new GetChangeOfEmployerChainResponse
                {
                    ChangeOfEmployerChain = new List <GetChangeOfEmployerChainResponse.ChangeOfEmployerLink>()
                };

                GetNewerTrainingProgrammeVersionsResponse = new GetNewerTrainingProgrammeVersionsResponse()
                {
                    NewerVersions = new List <TrainingProgramme>()
                };

                GetTrainingProgrammeByStandardUIdResponse = new GetTrainingProgrammeResponse();

                _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.PublicAccountLegalEntityId)).Returns(AgreementId);

                _authorizationService = new Mock <IAuthorizationService>();

                EncodedNewApprenticeshipId      = Fixture.Create <string>();
                EncodedPreviousApprenticeshipId = Fixture.Create <string>();
            }
        public void SetUp()
        {
            //Arrange
            var autoFixture = new Fixture();

            _request = autoFixture.Build <ApprenticeshipDetailsRequest>()
                       .With(x => x.AccountHashedId, "123")
                       .With(x => x.ApprenticeshipHashedId, "456")
                       .Create();
            _apprenticeshipResponse = autoFixture.Build <GetApprenticeshipResponse>()
                                      .With(x => x.CourseCode, "ABC")
                                      .With(x => x.DateOfBirth, autoFixture.Create <DateTime>())
                                      .Create();
            _priceEpisodesResponse = autoFixture.Build <GetPriceEpisodesResponse>()
                                     .With(x => x.PriceEpisodes, new List <PriceEpisode> {
                new PriceEpisode {
                    Cost = 1000, ToDate = DateTime.Now.AddMonths(-1)
                }
            })
                                     .Create();
            _apprenticeshipUpdatesResponse = autoFixture.Build <GetApprenticeshipUpdatesResponse>()
                                             .With(x => x.ApprenticeshipUpdates, new List <ApprenticeshipUpdate> {
                new ApprenticeshipUpdate {
                    OriginatingParty = Party.Employer
                }
            })
                                             .Create();
            _dataLocksResponse             = autoFixture.Build <GetDataLocksResponse>().Create();
            _changeOfPartyRequestsResponse = autoFixture.Build <GetChangeOfPartyRequestsResponse>().Create();
            _trainingProgrammeResponse     = autoFixture.Build <GetTrainingProgrammeResponse>().Create();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(r => r.GetApprenticeship(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_apprenticeshipResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_priceEpisodesResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeshipUpdates(It.IsAny <long>(), It.IsAny <GetApprenticeshipUpdatesRequest>(), CancellationToken.None))
            .ReturnsAsync(_apprenticeshipUpdatesResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeshipDatalocksStatus(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_dataLocksResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetChangeOfPartyRequests(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_changeOfPartyRequestsResponse);
            _mockCommitmentsApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_trainingProgrammeResponse);
            _mockEncodingService = new Mock <IEncodingService>();
            _mapper = new ApprenticeshipDetailsRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object, Mock.Of <ILogger <ApprenticeshipDetailsRequestToViewModelMapper> >());
        }
Пример #5
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _request = _fixture.Create <ChangeOptionRequest>();

            var baseDate    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            var startDate   = baseDate;
            var endDate     = baseDate.AddYears(2);
            var dateOfBirth = baseDate.AddYears(-18);

            _getApprenticeshipResponse = _fixture.Build <GetApprenticeshipResponse>()
                                         .With(x => x.StartDate, startDate)
                                         .With(x => x.EndDate, endDate)
                                         .With(x => x.DateOfBirth, dateOfBirth)
                                         .Create();

            _editViewModel = _fixture.Build <EditApprenticeshipRequestViewModel>()
                             .With(x => x.CourseCode, _getApprenticeshipResponse.CourseCode)
                             .With(x => x.Version, _getApprenticeshipResponse.Version)
                             .With(x => x.StartDate, new MonthYearModel(startDate.ToString("MMyyyy")))
                             .With(x => x.EndDate, new MonthYearModel(endDate.ToString("MMyyyy")))
                             .With(x => x.DateOfBirth, new MonthYearModel(dateOfBirth.ToString("MMyyyy")))
                             .Create();

            _getVersionResponse = _fixture.Create <GetTrainingProgrammeResponse>();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient
            .Setup(c => c.GetTrainingProgrammeVersionByCourseCodeAndVersion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getVersionResponse);
            _mockCommitmentsApiClient
            .Setup(c => c.GetApprenticeship(_request.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getApprenticeshipResponse);

            _mockTempDataDictionary = new Mock <ITempDataDictionary>();

            _mockTempDataFactory = new Mock <ITempDataDictionaryFactory>();
            _mockTempDataFactory.Setup(f => f.GetTempData(It.IsAny <HttpContext>()))
            .Returns(_mockTempDataDictionary.Object);

            _mapper = new ChangeOptionViewModelMapper(_mockCommitmentsApiClient.Object,
                                                      Mock.Of <IHttpContextAccessor>(),
                                                      _mockTempDataFactory.Object);
        }
Пример #6
0
        public async Task GetTrainingProgramme()
        {
            var trainingCode        = "123-ab";
            var request             = new TestRequest(new Uri(ExpectedApiBaseUrl + $"api/trainingprogramme/{trainingCode}"), string.Empty);
            var getProviderResponse = new GetTrainingProgrammeResponse
            {
                TrainingProgramme = new TrainingProgramme()
            };
            var content = JsonConvert.SerializeObject(
                getProviderResponse);

            _fakeHandler.AddFakeResponse(request, new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK, Content = new StringContent(content)
            });

            var response = (await _trainingProgrammeApi.Get(trainingCode));

            response.ShouldBeEquivalentTo(getProviderResponse);
        }
Пример #7
0
        public void Arrange()
        {
            var fixture = new Fixture();

            _draftApprenticeshipApiResponse = fixture.Build <GetDraftApprenticeshipResponse>().Create();
            _standardOptionsResponse        = fixture.Build <GetTrainingProgrammeResponse>().Create();
            _selectOptionsRequest           = fixture.Build <SelectOptionsRequest>().Create();

            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient
            .Setup(x => x.GetTrainingProgrammeVersionByStandardUId(_draftApprenticeshipApiResponse.StandardUId, CancellationToken.None))
            .ReturnsAsync(_standardOptionsResponse);
            _commitmentsApiClient
            .Setup(x => x.GetDraftApprenticeship(_selectOptionsRequest.CohortId, _selectOptionsRequest.DraftApprenticeshipId, CancellationToken.None))
            .ReturnsAsync(_draftApprenticeshipApiResponse);

            _mapper = new ViewStandardOptionsViewModelMapper(_commitmentsApiClient.Object);

            _act = async() => await _mapper.Map(TestHelper.Clone(_selectOptionsRequest));
        }
        private int?GetFundingBandCap(GetTrainingProgrammeResponse course, DateTime?startDate)
        {
            if (startDate == null)
            {
                return(null);
            }

            if (course == null)
            {
                return(null);
            }

            var cap = course.TrainingProgramme.FundingCapOn(startDate.Value);

            if (cap > 0)
            {
                return(cap);
            }

            return(null);
        }
        public void Arrange()
        {
            var fixture = new Fixture();

            _apiResponse = fixture.Build <GetDraftApprenticeshipResponse>().Create();
            _apiTrainingProgrammeResponse = fixture.Build <GetTrainingProgrammeResponse>().Create();

            var commitmentsApiClient = new Mock <ICommitmentsApiClient>();

            commitmentsApiClient.Setup(x =>
                                       x.GetDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_apiResponse);

            commitmentsApiClient.Setup(x => x.GetTrainingProgramme(_apiResponse.CourseCode, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_apiTrainingProgrammeResponse);

            _mapper = new ViewDraftApprenticeshipViewModelMapper(commitmentsApiClient.Object);
            _source = fixture.Build <DraftApprenticeshipRequest>().Create();

            _act = async() => (await _mapper.Map(TestHelper.Clone(_source))) as ViewDraftApprenticeshipViewModel;
        }
        public void Arrange()
        {
            var fixture = new Fixture();

            _request = fixture.Build <SelectOptionRequest>().Create();

            _getDraftApprenticeshipResponse = fixture.Build <GetDraftApprenticeshipResponse>()
                                              .With(x => x.HasStandardOptions, true)
                                              .Create();

            _GetTrainingProgrammeResponse = fixture.Build <GetTrainingProgrammeResponse>().Create();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(client => client.GetDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getDraftApprenticeshipResponse);

            _mockCommitmentsApiClient.Setup(client => client.GetTrainingProgrammeVersionByStandardUId(_getDraftApprenticeshipResponse.StandardUId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_GetTrainingProgrammeResponse);

            _mapper = new SelectOptionViewModelMapper(_mockCommitmentsApiClient.Object);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _viewModel = _fixture.Create <ChangeVersionViewModel>();
            _getApprenticeshipResponse = _fixture.Create <GetApprenticeshipResponse>();

            var priceEpisode = _fixture.Build <PriceEpisode>()
                               .With(x => x.ApprenticeshipId, _getApprenticeshipResponse.Id)
                               .With(x => x.FromDate, _getApprenticeshipResponse.StartDate.AddDays(-1))
                               .Without(x => x.ToDate)
                               .Create();

            _getPriceEpisodesResponse = _fixture.Build <GetPriceEpisodesResponse>()
                                        .With(x => x.PriceEpisodes, new List <PriceEpisode> {
                priceEpisode
            })
                                        .Create();

            var trainingProgramme = _fixture.Build <TrainingProgramme>().With(x => x.Name, _getApprenticeshipResponse.CourseName).Create();

            _getVersionResponse = new GetTrainingProgrammeResponse {
                TrainingProgramme = trainingProgramme
            };

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(_viewModel.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getApprenticeshipResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(_viewModel.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getPriceEpisodesResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgrammeVersionByCourseCodeAndVersion(_getApprenticeshipResponse.CourseCode, _viewModel.SelectedVersion, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getVersionResponse);

            _mapper = new ChangeVersionViewModelToEditApprenticehipRequestViewModelMapper(_mockCommitmentsApiClient.Object);
        }
            public ViewApprenticeshipUpdatesRequestToViewModelMapperTestsFixture()
            {
                var autoFixture = new Fixture();

                autoFixture.Customizations.Add(new DateTimeSpecimenBuilder());
                CommitmentApiClient = new Mock <ICommitmentsApiClient>();

                Source = new ViewApprenticeshipUpdatesRequest {
                    ApprenticeshipId = ApprenticeshipId, ProviderId = 22, ApprenticeshipHashedId = "XXX"
                };
                GetApprenticeshipResponse         = autoFixture.Create <GetApprenticeshipResponse>();
                GetApprenticeshipResponse.Id      = ApprenticeshipId;
                autoFixture.RepeatCount           = 1;
                GetApprenticeshipUpdatesResponses = autoFixture.Create <GetApprenticeshipUpdatesResponse>();
                ApprenticeshipUpdate         = GetApprenticeshipUpdatesResponses.ApprenticeshipUpdates.First();
                GetTrainingProgrammeResponse = autoFixture.Create <GetTrainingProgrammeResponse>();

                var priceEpisode = new GetPriceEpisodesResponse
                {
                    PriceEpisodes = new List <GetPriceEpisodesResponse.PriceEpisode>()
                    {
                        new GetPriceEpisodesResponse.PriceEpisode
                        {
                            FromDate = DateTime.UtcNow.AddDays(-10),
                            ToDate   = null,
                            Cost     = 100
                        }
                    }
                };

                CommitmentApiClient.Setup(x => x.GetApprenticeship(ApprenticeshipId, It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetApprenticeshipResponse));
                CommitmentApiClient.Setup(x => x.GetApprenticeshipUpdates(ApprenticeshipId, It.IsAny <GetApprenticeshipUpdatesRequest>(), It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetApprenticeshipUpdatesResponses));
                CommitmentApiClient.Setup(x => x.GetPriceEpisodes(ApprenticeshipId, It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(priceEpisode));
                CommitmentApiClient.Setup(x => x.GetTrainingProgramme(It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetTrainingProgrammeResponse));

                Mapper = new ViewApprenticeshipUpdatesRequestToViewModelMapper(CommitmentApiClient.Object);
            }
        private async Task SetFundingBandCap(string courseCode, IEnumerable <CohortDraftApprenticeshipViewModel> draftApprenticeships)
        {
            GetTrainingProgrammeResponse course = null;

            if (!string.IsNullOrEmpty(courseCode))
            {
                try
                {
                    course = await _commitmentsApiClient.GetTrainingProgramme(courseCode);
                }
                catch (RestHttpClientException e)
                {
                    if (e.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw;
                    }
                }
            }

            foreach (var draftApprenticeship in draftApprenticeships)
            {
                draftApprenticeship.FundingBandCap = GetFundingBandCap(course, draftApprenticeship.OriginalStartDate ?? draftApprenticeship.StartDate);
            }
        }
Пример #14
0
        public EditApprenticeshipRequestToViewModelMapperTestsFixture()
        {
            //Arrange
            var autoFixture = new Fixture();

            _request = autoFixture.Build <EditApprenticeshipRequest>()
                       .With(x => x.AccountHashedId, "123")
                       .With(x => x.ApprenticeshipHashedId, "456")
                       .Create();
            ApprenticeshipResponse = autoFixture.Build <GetApprenticeshipResponse>()
                                     .With(x => x.CourseCode, "ABC")
                                     .With(x => x.Version, "1.0")
                                     .With(x => x.DateOfBirth, autoFixture.Create <DateTime>())
                                     .Create();
            _priceEpisodesResponse = autoFixture.Build <GetPriceEpisodesResponse>()
                                     .With(x => x.PriceEpisodes, new List <PriceEpisode> {
                new PriceEpisode {
                    Cost = 1000, ToDate = DateTime.Now.AddMonths(-1)
                }
            })
                                     .Create();

            _cohortResponse  = autoFixture.Create <GetCohortResponse>();
            _accountResponse = autoFixture.Create <AccountResponse>();
            _allTrainingProgrammeStandardsResponse = autoFixture.Create <GetAllTrainingProgrammeStandardsResponse>();
            _allTrainingProgrammeResponse          = autoFixture.Create <GetAllTrainingProgrammesResponse>();

            _trainingProgrammeResponse = autoFixture.Build <GetTrainingProgrammeResponse>().Create();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(r => r.GetApprenticeship(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(ApprenticeshipResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_priceEpisodesResponse);

            _mockCommitmentsApiClient.Setup(t => t.GetTrainingProgramme(ApprenticeshipResponse.CourseCode, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_trainingProgrammeResponse);

            _mockCommitmentsApiClient.Setup(t => t.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _cohortResponse);

            _mockCommitmentsApiClient.Setup(t => t.GetAccount(_request.AccountId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _accountResponse);

            _mockCommitmentsApiClient.Setup(t => t.GetAllTrainingProgrammeStandards(It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => {
                _courses = _allTrainingProgrammeStandardsResponse.TrainingProgrammes;
                return(_allTrainingProgrammeStandardsResponse);
            });

            _mockCommitmentsApiClient.Setup(t => t.GetAllTrainingProgrammes(It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => {
                _courses = _allTrainingProgrammeResponse.TrainingProgrammes;
                return(_allTrainingProgrammeResponse);
            });

            _mockAcademicYearDateProvider = new Mock <IAcademicYearDateProvider>();

            _mockCurrentDateTimeProvider = new Mock <ICurrentDateTime>();

            _mapper = new EditApprenticeshipRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockAcademicYearDateProvider.Object, _mockCurrentDateTimeProvider.Object);
        }
Пример #15
0
 public void SetUpGetTrainingProgramme(EditApprenticeshipRequestViewModel viewModel, GetTrainingProgrammeResponse response)
 {
     _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgramme(viewModel.CourseCode, It.IsAny <CancellationToken>()))
     .ReturnsAsync(response);
 }
Пример #16
0
 public void SetUpGetCalculatedTrainingProgrammeVersion(EditApprenticeshipRequestViewModel viewModel, GetTrainingProgrammeResponse response)
 {
     _mockCommitmentsApiClient.Setup(c => c.GetCalculatedTrainingProgrammeVersion(int.Parse(viewModel.CourseCode), viewModel.StartDate.Date.Value, It.IsAny <CancellationToken>()))
     .ReturnsAsync(response);
 }
        public void Arrange()
        {
            _fixture = new Fixture();

            _viewModel = _fixture.Create <ChangeOptionViewModel>();

            var baseDate = DateTime.Now;

            var startDate   = baseDate;
            var endDate     = baseDate.AddYears(2);
            var dateOfBirth = baseDate.AddYears(-18);

            _getApprenticeshipResponse = _fixture.Build <GetApprenticeshipResponse>()
                                         .With(x => x.StartDate, startDate)
                                         .With(x => x.EndDate, endDate)
                                         .With(x => x.DateOfBirth, dateOfBirth)
                                         .Create();

            _editViewModel = _fixture.Build <EditApprenticeshipRequestViewModel>()
                             .With(x => x.CourseCode, _getApprenticeshipResponse.CourseCode)
                             .With(x => x.Version, _getApprenticeshipResponse.Version)
                             .With(x => x.StartDate, new MonthYearModel(startDate.ToString("MMyyyy")))
                             .With(x => x.EndDate, new MonthYearModel(endDate.ToString("MMyyyy")))
                             .With(x => x.DateOfBirth, new MonthYearModel(dateOfBirth.ToString("MMyyyy")))
                             .Create();

            var priceEpisode = _fixture.Build <PriceEpisode>()
                               .With(x => x.ApprenticeshipId, _getApprenticeshipResponse.Id)
                               .With(x => x.FromDate, _getApprenticeshipResponse.StartDate.AddDays(-1))
                               .Without(x => x.ToDate)
                               .Create();

            _getPriceEpisodesResponse = _fixture.Build <GetPriceEpisodesResponse>()
                                        .With(x => x.PriceEpisodes, new List <PriceEpisode> {
                priceEpisode
            })
                                        .Create();

            var trainingProgramme = _fixture.Build <TrainingProgramme>().With(x => x.Name, _getApprenticeshipResponse.CourseName).Create();

            _getVersionResponse = new GetTrainingProgrammeResponse {
                TrainingProgramme = trainingProgramme
            };

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(_viewModel.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getApprenticeshipResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(_viewModel.ApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getPriceEpisodesResponse);

            _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgrammeVersionByCourseCodeAndVersion(_getApprenticeshipResponse.CourseCode, _getApprenticeshipResponse.Version, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getVersionResponse);

            _mockTempDataDictionary = new Mock <ITempDataDictionary>();

            _mockTempDataFactory = new Mock <ITempDataDictionaryFactory>();
            _mockTempDataFactory.Setup(f => f.GetTempData(It.IsAny <HttpContext>()))
            .Returns(_mockTempDataDictionary.Object);

            _mapper = new ChangeOptionViewModelToEditApprenticeshipRequestViewModelMapper(
                _mockCommitmentsApiClient.Object,
                Mock.Of <IHttpContextAccessor>(),
                _mockTempDataFactory.Object);
        }
Пример #18
0
        public void SetUp()
        {
            //Arrange
            _request = autoFixture.Build <ApprenticeshipDetailsRequest>()
                       .With(x => x.AccountHashedId, $"A123")
                       .With(x => x.ApprenticeshipHashedId, $"A{ApprenticeshipIdFirst}")
                       .Create();
            _apprenticeshipResponse = autoFixture.Build <GetApprenticeshipResponse>()
                                      .With(x => x.Id, ApprenticeshipIdFirst)
                                      .With(x => x.CourseCode, "123")
                                      .With(x => x.StandardUId, "ST0001_1.0")
                                      .With(x => x.Version, "1.0")
                                      .With(x => x.DateOfBirth, autoFixture.Create <DateTime>())
                                      .Create();
            _priceEpisodesResponse = autoFixture.Build <GetPriceEpisodesResponse>()
                                     .With(x => x.PriceEpisodes, new List <PriceEpisode> {
                new PriceEpisode {
                    Cost = 1000, ToDate = DateTime.Now.AddMonths(-1)
                }
            })
                                     .Create();
            _apprenticeshipUpdatesResponse = autoFixture.Build <GetApprenticeshipUpdatesResponse>()
                                             .With(x => x.ApprenticeshipUpdates, new List <ApprenticeshipUpdate> {
                new ApprenticeshipUpdate {
                    OriginatingParty = Party.Employer
                }
            })
                                             .Create();
            _dataLocksResponse             = autoFixture.Build <GetDataLocksResponse>().Create();
            _changeOfPartyRequestsResponse = autoFixture.Build <GetChangeOfPartyRequestsResponse>().Create();

            var trainingProgrammeByStandardUId = autoFixture.Build <TrainingProgramme>()
                                                 .With(x => x.CourseCode, _apprenticeshipResponse.CourseCode)
                                                 .With(x => x.StandardUId, "ST0001_1.0")
                                                 .With(x => x.Version, "1.0")
                                                 .Create();

            _getTrainingProgrammeByStandardUId = new GetTrainingProgrammeResponse
            {
                TrainingProgramme = trainingProgrammeByStandardUId
            };

            var framework = autoFixture.Build <TrainingProgramme>()
                            .Without(x => x.Version)
                            .Without(x => x.StandardUId)
                            .With(x => x.CourseCode, "1-2-3")
                            .Create();

            _getTrainingProgrammeResponse = new GetTrainingProgrammeResponse
            {
                TrainingProgramme = framework
            };

            var trainingProgrammeVersions = autoFixture.Build <TrainingProgramme>().CreateMany(2).ToList();

            trainingProgrammeVersions[0].Version = "1.1";
            trainingProgrammeVersions[1].Version = "1.2";

            _newerTrainingProgrammeVersionsResponse = autoFixture.Build <GetNewerTrainingProgrammeVersionsResponse>()
                                                      .With(x => x.NewerVersions, trainingProgrammeVersions).Create();

            _changeOfProviderChainReponse = autoFixture.Build <GetChangeOfProviderChainResponse>().Create();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(r => r.GetApprenticeship(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_apprenticeshipResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_priceEpisodesResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeshipUpdates(It.IsAny <long>(), It.IsAny <GetApprenticeshipUpdatesRequest>(), CancellationToken.None))
            .ReturnsAsync(_apprenticeshipUpdatesResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetApprenticeshipDatalocksStatus(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_dataLocksResponse);
            _mockCommitmentsApiClient.Setup(c => c.GetChangeOfPartyRequests(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_changeOfPartyRequestsResponse);
            _mockCommitmentsApiClient.Setup(t => t.GetNewerTrainingProgrammeVersions(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_newerTrainingProgrammeVersionsResponse);
            _mockCommitmentsApiClient.Setup(t => t.GetChangeOfProviderChain(It.IsAny <long>(), CancellationToken.None))
            .ReturnsAsync(_changeOfProviderChainReponse);
            _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgrammeVersionByStandardUId(It.IsAny <string>(), CancellationToken.None))
            .ReturnsAsync(_getTrainingProgrammeByStandardUId);
            _mockCommitmentsApiClient.Setup(c => c.GetTrainingProgramme(It.IsAny <string>(), CancellationToken.None))
            .ReturnsAsync(_getTrainingProgrammeResponse);

            _mockEncodingService = new Mock <IEncodingService>();
            _mockEncodingService.Setup(t => t.Encode(It.IsAny <long>(), It.IsAny <EncodingType>()))
            .Returns((long value, EncodingType encodingType) => $"A{value}");
            _mockEncodingService.Setup(t => t.Decode(It.IsAny <string>(), It.IsAny <EncodingType>()))
            .Returns((string value, EncodingType encodingType) => long.Parse(Regex.Replace(value, "[A-Za-z ]", "")));

            _mapper = new ApprenticeshipDetailsRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object, Mock.Of <ILogger <ApprenticeshipDetailsRequestToViewModelMapper> >());
        }