public async Task Then_If_The_Command_Is_Valid_And_The_RegisteredName_Is_Used_Then_Employer_Profile_Updated(
            Vacancy vacancy,
            CreateVacancyCommand command,
            TrainingProvider provider,
            EmployerProfile employerProfile,
            [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IMessaging> messaging,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            command.Vacancy.EmployerNameOption = EmployerNameOption.TradingName;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.GetVacancyAsync(command.Vacancy.Id)).ReturnsAsync(vacancy);
            recruitVacancyClient
            .Setup(x => x.GetEmployerProfileAsync(command.Vacancy.EmployerAccountId,
                                                  command.Vacancy.AccountLegalEntityPublicHashedId)).ReturnsAsync(employerProfile);

            await handler.Handle(command, CancellationToken.None);

            recruitVacancyClient.Verify(x => x.UpdateEmployerProfileAsync(It.Is <EmployerProfile>(c =>
                                                                                                  c.TradingName.Equals(command.Vacancy.EmployerName)
                                                                                                  ), It.IsAny <VacancyUser>()), Times.Once);
        }
        public async Task Then_If_Not_Valid_Then_Returns_Response_With_Errors(
            EntityValidationError entityValidationError,
            CreateVacancyCommand command,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            var entityValidationResult = new EntityValidationResult {
                Errors = new List <EntityValidationError> {
                    entityValidationError
                }
            };

            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(entityValidationResult);

            var actual = await handler.Handle(command, CancellationToken.None);

            actual.ValidationErrors.Should().BeEquivalentTo(
                entityValidationResult.Errors.Select(error => new DetailedValidationError
            {
                Field   = error.PropertyName,
                Message = error.ErrorMessage
            }));
            actual.ResultCode.Should().Be(ResponseCode.InvalidRequest);
        }
        public async Task Then_If_Provider_Owned_And_Employer_Has_To_Review_Then_Review_Event_Is_Submitted(
            Vacancy vacancy,
            CreateVacancyCommand command,
            TrainingProvider provider,
            [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IMessaging> messaging,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            [Frozen] Mock <IProviderRelationshipsService> providerRelationshipsService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            providerRelationshipsService.Setup(x => x.HasProviderGotEmployersPermissionAsync(
                                                   provider.Ukprn.Value, command.Vacancy.EmployerAccountId,
                                                   command.Vacancy.AccountLegalEntityPublicHashedId, OperationType.RecruitmentRequiresReview))
            .ReturnsAsync(true);
            command.VacancyUserDetails.Email = string.Empty;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.GetVacancyAsync(command.Vacancy.Id)).ReturnsAsync(vacancy);

            await handler.Handle(command, CancellationToken.None);

            messaging.Verify(x => x.PublishEvent(It.Is <VacancyReviewedEvent>(c =>
                                                                              c.VacancyId.Equals(command.Vacancy.Id) &&
                                                                              c.VacancyReference.Equals(vacancy.VacancyReference) &&
                                                                              c.Ukprn.Equals(provider.Ukprn)
                                                                              )));
        }
        public async Task And_ValidateOnly_True_And_Submitted_By_Employer_Then_Returns_After_Validation(
            CreateVacancyCommand command,
            TrainingProvider provider,
            Vacancy vacancy,
            DateTime timeNow,
            [Frozen] Mock <ITimeProvider> timeProvider,
            [Frozen] Mock <IProviderVacancyClient> providerVacancyClient,
            [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IVacancyRepository> vacancyRepository,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            [Frozen] Mock <IProviderRelationshipsService> providerRelationshipsService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = true;
            vacancy.Id           = command.Vacancy.Id;
            vacancy.ProgrammeId  = command.Vacancy.ProgrammeId;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());

            var actual = await handler.Handle(command, CancellationToken.None);

            actual.ResultCode.Should().Be(ResponseCode.Created);
            actual.Data.Should().Be(1000000001);
            employerVacancyClient.Verify(x => x.CreateEmployerApiVacancy(
                                             It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <VacancyUser>(), It.IsAny <TrainingProvider>(), It.IsAny <string>()),
                                         Times.Never);
            vacancyRepository.Verify(x => x.UpdateAsync(It.IsAny <Vacancy>()),
                                     Times.Never);
        }
