Ejemplo n.º 1
0
        public void Setup()
        {
            Fixture fixture = new Fixture();

            fixture.Customize <Apprenticeship>(ob => ob
                                               .With(x => x.ULN, ApprenticeshipTestDataHelper.CreateValidULN())
                                               );
            _validator = new CreateCommitmentValidator();
            var populatedCommitment = fixture.Build <Domain.Entities.Commitment>().Create();

            _exampleCommand = new CreateCommitmentCommand {
                Commitment = populatedCommitment
            };
        }
Ejemplo n.º 2
0
        public void Arrange()
        {
            _validator = new CreateCommitmentCommandValidator();

            _validCommand = new CreateCommitmentCommand
            {
                Commitment = new Commitment
                {
                    LegalEntityId     = "001",
                    LegalEntityName   = "Test Legal Entity Name",
                    EmployerAccountId = 2,
                    ProviderId        = 3,
                    ProviderName      = "Test provider"
                },
                UserId = "TestUser"
            };
        }
        public void Arrange()
        {
            _validator = new CreateCommitmentCommandValidator();

            _validCommand = new CreateCommitmentCommand
            {
                Commitment = new Commitment
                {
                    LegalEntityId          = "001",
                    LegalEntityName        = "Test Legal Entity Name",
                    EmployerAccountId      = 2,
                    ProviderName           = "Test provider",
                    EmployerLastUpdateInfo = new LastUpdateInfo {
                        Name = "Test User", EmailAddress = "*****@*****.**"
                    }
                }
            };
        }
Ejemplo n.º 4
0
        public void Arrange()
        {
            _validCommand = new CreateCommitmentCommand
            {
                Commitment = new Commitment
                {
                    ProviderId      = 1,
                    ProviderName    = "Test Provider",
                    LegalEntityId   = "2",
                    LegalEntityName = "Test Legal Entity"
                }
            };

            _validator = new Mock <IValidator <CreateCommitmentCommand> >();
            _validator.Setup(x => x.Validate(It.IsAny <CreateCommitmentCommand>())).Returns(new ValidationResult());

            _commitmentsApi = new Mock <IProviderCommitmentsApi>();
            _commitmentsApi.Setup(x => x.CreateProviderCommitment(It.IsAny <long>(), It.IsAny <CommitmentRequest>()))
            .ReturnsAsync(new CommitmentView());

            _handler = new CreateCommitmentCommandHandler(_commitmentsApi.Object, _validator.Object);
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            _mockCommitmentRespository = new Mock <ICommitmentRepository>();
            _mockHashingService        = new Mock <IHashingService>();
            var commandValidator = new CreateCommitmentValidator();

            _mockHistoryRepository = new Mock <IHistoryRepository>();
            _handler = new CreateCommitmentCommandHandler(_mockCommitmentRespository.Object,
                                                          _mockHashingService.Object,
                                                          commandValidator,
                                                          Mock.Of <ICommitmentsLogger>(),
                                                          _mockHistoryRepository.Object);

            Fixture fixture = new Fixture();

            fixture.Customize <Apprenticeship>(ob => ob
                                               .With(x => x.ULN, ApprenticeshipTestDataHelper.CreateValidULN())
                                               .With(x => x.NINumber, ApprenticeshipTestDataHelper.CreateValidNino())
                                               .With(x => x.FirstName, "First name")
                                               .With(x => x.FirstName, "Last name")
                                               .With(x => x.ProviderRef, "Provider ref")
                                               .With(x => x.EmployerRef, null)
                                               .With(x => x.StartDate, DateTime.Now.AddYears(5))
                                               .With(x => x.EndDate, DateTime.Now.AddYears(7))
                                               .With(x => x.DateOfBirth, DateTime.Now.AddYears(-16))
                                               .With(x => x.TrainingCode, string.Empty)
                                               .With(x => x.TrainingName, string.Empty)
                                               );
            _populatedCommitment = fixture.Build <Commitment>().Create();
            _populatedCommitment.Apprenticeships = new List <Apprenticeship>();

            _exampleValidRequest = new CreateCommitmentCommand
            {
                Commitment = _populatedCommitment,
                Caller     = new Caller(1L, CallerType.Employer),
                UserId     = "UserId"
            };
        }
Ejemplo n.º 6
0
        public async Task <string> CreateCohort(int providerId, ConfirmEmployerViewModel confirmEmployerViewModel, string userId, SignInUserModel signinUser)
        {
            Logger.Info($"Creating cohort", providerId);

            var employerAccountId = _publicHashingService.DecodeValue(confirmEmployerViewModel.EmployerAccountPublicHashedId);

            var relationshipData = await Mediator.Send(new GetProviderRelationshipsWithPermissionQueryRequest
            {
                Permission = Operation.CreateCohort,
                ProviderId = providerId
            });

            //Check that the relationship is a valid selection
            var relationship = relationshipData.ProviderRelationships.SingleOrDefault(x =>
                                                                                      x.AccountPublicHashedId == confirmEmployerViewModel.EmployerAccountPublicHashedId &&
                                                                                      x.AccountLegalEntityPublicHashedId == confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId
                                                                                      );

            if (relationship == null)
            {
                throw new InvalidOperationException(
                          $"Error creating cohort - operation not permitted for Provider: {providerId}, Employer Account {employerAccountId}, Legal Entity {confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId} ");
            }

            var providerResponse = await Mediator.Send(new GetProviderQueryRequest { UKPRN = providerId });

            var employerAccountHashedId = HashingService.HashValue(employerAccountId);

            var accountResponse = await Mediator.Send(new GetEmployerAccountLegalEntitiesRequest
            {
                UserId          = userId,
                HashedAccountId = employerAccountHashedId
            });

            var legalEntity = accountResponse.LegalEntities.SingleOrDefault(x =>
                                                                            x.AccountLegalEntityPublicHashedId ==
                                                                            confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId);

            if (legalEntity == null)
            {
                throw new InvalidOperationException(
                          $"Error getting Employer Account Legal entity for {confirmEmployerViewModel.EmployerAccountLegalEntityPublicHashedId}");
            }

            var createCommitmentRequest = new CreateCommitmentCommand
            {
                UserId     = userId,
                Commitment = new Commitment
                {
                    Reference                        = Guid.NewGuid().ToString().ToUpper(),
                    EmployerAccountId                = employerAccountId,
                    LegalEntityId                    = legalEntity.Code,
                    LegalEntityName                  = legalEntity.Name,
                    LegalEntityAddress               = legalEntity.RegisteredAddress,
                    LegalEntityOrganisationType      = (OrganisationType)legalEntity.Source,
                    AccountLegalEntityPublicHashedId = legalEntity.AccountLegalEntityPublicHashedId,
                    ProviderId                       = providerId,
                    ProviderName                     = providerResponse.ProvidersView.Provider.ProviderName,
                    CommitmentStatus                 = CommitmentStatus.New,
                    EditStatus                       = EditStatus.ProviderOnly,
                    ProviderLastUpdateInfo           = new LastUpdateInfo {
                        Name = signinUser.DisplayName, EmailAddress = signinUser.Email
                    }
                }
            };

            var response = await Mediator.Send(createCommitmentRequest);

            return(HashingService.HashValue(response.CommitmentId));
        }