Exemplo n.º 1
0
        public async Task Arrange()
        {
            var autoFixture = new Fixture();

            _request = autoFixture.Create <ViewDraftApprenticeshipRequest>();

            _draftApprenticeship = autoFixture.Create <GetDraftApprenticeshipResponse>();
            _course = autoFixture.Create <TrainingProgramme>();

            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient
            .Setup(x => x.GetTrainingProgramme(_draftApprenticeship.CourseCode, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetTrainingProgrammeResponse
            {
                TrainingProgramme = _course
            });

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

            _authorizationService = new Mock <IAuthorizationService>();

            _mapper = new ViewDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _authorizationService.Object);

            _result = await _mapper.Map(_request) as ViewDraftApprenticeshipViewModel;
        }
Exemplo n.º 2
0
        public void Arrange()
        {
            var fixture = new Fixture();

            var birthDate = fixture.Create <DateTime?>();
            var startDate = fixture.Create <DateTime?>();
            var endDate   = fixture.Create <DateTime?>();

            _getDraftApprenticeshipResponse = fixture.Create <GetDraftApprenticeshipResponse>();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mapper = new UpdateDraftApprenticeshipRequestMapper(_mockCommitmentsApiClient.Object);

            _source = fixture.Build <EditDraftApprenticeshipViewModel>()
                      .With(x => x.CourseCode, fixture.Create <int>().ToString())
                      .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();

            _mockCommitmentsApiClient.Setup(x => x.GetDraftApprenticeship(_source.CohortId.Value, _source.DraftApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getDraftApprenticeshipResponse);

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

            _cohortReference = fixture.Create <string>();
            _encodedDraftApprenticeshipId = fixture.Create <string>();
            var 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(_encodedDraftApprenticeshipId);

            _apiResponse = fixture.Build <GetDraftApprenticeshipResponse>().Create();
            var commitmentsApiClient = new Mock <ICommitmentsApiClient>();

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

            _mapper = new EditDraftApprenticeshipViewModelMapper(encodingService.Object, commitmentsApiClient.Object);
            _source = fixture.Build <EditDraftApprenticeshipRequest>().Create();

            _act = async() => await _mapper.Map(TestHelper.Clone(_source));
        }
        public DetailsTestFixture WithDraftApprenticeship(GetDraftApprenticeshipResponse details = null)
        {
            var returnValue = details ?? EditDraftApprenticeshipDetails;

            CommitmentsApiClientMock
            .Setup(cs => cs.GetDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(returnValue);

            return(this);
        }
Exemplo n.º 5
0
        public async Task Arrange()
        {
            var autoFixture = new Fixture();

            _allTrainingProgrammes      = autoFixture.CreateMany <TrainingProgramme>().ToList();
            _standardTrainingProgrammes = autoFixture.CreateMany <TrainingProgramme>().ToList();
            _encodedApprenticeshipId    = autoFixture.Create <string>();
            _cohortReference            = autoFixture.Create <string>();

            _encodingService = new Mock <IEncodingService>();
            _encodingService
            .Setup(x => x.Encode(It.IsAny <long>(), It.Is <EncodingType>(e => e == EncodingType.ApprenticeshipId)))
            .Returns(_encodedApprenticeshipId);
            _encodingService
            .Setup(x => x.Encode(It.IsAny <long>(), It.Is <EncodingType>(e => e == EncodingType.CohortReference)))
            .Returns(_cohortReference);

            _draftApprenticeshipResponse = autoFixture.Create <GetDraftApprenticeshipResponse>();
            _draftApprenticeshipResponse.IsContinuation = false;
            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient.Setup(x =>
                                        x.GetDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_draftApprenticeshipResponse);
            _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
            });

            _cohort           = autoFixture.Create <GetCohortResponse>();
            _cohort.WithParty = Party.Employer;
            _cohort.ChangeOfPartyRequestId = null;
            _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_cohort);

            _source        = autoFixture.Create <EditDraftApprenticeshipRequest>();
            _source.Cohort = _cohort;
            _mapper        = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object);

            _result = await _mapper.Map(TestHelper.Clone(_source)) as EditDraftApprenticeshipViewModel;
        }
Exemplo n.º 6
0
        public void Arrange()
        {
            var fixture = new Fixture();

            _source = fixture.Build <ViewSelectOptionsViewModel>()
                      .Create();
            _apiResponse          = fixture.Build <GetDraftApprenticeshipResponse>().Create();
            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient
            .Setup(x => x.GetDraftApprenticeship(_source.CohortId, _source.DraftApprenticeshipId,
                                                 CancellationToken.None)).ReturnsAsync(_apiResponse);
            _mapper = new ViewSelectOptionsViewModelToUpdateRequestMapper(_commitmentsApiClient.Object);

            _act = async() => await _mapper.Map(TestHelper.Clone(_source));
        }