Пример #5
0
        public void Then_If_There_Is_An_Error_From_The_Api_A_Exception_Is_Returned(
            string errorContent,
            CreateVacancyCommand command,
            GetProviderAccountLegalEntitiesResponse response,
            [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient,
            [Frozen] Mock <IRecruitApiClient <RecruitApiConfiguration> > recruitApiClient,
            CreateVacancyCommandHandler handler)
        {
            //Arrange
            command.PostVacancyRequestData.OwnerType = OwnerType.Provider;
            response.AccountProviderLegalEntities.First().AccountLegalEntityPublicHashedId = command.PostVacancyRequestData.AccountLegalEntityPublicHashedId;
            command.IsSandbox = false;
            var apiResponse = new ApiResponse <string>(null, HttpStatusCode.InternalServerError, errorContent);

            recruitApiClient
            .Setup(client => client.PostWithResponseCode <string>(It.IsAny <PostVacancyRequest>()))
            .ReturnsAsync(apiResponse);
            providerRelationshipsApiClient.Setup(x =>
                                                 x.Get <GetProviderAccountLegalEntitiesResponse>(It.IsAny <GetProviderAccountLegalEntitiesRequest>())).ReturnsAsync(response);

            //Act
            Func <Task> act = async() => await handler.Handle(command, CancellationToken.None);

            //Assert
            act.Should().Throw <Exception>()
            .WithMessage($"Response status code does not indicate success: {(int)HttpStatusCode.InternalServerError} ({HttpStatusCode.InternalServerError})");
        }
Пример #6
0
        public async Task And_IsSandbox_Then_Api_Called_To_Validate_Request(
            string responseValue,
            CreateVacancyCommand command,
            [Frozen] Mock <IRecruitApiClient <RecruitApiConfiguration> > mockRecruitApiClient,
            CreateVacancyCommandHandler handler)
        {
            //Arrange
            command.IsSandbox = true;
            var apiResponse = new ApiResponse <string>(responseValue, HttpStatusCode.Created, "");

            mockRecruitApiClient
            .Setup(x =>
                   x.PostWithResponseCode <string>(
                       It.Is <PostValidateVacancyRequest>(c =>
                                                          c.PostUrl.Contains($"{command.Id.ToString()}/validate?ukprn={command.PostVacancyRequestData.User.Ukprn}&userEmail={command.PostVacancyRequestData.User.Email}") &&
                                                          ((PostVacancyRequestData)c.Data).Title.Equals(command.PostVacancyRequestData.Title)
                                                          )))
            .ReturnsAsync(apiResponse);

            //Act
            var result = await handler.Handle(command, CancellationToken.None);

            //Assert
            result.VacancyReference.Should().Be(apiResponse.Body);
            mockRecruitApiClient.Verify(client => client.PostWithResponseCode <string>(It.IsAny <PostVacancyRequest>()),
                                        Times.Never);
        }
        public async Task Then_The_Command_Is_Validated_For_EmployerOwner(
            CreateVacancyCommand command,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;

            await handler.Handle(command, CancellationToken.None);

            recruitVacancyClient.Verify(x => x.Validate(command.Vacancy, VacancyRuleSet.All), Times.Once);
            recruitVacancyClient.Verify(x => x.Validate(It.Is <Vacancy>(c => c.OwnerType == OwnerType.Employer), VacancyRuleSet.All), Times.Once);
        }
        public async Task Then_If_The_Command_Is_Valid_The_Vacancy_Is_Created_And_Submitted_For_Provider(
            CreateVacancyCommand command,
            TrainingProvider provider,
            Vacancy vacancy,
            DateTime timeNow,
            [Frozen] Mock <ITimeProvider> timeProvider,
            [Frozen] Mock <IProviderVacancyClient> providerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IVacancyRepository> vacancyRepository,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            [Frozen] Mock <IProviderRelationshipsService> providerRelationshipsService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly             = false;
            command.VacancyUserDetails.Email = null;
            vacancy.Id          = command.Vacancy.Id;
            vacancy.ProgrammeId = command.Vacancy.ProgrammeId;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.GetVacancyAsync(command.Vacancy.Id)).ReturnsAsync(vacancy);
            timeProvider.Setup(x => x.Now).Returns(timeNow);
            providerRelationshipsService.Setup(x => x.HasProviderGotEmployersPermissionAsync(
                                                   provider.Ukprn.Value, command.Vacancy.EmployerAccountId,
                                                   command.Vacancy.AccountLegalEntityPublicHashedId, OperationType.RecruitmentRequiresReview))
            .ReturnsAsync(false);

            var actual = await handler.Handle(command, CancellationToken.None);

            actual.ResultCode.Should().Be(ResponseCode.Created);
            actual.Data.Should().Be(vacancy.VacancyReference);
            providerVacancyClient.Verify(x => x.CreateProviderApiVacancy(command.Vacancy.Id, command.Vacancy.Title,
                                                                         command.Vacancy.EmployerAccountId, command.VacancyUserDetails), Times.Once);
            vacancyRepository.Verify(x => x.UpdateAsync(It.Is <Vacancy>(c =>
                                                                        c.Id.Equals(command.Vacancy.Id) &&
                                                                        c.Status == VacancyStatus.Submitted &&
                                                                        c.VacancyReference == vacancy.VacancyReference &&
                                                                        c.CreatedByUser == vacancy.CreatedByUser &&
                                                                        c.Title == command.Vacancy.Title &&
                                                                        c.CreatedByUser == vacancy.CreatedByUser &&
                                                                        c.CreatedDate == vacancy.CreatedDate &&
                                                                        c.OwnerType == vacancy.OwnerType &&
                                                                        c.SourceOrigin == vacancy.SourceOrigin &&
                                                                        c.SourceType == vacancy.SourceType &&
                                                                        c.ProgrammeId == command.Vacancy.ProgrammeId &&
                                                                        c.SubmittedByUser == command.VacancyUserDetails &&
                                                                        c.LastUpdatedByUser == command.VacancyUserDetails &&
                                                                        c.SubmittedDate == timeNow &&
                                                                        c.LastUpdatedDate == timeNow &&
                                                                        c.TrainingProvider == provider
                                                                        )), Times.Once);
        }
        public async Task Then_The_Provider_Is_Looked_Up_And_Error_Returned_If_Not_Exists(
            CreateVacancyCommand command,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync((TrainingProvider)null);

            var actual = await handler.Handle(command, CancellationToken.None);

            actual.ResultCode.Should().Be(ResponseCode.InvalidRequest);
            actual.ValidationErrors.Should().Contain(error =>
                                                     ((DetailedValidationError)error).Field.Equals(nameof(command.VacancyUserDetails.Ukprn), StringComparison.InvariantCultureIgnoreCase) &&
                                                     ((DetailedValidationError)error).Message.Equals("Training Provider UKPRN not valid"));
        }
        public async Task Then_If_The_Employer_Vacancy_Has_Already_Been_Created_For_The_Given_Id_Then_Error_Returned(
            Exception mongoWriteException,
            CreateVacancyCommand command,
            [Frozen] Mock <IEmployerVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> vacancyClient,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            vacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.CreateEmployerApiVacancy(It.IsAny <Guid>(), It.IsAny <string>(),
                                                                       It.IsAny <string>(), It.IsAny <VacancyUser>(), It.IsAny <TrainingProvider>(), It.IsAny <string>()))
            .ThrowsAsync(mongoWriteException);

            var actual = await handler.Handle(command, CancellationToken.None);

            actual.ValidationErrors.Should().Contain(error =>
                                                     ((DetailedValidationError)error).Field.Equals(nameof(command.Vacancy.Id), StringComparison.InvariantCultureIgnoreCase) &&
                                                     ((DetailedValidationError)error).Message.Equals("Unable to create Vacancy. Vacancy already submitted"));
            actual.ResultCode.Should().Be(ResponseCode.InvalidRequest);
        }
