public void Arrange()
        {
            _accountRepository = new Mock <IPayeRepository>();

            _validator = new Mock <IValidator <RemovePayeFromAccountCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <RemovePayeFromAccountCommand>())).ReturnsAsync(new ValidationResult());

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(HashedAccountId)).Returns(AccountId);

            _mediator               = new Mock <IMediator>();
            _genericEventFactory    = new Mock <IGenericEventFactory>();
            _payeSchemeEventFactory = new Mock <IPayeSchemeEventFactory>();

            _eventPublisher           = new TestableEventPublisher();
            _mockMembershipRepository = new Mock <IMembershipRepository>();

            _mockMembershipRepository.Setup(a => a.GetCaller(It.IsAny <long>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new MembershipView {
                FirstName = UserFirstName, LastName = UserLastName, AccountId = AccountId, UserRef = UserRef.ToString()
            }));

            _handler = new RemovePayeFromAccountCommandHandler(
                _mediator.Object,
                _validator.Object,
                _accountRepository.Object,
                _hashingService.Object,
                _genericEventFactory.Object,
                _payeSchemeEventFactory.Object,
                _eventPublisher,
                _mockMembershipRepository.Object);
        }
Beispiel #2
0
        public void Arrange()
        {
            _levyRepository = new Mock <IDasLevyRepository>();
            _levyRepository.Setup(x => x.GetLastSubmissionForScheme(ExpectedEmpRef)).ReturnsAsync(new DasDeclaration {
                LevyDueYtd = 1000m, LevyAllowanceForFullYear = 1200m
            });

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

            _mediator = new Mock <IMediator>();

            _hmrcDateService = new Mock <IHmrcDateService>();
            _hmrcDateService.Setup(x => x.IsSubmissionForFuturePeriod(It.IsAny <string>(), It.IsAny <short>(), It.IsAny <DateTime>())).Returns(false);

            _currentDateTime = new Mock <ICurrentDateTime>();
            _currentDateTime.Setup(cdt => cdt.Now).Returns(() => DateTime.UtcNow);

            _levyEventFactory    = new Mock <ILevyEventFactory>();
            _genericEventFactory = new Mock <IGenericEventFactory>();
            _hashingService      = new Mock <IHashingService>();
            _logger                    = new Mock <ILog>();
            _eventPublisher            = new TestableEventPublisher();
            _levyImportCleanerStrategy = new LevyImportCleanerStrategy(_levyRepository.Object, _hmrcDateService.Object, _logger.Object, _currentDateTime.Object);

            _refreshEmployerLevyDataCommandHandler = new RefreshEmployerLevyDataCommandHandler(_validator.Object, _levyRepository.Object, _mediator.Object,
                                                                                               _levyEventFactory.Object, _genericEventFactory.Object, _hashingService.Object, _levyImportCleanerStrategy, _eventPublisher);
        }
Beispiel #3
0
        public RefreshPaymentDataCommandHandlerTestsFixture()
        {
            _dasLevyRepository = new Mock <IDasLevyRepository>();
            var logger   = new Mock <ILog>();
            var mediator = new Mock <IMediator>();

            _paymentService = new Mock <IPaymentService>();
            var validator = new Mock <IValidator <RefreshPaymentDataCommand> >();

            eventPublisher = new TestableEventPublisher();

            validator.Setup(x => x.Validate(It.IsAny <RefreshPaymentDataCommand>()))
            .Returns(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });


            _handler = new RefreshPaymentDataCommandHandler(
                eventPublisher,
                validator.Object,
                _paymentService.Object,
                _dasLevyRepository.Object,
                mediator.Object,
                logger.Object);
        }
