Example #1
0
        public void Arrange()
        {
            _validator = new Mock <IValidator <RemoveLegalEntityCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <RemoveLegalEntityCommand>())).ReturnsAsync(new ValidationResult());

            _logger = new Mock <ILog>();

            _mediator = new Mock <IMediator>();

            _repository = new Mock <IEmployerAgreementRepository>();
            _repository.Setup(r => r.GetEmployerAgreement(ExpectedEmployerAgreementId))
            .ReturnsAsync(new EmployerAgreementView
            {
                AccountLegalEntityId = ExpectedAccountLegalEntityId,
                LegalEntityId        = ExpectedLegalEntityId,
                LegalEntityName      = ExpectedLegalEntityName,
                Status = EmployerAgreementStatus.Signed
            });

            _agreementService = new Mock <IAgreementService>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(ExpectedHashedAccountId)).Returns(ExpectedAccountId);
            _hashingService.Setup(x => x.DecodeValue(ExpectedHashedEmployerAgreementId)).Returns(ExpectedEmployerAgreementId);

            _employerAgreementEventFactory = new Mock <IEmployerAgreementEventFactory>();
            _employerAgreementEventFactory.Setup(x => x.RemoveAgreementEvent(ExpectedHashedEmployerAgreementId)).Returns(new AgreementRemovedEvent {
                HashedAgreementId = ExpectedHashedEmployerAgreementId
            });
            _genericEventHandler = new Mock <IGenericEventFactory>();
            _genericEventHandler.Setup(x => x.Create(It.Is <AgreementRemovedEvent>(c => c.HashedAgreementId.Equals(ExpectedHashedEmployerAgreementId)))).Returns(new GenericEvent {
                Payload = ExpectedHashedEmployerAgreementId
            });

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository
            .Setup(mr => mr.GetCaller(ExpectedAccountId, _expectedUserId))
            .Returns <long, string>((accountId, userRef) => Task.FromResult(new MembershipView {
                AccountId = ExpectedAccountId, FirstName = "Harry", LastName = "Potter"
            }));

            _eventPublisher = new Mock <IEventPublisher>();

            _command = new RemoveLegalEntityCommand {
                HashedAccountId = ExpectedHashedAccountId, UserId = _expectedUserId, HashedLegalAgreementId = ExpectedHashedEmployerAgreementId
            };

            _handler = new RemoveLegalEntityCommandHandler(
                _validator.Object,
                _logger.Object,
                _repository.Object,
                _mediator.Object,
                _hashingService.Object,
                _genericEventHandler.Object,
                _employerAgreementEventFactory.Object,
                _agreementService.Object,
                _membershipRepository.Object,
                _eventPublisher.Object);
        }
Example #2
0
        public void Arrange()
        {
            _validator = new Mock <IValidator <RemoveLegalEntityCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <RemoveLegalEntityCommand>())).ReturnsAsync(new ValidationResult());

            _logger = new Mock <ILog>();

            _mediator = new Mock <IMediator>();

            _repository = new Mock <IEmployerAgreementRepository>();
            _repository.Setup(r => r.GetAccountLegalEntityAgreements(ExpectedAccountLegalEntityId))
            .ReturnsAsync(new List <EmployerAgreement>
            {
                new EmployerAgreement
                {
                    AccountLegalEntityId = ExpectedAccountLegalEntityId,
                    TemplateId           = 1,
                    Id         = ExpectedEmployerAgreementId,
                    SignedDate = DateTime.Now
                }
            });

            _expectedAgreement = new EmployerAgreementView
            {
                AccountLegalEntityId = ExpectedAccountLegalEntityId,
                LegalEntityId        = ExpectedLegalEntityId,
                LegalEntityName      = ExpectedLegalEntityName,
                Status          = EmployerAgreementStatus.Signed,
                LegalEntityCode = "test_code"
            };

            _repository.Setup(r => r.GetEmployerAgreement(ExpectedEmployerAgreementId)).ReturnsAsync(_expectedAgreement);

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(ExpectedHashedAccountId)).Returns(ExpectedAccountId);
            _hashingService.Setup(x => x.DecodeValue(ExpectedHashedEmployerAgreementId)).Returns(ExpectedEmployerAgreementId);
            _hashingService.Setup(x => x.HashValue(ExpectedEmployerAgreementId)).Returns(ExpectedHashedEmployerAgreementId);

            _accountLegalEntityPublicHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            _accountLegalEntityPublicHashingService.Setup(x => x.DecodeValue(ExpectedHashedAccountLegalEntityId)).Returns(ExpectedAccountLegalEntityId);

            _employerAgreementEventFactory = new Mock <IEmployerAgreementEventFactory>();
            _employerAgreementEventFactory.Setup(x => x.RemoveAgreementEvent(ExpectedHashedEmployerAgreementId)).Returns(new AgreementRemovedEvent {
                HashedAgreementId = ExpectedHashedEmployerAgreementId
            });
            _genericEventHandler = new Mock <IGenericEventFactory>();
            _genericEventHandler.Setup(x => x.Create(It.Is <AgreementRemovedEvent>(c => c.HashedAgreementId.Equals(ExpectedHashedEmployerAgreementId)))).Returns(new GenericEvent {
                Payload = ExpectedHashedEmployerAgreementId
            });

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository
            .Setup(mr => mr.GetCaller(ExpectedAccountId, _expectedUserId))
            .Returns <long, string>((accountId, userRef) => Task.FromResult(new MembershipView {
                AccountId = ExpectedAccountId, FirstName = "Harry", LastName = "Potter"
            }));

            _eventPublisher = new Mock <IEventPublisher>();

            _commitmentsApi = new Mock <IEmployerCommitmentApi>();
            _commitmentsApi
            .Setup(x => x.GetEmployerAccountSummary(ExpectedAccountId))
            .ReturnsAsync(new List <ApprenticeshipStatusSummary>
            {
                new ApprenticeshipStatusSummary
                {
                    ActiveCount = 0, PausedCount = 0, PendingApprovalCount = 0, LegalEntityIdentifier = _expectedAgreement.LegalEntityCode
                }
            });

            _command = new RemoveLegalEntityCommand {
                HashedAccountId = ExpectedHashedAccountId, UserId = _expectedUserId, HashedAccountLegalEntityId = ExpectedHashedAccountLegalEntityId
            };

            _handler = new RemoveLegalEntityCommandHandler(
                _validator.Object,
                _logger.Object,
                _repository.Object,
                _mediator.Object,
                _accountLegalEntityPublicHashingService.Object,
                _hashingService.Object,
                _genericEventHandler.Object,
                _employerAgreementEventFactory.Object,
                _membershipRepository.Object,
                _eventPublisher.Object,
                _commitmentsApi.Object);
        }