Пример #11
0
        public async Task Then_If_The_Legal_Entity_Does_Not_Belong_To_The_Employer_Account_Exception_Thrown(
            string responseValue,
            CreateVacancyCommand command,
            AccountDetail accountDetailApiResponse,
            GetEmployerAccountLegalEntityItem leaglEntityResponse,
            [Frozen] Mock <IAccountLegalEntityPermissionService> accountLegalEntityPermissionService,
            [Frozen] Mock <IRecruitApiClient <RecruitApiConfiguration> > recruitApiClient,
            CreateVacancyCommandHandler handler)
        {
            command.PostVacancyRequestData.OwnerType = OwnerType.Employer;
            accountLegalEntityPermissionService
            .Setup(x => x.GetAccountLegalEntity(It.IsAny <AccountIdentifier>(), It.IsAny <string>()))
            .ReturnsAsync((AccountLegalEntityItem)null);

            //Act
            Assert.ThrowsAsync <SecurityException>(() => handler.Handle(command, CancellationToken.None));

            recruitApiClient.Verify(x =>
                                    x.PostWithResponseCode <string>(
                                        It.IsAny <PostVacancyRequest>()), Times.Never);
        }
        public async Task Then_If_The_Command_Is_Valid_A_Vacancy_Created_Event_Is_Submitted(
            Vacancy vacancy,
            CreateVacancyCommand command,
            TrainingProvider provider,
            [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IMessaging> messaging,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.GetVacancyAsync(command.Vacancy.Id)).ReturnsAsync(vacancy);

            await handler.Handle(command, CancellationToken.None);

            messaging.Verify(x => x.PublishEvent(It.Is <VacancySubmittedEvent>(c =>
                                                                               c.VacancyId.Equals(command.Vacancy.Id) &&
                                                                               c.VacancyReference.Equals(vacancy.VacancyReference)
                                                                               )));
        }