Exemplo n.º 7
0
        public void Arrange()
        {
            var _autoFixture = new Fixture();

            _deleteConfirmationRequest = _autoFixture.Create <DeleteConfirmationRequest>();

            _getDraftApprenticeshipResponse = _autoFixture.Create <GetDraftApprenticeshipResponse>();

            _mockencodingService = new Mock <IEncodingService>();
            _mockencodingService.Setup(x => x.Decode(It.IsAny <string>(), EncodingType.CohortReference)).Returns(It.IsAny <long>);
            _mockencodingService.Setup(x => x.Decode(It.IsAny <string>(), EncodingType.ApprenticeshipId)).Returns(It.IsAny <long>);

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _mockCommitmentsApiClient.Setup(m => m.GetDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getDraftApprenticeshipResponse);

            _mapper = new DeleteConfirmationViewModelMapper(_mockCommitmentsApiClient.Object, _mockencodingService.Object, Mock.Of <ILogger <DeleteConfirmationViewModelMapper> >());
        }
Exemplo n.º 8
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));
        }
        public void Arrange()
        {
            var fixture = new Fixture();

            _cohortReference = fixture.Create <string>();

            _apiResponse = fixture.Build <GetDraftApprenticeshipResponse>().Create();
            var commitmentsApiClient = new Mock <ICommitmentsApiClient>();

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

            _authorizationService = new Mock <IAuthorizationService>();

            _mapper = new EditDraftApprenticeshipViewModelMapper(commitmentsApiClient.Object, _authorizationService.Object);
            _source = fixture.Build <EditDraftApprenticeshipRequest>().Create();

            _act = async() => (await _mapper.Map(TestHelper.Clone(_source))) as EditDraftApprenticeshipViewModel;
        }
        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;
        }
Exemplo n.º 11
0
        public void Arrange()
        {
            var fixture = new Fixture();

            var birthDate = fixture.Create <DateTime?>();
            var startDate = fixture.Create <DateTime?>();
            var endDate   = fixture.Create <DateTime?>();

            _viewModel = fixture.Build <SelectOptionViewModel>()
                         .Without(x => x.StartDate)
                         .Create();

            _getDraftApprenticeshipResponse = fixture.Create <GetDraftApprenticeshipResponse>();

            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _mockCommitmentsApiClient.Setup(c => c.GetDraftApprenticeship(_viewModel.CohortId.Value, _viewModel.DraftApprenticeshipId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(_getDraftApprenticeshipResponse);

            _mapper = new SelectOptionViewModelToUpdateDraftApprenticeshipRequestMapper(_mockCommitmentsApiClient.Object);
        }
Exemplo n.º 12
0
        public DetailsTestFixture()
        {
            ViewModel = new Mock <IDraftApprenticeshipViewModel>();
            CommitmentsApiClientMock = new Mock <ICommitmentsApiClient>();

            DetailsRequest = new DetailsRequest
            {
                AccountHashedId             = AccountHashedId,
                CohortId                    = CohortId,
                CohortReference             = CohortReference,
                DraftApprenticeshipId       = DraftApprenticeshipId,
                DraftApprenticeshipHashedId = DraftApprenticeshipHashedId
            };
            CohortDetails = new GetCohortResponse
            {
                CohortId     = CohortId,
                ProviderName = "ProviderName",
                WithParty    = Party.Employer
            };
            EditDraftApprenticeshipDetails = new GetDraftApprenticeshipResponse
            {
                Id = DraftApprenticeshipId
            };
            ApiErrors = new List <ErrorDetail> {
                new ErrorDetail("Field1", "Message1")
            };

            ModelMapperMock = new Mock <IModelMapper>();
            ModelMapperMock.Setup(x => x.Map <IDraftApprenticeshipViewModel>(It.IsAny <DetailsRequest>()))
            .ReturnsAsync(ViewModel.Object);

            AuthorizationServiceMock = new Mock <IAuthorizationService>();
            AuthorizationServiceMock.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(false);

            Sut = new DraftApprenticeshipController(
                ModelMapperMock.Object,
                CommitmentsApiClientMock.Object,
                AuthorizationServiceMock.Object,
                Mock.Of <IEncodingService>());
        }
        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 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);
        }