public void Arrange()
        {
            SetUp();

            Query = new GetEmployerAgreementPdfRequest {
                HashedAccountId = "123RED", HashedLegalAgreementId = "668YUT", UserId = "1234RFV"
            };

            _db = new Mock <EmployerAccountsDbContext>();
            var employerAgreement = new EmployerAgreement {
                Id = ExpectedEmployerAgreementId, Template = new AgreementTemplate {
                    PartialViewName = ExpectedAgreementFileName
                }
            };

            _employerAgreementDbSet = new DbSetStub <EmployerAgreement>(employerAgreement);
            _db.Setup(d => d.Agreements).Returns(_employerAgreementDbSet);

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue("668YUT")).Returns(ExpectedEmployerAgreementId);

            _pdfService = new Mock <IPdfService>();
            _pdfService.Setup(x => x.SubsituteValuesForPdf(It.IsAny <string>())).ReturnsAsync(new MemoryStream());

            RequestHandler = new GetEmployerAgreementPdfQueryHandler(RequestValidator.Object, _pdfService.Object, _hashingService.Object, new Lazy <EmployerAccountsDbContext>(() => _db.Object));
        }
        public Task GetLastSignedAgreement_IfRequestIsNotValid_DoNotGetAgreement()
        {
            User user = null;
            EmployerAgreement signedAgreement = null;

            return(RunAsync(
                       arrange: fixtures => fixtures
                       .WithInvalidRequest(),
                       act: fixtures => fixtures.Handle(AccountLegalEntityId),
                       assert: (f, r) => r.ShouldThrowExactly <InvalidRequestException>()));
        }
Esempio n. 3
0
        public Task GetAgreementToSign_IfNoSignedAgreementsExists_ShouldReturnNoSignedAgreement()
        {
            User user = null;
            EmployerAgreement pendingAgreement = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithPendingAgreement(AccountId, LegalEntityId, 3, out pendingAgreement)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, pendingAgreement.Id, user.Ref),
                       assert: fixtures => Assert.IsNull(fixtures.Response.LastSignedAgreement)));
        }
Esempio n. 4
0
        public Task GetAgreementToSign_IfRequestIsNotValid_DoNotShowAgreement()
        {
            User user = null;
            EmployerAgreement signedAgreement = null;

            return(this.TestExceptionAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithSignedAgreement(AccountId, LegalEntityId, 3, DateTime.Now.AddDays(-20), out signedAgreement)
                       .WithUser(AccountId, "Buck", "Rogers", out user).WithInvalidRequest(),
                       act: fixtures => fixtures.Handle(HashedAccountId, signedAgreement.Id, user.Ref),
                       assert: (f, r) => r.ShouldThrowExactly <InvalidRequestException>()));
        }
Esempio n. 5
0
        public Task GetAgreementToSign_IfAgreementHasNotBeenSigned_ShouldAddCurrentUserAsSigner()
        {
            User user = null;
            EmployerAgreement latestAgreement = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithPendingAgreement(AccountId, LegalEntityId, 2, out latestAgreement)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, latestAgreement.Id, user.Ref),
                       assert: fixtures => Assert.AreEqual(user.FullName, fixtures.Response.EmployerAgreement.SignedByName)));
        }
Esempio n. 6
0
 public GetEmployerAgreementTestFixtures WithPendingAgreement(
     long accountId,
     long legalEntityId,
     int agreementVersion,
     out EmployerAgreement employerAgreement)
 {
     this.EmployerAgreementBuilder.WithPendingAgreement(
         accountId,
         legalEntityId,
         agreementVersion,
         out employerAgreement);
     return(this);
 }
Esempio n. 7
0
        public Task GetAgreementToSign_ShouldReturnRequestedAgreement()
        {
            EmployerAgreement expectedAgreement = null;
            User user = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithAgreement(AccountId, LegalEntityId, 1, EmployerAgreementStatus.Pending, out expectedAgreement)
                       .WithAgreement(AccountId, LegalEntityId, 2, EmployerAgreementStatus.Pending, out _)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, expectedAgreement.Id, user.Ref),
                       assert: fixtures => Assert.AreEqual(expectedAgreement.Id, fixtures.Response.EmployerAgreement.Id)));
        }
Esempio n. 8
0
        public Task GetAgreementToSign_IfRequestAgreementIsSigned_ShouldNotReturnLatestSignedAgreementAsWell()
        {
            User user = null;
            EmployerAgreement latestAgreement = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithSignedAgreement(AccountId, LegalEntityId, 3, DateTime.Now.AddDays(-10), out latestAgreement)
                       .WithSignedAgreement(AccountId, LegalEntityId, 2, DateTime.Now.AddDays(-20), out _)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, latestAgreement.Id, user.Ref),
                       assert: fixtures => Assert.IsNull(fixtures.Response.LastSignedAgreement)));
        }
Esempio n. 9
0
        public Task ThenIfTheAgreementIsSignedThenAnyoneCanViewIt(Role role)
        {
            EmployerAgreement signedAgreement = null;
            User user = null;

            return(RunAsync(
                       arrange: fixtures => fixtures
                       .WithAccount(AccountId, HashedAccountId)
                       .WithSignedAgreement(AccountId, LegalEntityId, AccountLegalEntityId, 3, DateTime.Now.AddDays(-30), out signedAgreement)
                       .WithUser(AccountId, "Buck", "Rogers", role, out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, signedAgreement.Id, user.Ref),
                       assert: fixtures => Assert.AreEqual(signedAgreement.Id, fixtures.Response.EmployerAgreement.Id)));
        }
