public void AccountIdMustBeGreaterThanZeroElseExceptionThrown(long accountId)
        {
            var command = new CreateApprenticeshipCommand {
                AccountId = accountId, Apprenticeship = new Apprenticeship {
                    CommitmentId = 123
                }
            };

            Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));
        }
Exemplo n.º 2
0
        public void AndCommandNotValid_ThenThrowsValidationException()
        {
            var errorMessage   = _fixture.Create <string>();
            var invalidRequest = _fixture.Create <CreateApprenticeshipRequest>();

            _mockValidator
            .Setup(validator => validator.ValidateAsync(invalidRequest, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ValidationResult(new List <ValidationFailure>
            {
                new ValidationFailure("stuff", errorMessage)
            }));

            var action = new Func <Task <CreateApprenticeshipResponse> >(() => _handler.Handle(invalidRequest));

            action.ShouldThrow <ValidationException>()
            .WithMessage($"Validation failed: \r\n -- {errorMessage}");
        }
        public async Task ThenTheApprenticeshipIsCreated()
        {
            await _handler.Handle(_validCommand);

            _commitmentApi.Verify(
                x =>
                x.CreateEmployerApprenticeship(_validCommand.AccountId, _validCommand.Apprenticeship.CommitmentId,
                                               It.Is <ApprenticeshipRequest>(
                                                   y =>
                                                   y.Apprenticeship == _validCommand.Apprenticeship && y.UserId == _validCommand.UserId && y.LastUpdatedByInfo.Name == _validCommand.UserDisplayName &&
                                                   y.LastUpdatedByInfo.EmailAddress == _validCommand.UserEmailAddress)));
        }
Exemplo n.º 4
0
        public async Task SetUp()
        {
            _fixture = new Fixture().Customize(new AutoMoqCustomization());

            _employerInformation = _fixture.Create <EmployerInformation>();
            _expectedRefNumber   = _fixture.Create <int>();
            _expectedParameters  = _fixture.Freeze <CreateApprenticeshipParameters>();
            _validRequest        = _fixture.Create <CreateApprenticeshipRequest>();

            _mockValidator = _fixture.Freeze <Mock <IValidator <CreateApprenticeshipRequest> > >(composer =>
                                                                                                 composer.Do(mock => mock
                                                                                                             .Setup(validator => validator.ValidateAsync(It.IsAny <CreateApprenticeshipRequest>(), It.IsAny <CancellationToken>()))
                                                                                                             .ReturnsAsync(new ValidationResult())));

            _mockVacancyOwnerService = _fixture.Freeze <Mock <IVacancyOwnerService> >(composer =>
                                                                                      composer.Do(mock => mock
                                                                                                  .Setup(svc => svc.GetEmployersInformationAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
                                                                                                  .ReturnsAsync(_employerInformation)));

            _mockMapper = _fixture.Freeze <Mock <ICreateApprenticeshipParametersMapper> >(composer =>
                                                                                          composer.Do(mock => mock
                                                                                                      .Setup(mapper => mapper.MapFromRequest(It.IsAny <CreateApprenticeshipRequest>(), It.IsAny <EmployerInformation>()))
                                                                                                      .Returns(_expectedParameters)));

            _mockService = _fixture.Freeze <Mock <ICreateApprenticeshipService> >(composer =>
                                                                                  composer.Do(mock => mock
                                                                                              .Setup(repository => repository.CreateApprenticeshipAsync(It.IsAny <CreateApprenticeshipParameters>()))
                                                                                              .ReturnsAsync(_expectedRefNumber)));

            _trainingDetails = new List <TrainingDetail>()
            {
                new TrainingDetail()
                {
                    TrainingCode = _validRequest.TrainingCode, Level = 1
                }
            };
            _mockTrainingDetailService = _fixture.Freeze <Mock <ITrainingDetailService> >(composer =>
                                                                                          composer.Do(mock =>
            {
                mock
                .Setup(svc => svc.GetAllFrameworkDetailsAsync())
                .ReturnsAsync(_trainingDetails);
                mock
                .Setup(svc => svc.GetAllStandardDetailsAsync())
                .ReturnsAsync(_trainingDetails);
            }));

            _handler = _fixture.Create <CreateApprenticeshipCommandHandler>();

            _createApprenticeshipResponse = await _handler.Handle(_validRequest);
        }
        public async Task ThenShouldCallTheRepositoryToCreateApprenticeship()
        {
            _mockCommitmentRespository.Setup(x => x.GetCommitmentById(It.IsAny <long>())).ReturnsAsync(new Commitment
            {
                Id         = _exampleValidRequest.CommitmentId,
                ProviderId = _exampleValidRequest.Caller.Id
            });

            await _handler.Handle(_exampleValidRequest);

            _mockApprenticeshipRepository.Verify(x =>
                                                 x.CreateApprenticeship(It.IsAny <Domain.Entities.Apprenticeship>()));
        }