private GetAccountLegalEntitiesResponse MockLegalEntitiesResponse(EmployerAgreementStatus v1,
                                                                          EmployerAgreementStatus v2)
        {
            var result = new GetAccountLegalEntitiesResponse
            {
                LegalEntities = new List <LegalEntity>
                {
                    new LegalEntity
                    {
                        Code       = "123",
                        Agreements = new List <Agreement>
                        {
                            new Agreement {
                                TemplateVersionNumber = 1, Status = v1
                            },
                            new Agreement {
                                TemplateVersionNumber = 2, Status = v2
                            }
                        }
                    }
                }
            };

            return(result);
        }
Beispiel #2
0
        public async Task ThenIfTheAgreementIsAlreadySignedThenTheRequestIsNotValid(EmployerAgreementStatus employerAgreementStatus)
        {
            //Arrange
            var employerAgreementId = 12345;
            var hashedAgreementId   = "123ASD";

            _hashingService.Setup(x => x.DecodeValue(hashedAgreementId)).Returns(employerAgreementId);
            _employerAgreementRepository.Setup(x => x.GetEmployerAgreement(employerAgreementId)).ReturnsAsync(new EmployerAgreementView {
                Status = employerAgreementStatus
            });

            //Act
            var actual = await _validator.ValidateAsync(new SignEmployerAgreementCommand
            {
                HashedAccountId   = "GHT432",
                ExternalUserId    = "123asd",
                SignedDate        = new DateTime(2016, 01, 01),
                HashedAgreementId = hashedAgreementId,
                OrganisationName  = "compName"
            });


            //Assert
            Assert.IsFalse(actual.IsValid());
        }
        public static string GetDescription(this EmployerAgreementStatus status)
        {
            var type                 = typeof(EmployerAgreementStatus);
            var memInfo              = type.GetMember(status.ToString());
            var attributes           = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
            var descriptionAttribute = attributes.OfType <DescriptionAttribute>().FirstOrDefault();

            return(descriptionAttribute?.Description ?? string.Empty);
        }
        public void ThenIfTheAgreementIsNotSignedThenAnErrorIsReturned(EmployerAgreementStatus status)
        {
            //Arrange
            _employerAgreementRepository.Setup(x => x.GetEmployerAgreement(ExpectedLegalAgreementId))
            .ReturnsAsync(new EmployerAgreementView {
                Status = status
            });

            //Act Assert
            Assert.ThrowsAsync <InvalidRequestException>(async() => await RequestHandler.Handle(Query));
        }
        public async Task ItShouldReturnTheMatchingAccountWithOutLegalEntitiesThatAreOutOfScope(
            EmployerAgreementStatus scope)
        {
            var id = "123";

            var accountResponse = new AccountDetailViewModel
            {
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel {
                        Href = "https://tempuri.org/legalEntity/{id}", Id = "ABC"
                    }
                })
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountResponse);

            var legalEntityResponse = new LegalEntityViewModel
            {
                AgreementStatus = scope
            };

            var legalEntity = accountResponse.LegalEntities[0];

            AccountApiClient.Setup(x => x.GetResource <LegalEntityViewModel>(legalEntity.Href))
            .ReturnsAsync(legalEntityResponse);

            var actual = await _sut.Get(id, AccountFieldsSelection.Organisations);


            Logger.Verify(
                x => x.Debug(
                    $"{nameof(IAccountApiClient)}.{nameof(IAccountApiClient.GetResource)}<{nameof(AccountDetailViewModel)}>(\"/api/accounts/{id}\");"),
                Times.Once);
            Logger.Verify(
                x => x.Debug(
                    $"{nameof(IAccountApiClient)}.{nameof(IAccountApiClient.GetResource)}<{nameof(LegalEntityViewModel)}>(\"{legalEntity.Href}\");"),
                Times.Once);

            AccountApiClient.Verify(x => x.GetResource <LegalEntityViewModel>(It.IsAny <string>()),
                                    Times.Exactly(accountResponse.LegalEntities.Count));

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.LegalEntities);
            Assert.AreEqual(0, actual.LegalEntities.Count());

            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.Transactions);
            Assert.IsNull(actual.TeamMembers);
        }
        public async Task ThenHasSignedAgreementIsCorrectlyDeterminedForTransfers(EmployerAgreementStatus v1,
                                                                                  EmployerAgreementStatus v2, bool expectHasSigned)
        {
            //Arrange
            MockMediator.Setup(x => x.SendAsync(It.IsAny <GetAccountLegalEntitiesRequest>()))
            .ReturnsAsync(MockLegalEntitiesResponse(v1, v2));

            //Act
            var result = await EmployerCommitmentOrchestrator.GetLegalEntitySignedAgreementViewModel("ABC123", "789FGH", "123", "C789", "123EDC");


            //Assert
            Assert.AreEqual(expectHasSigned, result.Data.HasSignedAgreement);
        }
        public async Task ThenHasSignedAgreementIsCorrectlyDeterminedForNonTransfers(EmployerAgreementStatus v1,
                                                                                     EmployerAgreementStatus v2, bool expectHasSigned)
        {
            //Arrange
            _commitmentView.TransferSender = null;

            MockMediator.Setup(x => x.SendAsync(It.IsAny <GetAccountLegalEntitiesRequest>()))
            .ReturnsAsync(MockLegalEntitiesResponse(v1, v2));

            //Act
            var result = await EmployerCommitmentOrchestrator.GetFinishEditingViewModel("ABC123", "XYZ123", "ABC321");

            //Assert
            Assert.AreEqual(expectHasSigned, result.Data.HasSignedTheAgreement);
        }