Beispiel #4
0
        public void Arrange()
        {
            _command = new RenameEmployerAccountCommand
            {
                HashedAccountId = HashedAccountId,
                NewName         = "Renamed account"
            };

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                UserRef   = Guid.NewGuid().ToString(),
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green"
            };

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(_owner);

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(It.Is <string>(s => s == HashedAccountId)))
            .Returns(AccountId);

            _repository = new Mock <IEmployerAccountRepository>();
            _repository.Setup(x => x.GetAccountById(It.IsAny <long>()))
            .ReturnsAsync(new Account
            {
                Id       = AccountId,
                HashedId = HashedAccountId,
                Name     = AccountName
            });

            _validator = new Mock <IValidator <RenameEmployerAccountCommand> >();

            _validator.Setup(x => x.ValidateAsync(It.IsAny <RenameEmployerAccountCommand>()))
            .ReturnsAsync(new ValidationResult());

            _mediator            = new Mock <IMediator>();
            _genericEventFactory = new Mock <IGenericEventFactory>();
            _accountEventFactory = new Mock <IAccountEventFactory>();
            _eventPublisher      = new TestableEventPublisher();

            _commandHandler = new RenameEmployerAccountCommandHandler(
                _eventPublisher,
                _repository.Object,
                _membershipRepository.Object,
                _validator.Object,
                _hashingService.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _accountEventFactory.Object);
        }
Beispiel #5
0
        public void Arrange()
        {
            _command = new RefreshPaymentDataCommand
            {
                AccountId = AccountId,
                PeriodEnd = PeriodEnd
            };

            _existingPaymentIds = new List <Guid>
            {
                Guid.NewGuid(),
                    Guid.NewGuid(),
                    Guid.NewGuid()
            };

            _validator = new Mock <IValidator <RefreshPaymentDataCommand> >();
            _validator.Setup(x => x.Validate(It.IsAny <RefreshPaymentDataCommand>()))
            .Returns(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });

            _dasLevyRepository = new Mock <IDasLevyRepository>();
            _dasLevyRepository.Setup(x => x.GetAccountPaymentIds(It.IsAny <long>()))
            .ReturnsAsync(new HashSet <Guid>(_existingPaymentIds));

            _paymentDetails = new List <PaymentDetails> {
                new PaymentDetails
                {
                    Id                = Guid.NewGuid(),
                    Amount            = Amount,
                    EmployerAccountId = AccountId,
                    ProviderName      = ProviderName
                }
            };

            _paymentService = new Mock <IPaymentService>();
            _paymentService.Setup(x => x.GetAccountPayments(It.IsAny <string>(), It.IsAny <long>()))
            .ReturnsAsync(_paymentDetails);

            _mediator       = new Mock <IMediator>();
            _logger         = new Mock <ILog>();
            _eventPublisher = new TestableEventPublisher();

            _handler = new RefreshPaymentDataCommandHandler(
                _eventPublisher,
                _validator.Object,
                _paymentService.Object,
                _dasLevyRepository.Object,
                _mediator.Object,
                _logger.Object);
        }
Beispiel #6
0
        public void Setup()
        {
            _invitation = new Invitation
            {
                Id         = 1,
                AccountId  = 101,
                Email      = "*****@*****.**",
                Status     = InvitationStatus.Pending,
                ExpiryDate = DateTimeProvider.Current.UtcNow.AddDays(2),
                Role       = Role.Owner,
                Name       = "Bob Green"
            };

            _invitationRepository  = new Mock <IInvitationRepository>();
            _membershipRepository  = new Mock <IMembershipRepository>();
            _userAccountRepository = new Mock <IUserAccountRepository>();
            _auditService          = new Mock <IAuditService>();
            _eventPublisher        = new TestableEventPublisher();
            _validator             = new Mock <IValidator <AcceptInvitationCommand> >();
            _hashingService        = new Mock <IHashingService>();

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

            _membershipRepository.Setup(x => x.GetCaller(It.IsAny <long>(), It.IsAny <string>())).ReturnsAsync(() => null);

            _invitationRepository.Setup(x => x.Get(It.IsAny <long>())).ReturnsAsync(_invitation);
            _userAccountRepository.Setup(x => x.Get(It.IsAny <string>())).ReturnsAsync(new User {
                UserRef = Guid.NewGuid().ToString()
            });

            _handler = new AcceptInvitationCommandHandler(
                _invitationRepository.Object,
                _membershipRepository.Object,
                _userAccountRepository.Object,
                _auditService.Object,
                _eventPublisher,
                _validator.Object,
                _hashingService.Object,
                Mock.Of <ILog>());
        }
