Esempio n. 1
0
        public DeleteDraftApprenticeshipTestsFixture()
        {
            var fixture = new AutoFixture.Fixture();

            CommitmentApiClient = new Mock <ICommitmentsApiClient>();
            CommitmentApiClient.Setup(x => x.GetCohort(It.IsAny <long>(), It.IsAny <CancellationToken>())).ReturnsAsync(new GetCohortResponse());

            var deleteDraftApprenticeshipViewModel = new DeleteDraftApprenticeshipViewModel
            {
                FirstName = "John",
                LastName  = "Jack",
                CohortId  = CohortId,
                DraftApprenticeshipHashedId = DraftApprenticeshipHashedId,
                AccountHashedId             = AccountHashedId,
            };

            ModelMapperMock = new Mock <IModelMapper>();
            ModelMapperMock.Setup(x => x.Map <DeleteDraftApprenticeshipViewModel>(It.IsAny <DeleteApprenticeshipRequest>()))
            .ReturnsAsync(deleteDraftApprenticeshipViewModel);

            AuthorizationServiceMock = new Mock <IAuthorizationService>();

            Sut = new DraftApprenticeshipController(
                ModelMapperMock.Object,
                CommitmentApiClient.Object,
                AuthorizationServiceMock.Object);


            Sut.TempData = new Mock <ITempDataDictionary>().Object;
        }
Esempio n. 2
0
        public void Arrange()
        {
            var fixture = new Fixture();

            _request = fixture.Create <SelectOptionRequest>();

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

            _viewModel = fixture.Build <SelectOptionViewModel>()
                         .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)
                         .Create();

            _updateRequest = fixture.Create <UpdateDraftApprenticeshipRequest>();

            _mockModelMapper          = new Mock <IModelMapper>();
            _mockCommitmentsApiClient = new Mock <ICommitmentsApiClient>();

            _controller = new DraftApprenticeshipController(_mockModelMapper.Object, _mockCommitmentsApiClient.Object, Mock.Of <IAuthorizationService>(), Mock.Of <IEncodingService>());

            _mockModelMapper.Setup(m => m.Map <UpdateDraftApprenticeshipRequest>(_viewModel))
            .ReturnsAsync(_updateRequest);
        }
        public void Arrange()
        {
            var _autoFixture = new Fixture();

            _request         = _autoFixture.Create <DeleteConfirmationRequest>();
            _modelMapperMock = new Mock <IModelMapper>();
            _viewModel       = _autoFixture.Create <DeleteConfirmationViewModel>();

            _modelMapperMock
            .Setup(x => x.Map <DeleteConfirmationViewModel>(_request))
            .ReturnsAsync(_viewModel);

            Sut = new DraftApprenticeshipController(Mock.Of <IMediator>(), Mock.Of <ICommitmentsApiClient>(), _modelMapperMock.Object, Mock.Of <IEncodingService>());
        }
        public async Task And_Exception_Then_Returns_Bad_Request(
            long cohortId,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] DraftApprenticeshipController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetDraftApprenticeshipsQuery>(x => x.CohortId == cohortId),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetAll(cohortId) as BadRequestResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public DraftApprenticeshipControllerTestsFixture()
        {
            Mediator = new Mock <IMediator>();
            UpdateDraftApprenticeshipMapper = new Mock <IOldMapper <UpdateDraftApprenticeshipRequest, UpdateDraftApprenticeshipCommand> >();
            GetDraftApprenticeshipMapper    = new Mock <IOldMapper <GetDraftApprenticeshipQueryResult, GetDraftApprenticeshipResponse> >();
            AddDraftApprenticeshipMapper    = new Mock <IOldMapper <AddDraftApprenticeshipRequest, AddDraftApprenticeshipCommand> >();
            GetDraftApprenticeshipsMapper   = new Mock <IOldMapper <GetDraftApprenticeshipsQueryResult, GetDraftApprenticeshipsResponse> >();
            DeleteDraftApprenticeshipMapper = new Mock <IOldMapper <DeleteDraftApprenticeshipRequest, DeleteDraftApprenticeshipCommand> >();

            Controller = new DraftApprenticeshipController(
                Mediator.Object,
                UpdateDraftApprenticeshipMapper.Object,
                GetDraftApprenticeshipMapper.Object,
                AddDraftApprenticeshipMapper.Object,
                GetDraftApprenticeshipsMapper.Object,
                DeleteDraftApprenticeshipMapper.Object
                );
        }
        public async Task Then_Gets_DraftApprenticeships_From_Mediator(
            long cohortId,
            GetDraftApprenticeshipsResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] DraftApprenticeshipController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetDraftApprenticeshipsQuery>(x => x.CohortId == cohortId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetAll(cohortId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetDraftApprenticeshipsResult;

            Assert.IsNotNull(model);
            model.DraftApprenticeships.Should().BeEquivalentTo(mediatorResult.DraftApprenticeships);
        }
Esempio n. 7
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 _autoFixture = new Fixture();

            _modelMapperMock = new Mock <IModelMapper>();
            _viewModel       = _autoFixture.Create <DeleteConfirmationViewModel>();
            _apiClient       = new Mock <ICommitmentsApiClient>();
            _apiClient.Setup(x => x.DeleteDraftApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <DeleteDraftApprenticeshipRequest>(),
                                                              It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            _mapperResult = new DeleteDraftApprenticeshipRequest();
            _modelMapperMock
            .Setup(x => x.Map <DeleteDraftApprenticeshipRequest>(_viewModel))
            .ReturnsAsync(_mapperResult);

            RedirectUrl = $"{_viewModel.ProviderId}/apprentices/{_viewModel.CohortReference}/Details";

            var tempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>());

            Sut          = new DraftApprenticeshipController(Mock.Of <IMediator>(), _apiClient.Object, _modelMapperMock.Object, Mock.Of <IEncodingService>());
            Sut.TempData = tempData;
        }
        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);
        }
        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);
        }