Esempio n. 10
0
        public Task GetAgreementToSign_IfSignedAgreementIfForAnotherAccount_ShouldNotReturnSignedAgreement()
        {
            User user = null;
            EmployerAgreement latestAgreement = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithAccount(AccountId + 1, "XXX123")
                       .WithPendingAgreement(AccountId, LegalEntityId, 3, out latestAgreement)
                       .WithSignedAgreement(AccountId + 1, LegalEntityId, 2, DateTime.Now.AddDays(-30), out _)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, latestAgreement.Id, user.Ref),
                       assert: fixtures => Assert.IsNull(fixtures.Response.LastSignedAgreement)));
        }
        public EmployerAgreementBuilder WithAgreement(EmployerAgreement employerAgreement, AccountLegalEntity accountLegalEntity)
        {
            employerAgreement.AccountLegalEntity   = accountLegalEntity;
            employerAgreement.AccountLegalEntityId = accountLegalEntity.Id;

            EmployerAgreements.Add(employerAgreement);

            accountLegalEntity.Agreements.Add(employerAgreement);

            var agreementHash = $"AGR{employerAgreement.Id:D3}";

            AddHash(employerAgreement.Id, agreementHash);
            return(this);
        }
Esempio n. 12
0
 public GetEmployerAgreementTestFixtures WithSignedAgreement(
     long accountId,
     long legalEntityId,
     int agreementVersion,
     DateTime signedTime,
     out EmployerAgreement employerAgreement)
 {
     this.EmployerAgreementBuilder.WithSignedAgreement(
         accountId,
         legalEntityId,
         agreementVersion,
         signedTime,
         out employerAgreement);
     return(this);
 }
        public Task GetLastSignedAgreement_ShouldReturnLatestSignedAgreement()
        {
            EmployerAgreement latestSignedAgreement = null;
            EmployerAgreement pendingAgreement      = null;
            User user = null;

            return(RunAsync(
                       arrange: fixtures => fixtures
                       .WithSignedAgreement(123354, 2, AccountLegalEntityId, 1, DateTime.Now.AddDays(-30), out latestSignedAgreement),
                       act: fixtures => fixtures.Handle(AccountLegalEntityId),
                       assert: fixtures =>
            {
                Assert.AreEqual(latestSignedAgreement.Id, fixtures.Response.LastSignedAgreement.Id);
            }));
        }
        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));
        }
Esempio n. 15
0
        private GetLegalEntityQueryTestsFixture AddLegalEntityAgreement(int versionNumber, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus status, long?signedUserId = null)
        {
            var newAgreement = new EmployerAgreement
            {
                Template = new AgreementTemplate
                {
                    VersionNumber = versionNumber,
                    AgreementType = AgreementType.Levy
                },
                StatusId   = status,
                SignedById = signedUserId
            };

            newAgreement.AccountLegalEntity   = AccountLegalEntity;
            newAgreement.AccountLegalEntityId = AccountLegalEntity.Id;
            AccountLegalEntity.Agreements.Add(newAgreement);

            return(this);
        }
Esempio n. 16
0
        public Task GetAgreementToSign_ShouldReturnLatestSignedAgreement()
        {
            EmployerAgreement latestSignedAgreement = null;
            EmployerAgreement pendingAgreement      = null;
            User user = null;

            return(this.TestAsync(
                       arrange: fixtures => fixtures.WithAccount(AccountId, HashedAccountId)
                       .WithSignedAgreement(AccountId, LegalEntityId, 1, DateTime.Now.AddDays(-60), out _)
                       .WithSignedAgreement(
                           AccountId,
                           LegalEntityId,
                           2,
                           DateTime.Now.AddDays(-30),
                           out latestSignedAgreement)
                       .WithPendingAgreement(AccountId, LegalEntityId, 3, out pendingAgreement)
                       .WithUser(AccountId, "Buck", "Rogers", out user),
                       act: fixtures => fixtures.Handle(HashedAccountId, pendingAgreement.Id, user.Ref),
                       assert: fixtures =>
            {
                Assert.AreEqual(pendingAgreement.Id, fixtures.Response.EmployerAgreement.Id);
                Assert.AreEqual(latestSignedAgreement.Id, fixtures.Response.LastSignedAgreement.Id);
            }));
        }
Esempio n. 17
0
        public GetEmployerAgreementTestFixtures WithAgreement(long accountId, long legalEntityId, long accountLegalEntityId, int agreementVersion, EmployerAgreementStatus status, out EmployerAgreement employerAgreement)
        {
            EmployerAgreementBuilder.WithAgreement(accountId, legalEntityId, accountLegalEntityId, agreementVersion, status, out employerAgreement);

            return(this);
        }
 public EmployerAgreementBuilder WithSignedAgreement(long accountId, long legalEntityId, int agreementVersion, DateTime signeDateTime, out EmployerAgreement employerAgreement)
 {
     WithAgreement(accountId, legalEntityId, agreementVersion, EmployerAgreementStatus.Signed, out employerAgreement);
     employerAgreement.SignedDate = signeDateTime;
     return(this);
 }
        public EmployerAgreementBuilder WithAgreement(EmployerAgreement employerAgreement, long accountId, long legalEntityId)
        {
            var accountLegalEntity = EnsureAccountLegalEntity(accountId, legalEntityId);

            return(WithAgreement(employerAgreement, accountLegalEntity));
        }
 public EmployerAgreementBuilder WithPendingAgreement(long accountId, long legalEntityId, int agreementVersion, out EmployerAgreement employerAgreement)
 {
     return(WithAgreement(accountId, legalEntityId, agreementVersion, EmployerAgreementStatus.Pending, out employerAgreement));
 }