Beispiel #8
0
        public GetEmployerAgreementTestFixtures WithAgreement(
            long accountId,
            long legalEntityId,
            int agreementVersion,
            EmployerAgreementStatus status,
            out EmployerAgreement employerAgreement)
        {
            this.EmployerAgreementBuilder.WithAgreement(
                accountId,
                legalEntityId,
                agreementVersion,
                status,
                out employerAgreement);

            return(this);
        }
Beispiel #9
0
        public async Task Then_with_single_legal_entity_then_redirects_correctly(bool isTransfer, EmployerAgreementStatus status, int templateVersionNumber, ExpectedAction expectedAction)
        {
            //Arrange
            if (expectedAction == ExpectedAction.AgreementNotSigned)
            {
                _linkGeneratorResult = $"accounts/{_chooseOrganisationRequest.AccountHashedId}/apprentices/{LegalEntityCode}/AgreementNotSigned";
            }

            if (expectedAction == ExpectedAction.SelectProvider)
            {
                _linkGeneratorResult = $"accounts/{_chooseOrganisationRequest.AccountHashedId}/apprentices/provider/create";
            }

            _linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny <string>())).Returns(_linkGeneratorResult);
            _modelMapper.Setup(x => x.Map <SelectLegalEntityViewModel>(It.Is <SelectLegalEntityRequest>(r => r == _chooseOrganisationRequest)))
            .ReturnsAsync(new SelectLegalEntityViewModel
            {
                LegalEntities = new[] { new LegalEntity
                                        {
                                            Agreements = new List <Agreement> {
                                                new Agreement
                                                {
                                                    Status = status,
                                                    TemplateVersionNumber = templateVersionNumber
                                                }
                                            },
                                            Code = LegalEntityCode,
                                            Name = LegalEntityName
                                        } },
                CohortRef = CohortRefViewModel
            });

            //Act
            _chooseOrganisationRequest.transferConnectionCode = isTransfer ? _chooseOrganisationRequest.transferConnectionCode : string.Empty;
            var result = await _controller.SelectLegalEntity(_chooseOrganisationRequest);

            //Assert
            var redirectToActionResult = result as RedirectToActionResult;

            switch (expectedAction)
            {
            case ExpectedAction.AgreementNotSigned:
                Assert.AreEqual(expectedAction.ToString(), redirectToActionResult.ActionName);
                break;

            case ExpectedAction.SelectProvider:
                Assert.AreEqual(expectedAction.ToString(), redirectToActionResult.ActionName);
                break;

            default:
                throw new NotImplementedException();
            }
        }
        public EmployerFeatureAuthorisationHandlerTestsFixture SetMediatorResponse(int agreementVersion = AgreementVersion, EmployerAgreementStatus agreementStatus = EmployerAgreementStatus.Pending)
        {
            var response = new GetEmployerAgreementsByAccountIdResponse
            {
                EmployerAgreements = new List <EmployerAgreement>
                {
                    new EmployerAgreement
                    {
                        StatusId           = agreementStatus,
                        AccountLegalEntity = new AccountLegalEntity
                        {
                            SignedAgreementVersion  = agreementStatus == EmployerAgreementStatus.Signed ? (int?)agreementVersion : null,
                            PendingAgreementVersion = agreementStatus == EmployerAgreementStatus.Pending ? (int?)agreementVersion : null
                        }
                    }
                }
            };

            Mediator.Setup(s => s.SendAsync(It.Is <GetEmployerAgreementsByAccountIdRequest>(q => q.AccountId == AccountId))).ReturnsAsync(response);

            return(this);
        }
        public async Task WithSingleLegalEntityThenRedirectsCorrectly(bool isTransfer, EmployerAgreementStatus status, int templateVersionNumber, ExpectedAction expectedAction)
        {
            var transferConnectionCode = GetTransferConnectionCode(isTransfer);

            var response = new OrchestratorResponse <SelectLegalEntityViewModel>
            {
                Data = new SelectLegalEntityViewModel
                {
                    LegalEntities = new[] { new LegalEntity
                                            {
                                                Agreements = new List <Agreement> {
                                                    new Agreement
                                                    {
                                                        Status = status,
                                                        TemplateVersionNumber = templateVersionNumber
                                                    }
                                                },
                                                Code = LegalEntityCode,
                                                Name = LegalEntityName
                                            } },
                    CohortRef = CohortRefViewModel
                }
            };

            Orchestrator.Setup(o => o.GetLegalEntities(HashedAccountId, transferConnectionCode, CohortRefParam, null))
            .ReturnsAsync(response);

            var result = await Controller.SelectLegalEntity(HashedAccountId, transferConnectionCode);

            object expectedRouteValues;

            switch (expectedAction)
            {
            case ExpectedAction.AgreementNotSigned:
                expectedRouteValues = new { TransferConnectionCode = transferConnectionCode, HashedAccountId, LegalEntityCode, CohortRef = CohortRefViewModel, HasSignedAgreement = false, LegalEntityName };
                break;

            case ExpectedAction.SearchProvider:
                expectedRouteValues = new { TransferConnectionCode = transferConnectionCode, LegalEntityCode, CohortRef = CohortRefViewModel };
                break;

            default:
                throw new NotImplementedException();
            }

            AssertRedirectAction(result, expectedAction.ToString(), expectedRouteValues: expectedRouteValues);
        }
 public EmployerAgreementBuilder WithAgreement(long accountId, long legalEntityId, int agreementVersion, EmployerAgreementStatus status)
 {
     return(WithAgreement(accountId, legalEntityId, agreementVersion, status, out _));
 }
        public EmployerAgreementBuilder WithAgreement(long accountId, long legalEntityId, int agreementVersion, EmployerAgreementStatus status, out EmployerAgreement employerAgreement)
        {
            var template           = EnsureTemplate(agreementVersion);
            var accountLegalEntity = EnsureAccountLegalEntity(accountId, legalEntityId);

            employerAgreement = new EmployerAgreement
            {
                Id         = EmployerAgreements.Count + 1000, // offset from account Ids so that hashing mock won't get clashing ids
                Template   = template,
                TemplateId = template.Id,
                StatusId   = status
            };

            template.Agreements.Add(employerAgreement);

            return(WithAgreement(employerAgreement, accountLegalEntity));
        }