Пример #13
0
        public async Task Then_The_Command_Is_Handled_With_Account_Info_looked_Up_For_Provider_And_Api_Called_With_Response(
            int accountIdentifierId,
            string responseValue,
            CreateVacancyCommand command,
            AccountLegalEntityItem accountLegalEntityItem,
            [Frozen] Mock <IAccountLegalEntityPermissionService> accountLegalEntityPermissionService,
            [Frozen] Mock <IRecruitApiClient <RecruitApiConfiguration> > mockRecruitApiClient,
            CreateVacancyCommandHandler handler)
        {
            //Arrange
            command.AccountIdentifier = new AccountIdentifier($"Provider-{accountIdentifierId}-Product");
            command.IsSandbox         = false;
            var apiResponse = new ApiResponse <string>(responseValue, HttpStatusCode.Created, "");

            mockRecruitApiClient.Setup(x =>
                                       x.PostWithResponseCode <string>(
                                           It.Is <PostVacancyRequest>(c =>
                                                                      c.PostUrl.Contains($"{command.Id.ToString()}?ukprn={command.PostVacancyRequestData.User.Ukprn}&userEmail=") &&
                                                                      ((PostVacancyRequestData)c.Data).Title.Equals(command.PostVacancyRequestData.Title) &&
                                                                      ((PostVacancyRequestData)c.Data).LegalEntityName.Equals(accountLegalEntityItem.Name) &&
                                                                      ((PostVacancyRequestData)c.Data).EmployerAccountId.Equals(accountLegalEntityItem.AccountHashedId)
                                                                      )))
            .ReturnsAsync(apiResponse);
            accountLegalEntityPermissionService
            .Setup(x => x.GetAccountLegalEntity(It.Is <AccountIdentifier>(c => c.Equals(command.AccountIdentifier)),
                                                command.PostVacancyRequestData.AccountLegalEntityPublicHashedId))
            .ReturnsAsync(accountLegalEntityItem);

            //Act
            var result = await handler.Handle(command, CancellationToken.None);

            //Assert
            result.VacancyReference.Should().Be(apiResponse.Body);
            mockRecruitApiClient.Verify(client => client.PostWithResponseCode <string>(It.IsAny <PostValidateVacancyRequest>()),
                                        Times.Never);
        }