Beispiel #7
0
        public void Arrange()
        {
            _eventPublisher = new TestableEventPublisher();

            _accountRepository = new Mock <IPayeRepository>();

            _validator = new Mock <IValidator <AddPayeToAccountCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <AddPayeToAccountCommand>())).ReturnsAsync(new ValidationResult());

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(It.IsAny <string>())).Returns(ExpectedAccountId);

            _mediator               = new Mock <IMediator>();
            _genericEventFactory    = new Mock <IGenericEventFactory>();
            _payeSchemeEventFactory = new Mock <IPayeSchemeEventFactory>();

            _refreshEmployerLevyService = new Mock <IRefreshEmployerLevyService>();

            _addPayeToAccountCommandHandler = new AddPayeToAccountCommandHandler(
                _validator.Object,
                _accountRepository.Object,
                _eventPublisher,
                _hashingService.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _payeSchemeEventFactory.Object,
                _refreshEmployerLevyService.Object);

            _user = new User
            {
                FirstName = "Bob",
                LastName  = "Green",
                Ref       = Guid.NewGuid()
            };

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetUserByRefQuery>()))
            .ReturnsAsync(new GetUserByRefResponse {
                User = _user
            });
        }
Beispiel #8
0
        public RefreshEmployerLevyDataCommandHandlerTestsFixture()
        {
            _dasLevyRepository = new Mock <IDasLevyRepository>();
            var genericEventFactory = new Mock <IGenericEventFactory>();
            var hashingService      = new Mock <IHashingService>();
            var levyEventFactory    = new Mock <ILevyEventFactory>();
            var logger   = new Mock <ILog>();
            var mediator = new Mock <IMediator>();

            _eventPublisher  = new TestableEventPublisher();
            _currentDateTime = new Mock <ICurrentDateTime>();
            _currentDateTime.Setup(cdt => cdt.Now).Returns(() => DateTime.UtcNow);
            var validator = new Mock <IValidator <RefreshEmployerLevyDataCommand> >();

            validator.Setup(x => x.Validate(It.IsAny <RefreshEmployerLevyDataCommand>())).Returns(new ValidationResult());

            _hmrcDateService = new Mock <IHmrcDateService>();

            var levyImportCleanerStrategy = new LevyImportCleanerStrategy(_dasLevyRepository.Object, _hmrcDateService.Object, logger.Object, _currentDateTime.Object);

            _handler = new RefreshEmployerLevyDataCommandHandler(validator.Object, _dasLevyRepository.Object, mediator.Object,
                                                                 levyEventFactory.Object, genericEventFactory.Object, hashingService.Object, levyImportCleanerStrategy, _eventPublisher);
        }
