public async Task <IActionResult> SelectOptions(SelectOptionsRequest request)
        {
            var model = await _modelMapper.Map <ViewSelectOptionsViewModel>(request);

            if (!model.Options.Any())
            {
                return(RedirectToAction("Details", "Cohort", new { model.ProviderId, model.CohortReference }));
            }

            return(View("SelectStandardOption", model));
        }
예제 #2
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));
        }
예제 #3
0
        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>();

            _draftApprenticeshipRequest = autoFixture.Build <DraftApprenticeshipRequest>()
                                          .With(x => x.CohortId, _cohortId)
                                          .With(x => x.DraftApprenticeshipId, _draftApprenticeshipId)
                                          .Create();

            _selectOptionsRequest = autoFixture.Build <SelectOptionsRequest>()
                                    .With(c => c.CohortId, _cohortId)
                                    .With(x => x.DraftApprenticeshipId, _draftApprenticeshipId)
                                    .Create();

            _selectOptionsViewModel = autoFixture.Build <ViewSelectOptionsViewModel>()
                                      .With(c => c.CohortId, _cohortId)
                                      .With(x => x.DraftApprenticeshipId, _draftApprenticeshipId)
                                      .Create();

            _draftApprenticeshipDetails = autoFixture.Build <GetDraftApprenticeshipResponse>()
                                          .With(x => x.Id, _draftApprenticeshipId)
                                          .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
            {
                CourseCode      = "123",
                ProviderId      = _providerId,
                CohortId        = _cohortId,
                CohortReference = _cohortReference
            };

            _editModel = new EditDraftApprenticeshipViewModel
            {
                ProviderId                  = _providerId,
                CohortId                    = _cohortId,
                CohortReference             = _cohortReference,
                DraftApprenticeshipId       = _draftApprenticeshipId,
                DraftApprenticeshipHashedId = _draftApprenticeshipHashedId
            };

            _viewModel = new ViewDraftApprenticeshipViewModel
            {
                ProviderId      = _providerId,
                CohortReference = _cohortReference
            };

            _viewSelectOptionsViewModel = autoFixture.Build <ViewSelectOptionsViewModel>().Create();

            _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 <UpdateDraftApprenticeshipRequest>(It.IsAny <EditDraftApprenticeshipViewModel>()))
            .ReturnsAsync(_updateDraftApprenticeshipRequest);

            _modelMapper.Setup(x => x.Map <AddDraftApprenticeshipViewModel>(It.IsAny <ReservationsAddDraftApprenticeshipRequest>()))
            .ReturnsAsync(_addModel);

            _modelMapper.Setup(x => x.Map <UpdateDraftApprenticeshipRequest>(It.IsAny <GetDraftApprenticeshipResponse>()))
            .ReturnsAsync(_updateDraftApprenticeshipRequest);

            _modelMapper.Setup(x => x.Map <UpdateDraftApprenticeshipRequest>(It.IsAny <ViewSelectOptionsViewModel>()))
            .ReturnsAsync(_updateDraftApprenticeshipRequest);

            _commitmentsApiClient = new Mock <ICommitmentsApiClient>();
            _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_cohortResponse);
            _commitmentsApiClient.Setup(
                x => x.AddDraftApprenticeship(_addModel.CohortId.Value, _createAddDraftApprenticeshipRequest, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new AddDraftApprenticeshipResponse
            {
                DraftApprenticeshipId = _draftApprenticeshipId
            });

            var encodingService = new Mock <IEncodingService>();

            encodingService.Setup(x => x.Encode(_draftApprenticeshipId, EncodingType.ApprenticeshipId))
            .Returns(_draftApprenticeshipHashedId);

            _controller = new DraftApprenticeshipController(_mediator.Object, _commitmentsApiClient.Object, _modelMapper.Object, encodingService.Object);
        }