Beispiel #9
0
        public void Arrange()
        {
            _accountRepository = new Mock <IAccountRepository>();
            _accountRepository.Setup(x => x.GetPayeSchemesByAccountId(ExpectedAccountId)).ReturnsAsync(new List <PayeView> {
                new PayeView {
                    LegalEntityId = ExpectedLegalEntityId
                }
            });
            _accountRepository.Setup(x => x.CreateAccount(It.IsAny <CreateAccountParams>())).ReturnsAsync(new CreateAccountResult {
                AccountId = ExpectedAccountId, LegalEntityId = ExpectedLegalEntityId, EmployerAgreementId = ExpectedEmployerAgreementId, AccountLegalEntityId = ExpectedAccountLegalEntityId
            });

            _eventPublisher = new TestableEventPublisher();
            _mediator       = new Mock <IMediator>();

            _user = new User {
                Id = 33, FirstName = "Bob", LastName = "Green", Ref = Guid.NewGuid()
            };

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetUserByRefQuery>()))
            .ReturnsAsync(new GetUserByRefResponse {
                User = _user
            });

            _validator = new Mock <IValidator <CreateAccountCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateAccountCommand>())).ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.HashValue(ExpectedAccountId)).Returns(ExpectedHashString);

            _externalhashingService = new Mock <IPublicHashingService>();
            _externalhashingService.Setup(x => x.HashValue(ExpectedAccountId)).Returns(ExpectedPublicHashString);

            _accountLegalEntityHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            _accountLegalEntityHashingService.Setup(x => x.HashValue(ExpectedAccountLegalEntityId)).Returns(ExpectedAccountLegalEntityPublicHashString);

            _genericEventFactory = new Mock <IGenericEventFactory>();
            _accountEventFactory = new Mock <IAccountEventFactory>();

            _mockAuthorizationService = new Mock <IAuthorizationService>();
            _mockAuthorizationService.Setup(x => x.IsAuthorized("EmployerFeature.ExpressionOfInterest")).Returns(false);

            _mockMembershipRepository = new Mock <IMembershipRepository>();
            _mockMembershipRepository.Setup(r => r.GetCaller(It.IsAny <long>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new MembershipView()
            {
                FirstName = _user.FirstName, LastName = _user.LastName
            }));

            _mockEmployerAgreementRepository = new Mock <IEmployerAgreementRepository>();

            _handler = new CreateAccountCommandHandler(
                _accountRepository.Object,
                _mediator.Object,
                _validator.Object,
                _hashingService.Object,
                _externalhashingService.Object,
                _accountLegalEntityHashingService.Object,
                _genericEventFactory.Object,
                _accountEventFactory.Object,
                _mockMembershipRepository.Object,
                _mockEmployerAgreementRepository.Object,
                _eventPublisher,
                _mockAuthorizationService.Object);
        }
        public void Setup()
        {
            _command = new SignEmployerAgreementCommand
            {
                HashedAccountId   = "1AVCFD",
                HashedAgreementId = "2EQWE34",
                ExternalUserId    = Guid.NewGuid().ToString(),
                SignedDate        = DateTime.Now
            };

            _membershipRepository = new Mock <IMembershipRepository>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(_command.HashedAccountId)).Returns(AccountId);
            _hashingService.Setup(x => x.DecodeValue(_command.HashedAgreementId)).Returns(AgreementId);
            _hashingService.Setup(x => x.HashValue(It.IsAny <long>())).Returns(HashedLegalEntityId);

            _validator = new Mock <IValidator <SignEmployerAgreementCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <SignEmployerAgreementCommand>())).ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });


            _agreement = new EmployerAgreementView
            {
                HashedAgreementId    = "124GHJG",
                LegalEntityId        = LegalEntityId,
                LegalEntityName      = OrganisationName,
                AgreementType        = AgreementType,
                AccountId            = AccountId,
                AccountLegalEntityId = AccountLegalEntityId,
                Id = AgreementId
            };

            _agreementRepository = new Mock <IEmployerAgreementRepository>();

            _agreementRepository.Setup(x => x.GetEmployerAgreement(It.IsAny <long>()))
            .ReturnsAsync(_agreement);

            _agreementEventFactory = new Mock <IEmployerAgreementEventFactory>();

            _agreementEvent = new AgreementSignedEvent();

            _agreementEventFactory.Setup(
                x => x.CreateSignedEvent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(_agreementEvent);

            _genericEventFactory = new Mock <IGenericEventFactory>();
            _mediator            = new Mock <IMediator>();

            _mediator.Setup(x => x.SendAsync(It.Is <GetUserByRefQuery>(s => s.UserRef == _command.ExternalUserId))).ReturnsAsync(new GetUserByRefResponse {
                User = new User {
                    CorrelationId = "CORRELATION_ID"
                }
            });

            _commintmentService = new Mock <ICommitmentService>();

            _commintmentService.Setup(x => x.GetEmployerCommitments(It.IsAny <long>()))
            .ReturnsAsync(new List <Cohort>());

            _eventPublisher = new TestableEventPublisher();

            _handler = new SignEmployerAgreementCommandHandler(
                _membershipRepository.Object,
                _agreementRepository.Object,
                _hashingService.Object,
                _validator.Object,
                _agreementEventFactory.Object,
                _genericEventFactory.Object,
                _mediator.Object,
                _eventPublisher,
                _commintmentService.Object);

            _owner = new MembershipView
            {
                UserId    = 1,
                Role      = Role.Owner,
                FirstName = "Fred",
                LastName  = "Bloggs",
                UserRef   = Guid.NewGuid()
            };

            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId))
            .ReturnsAsync(_owner);
        }