Ejemplo n.º 1
0
        public void Arrange()
        {
            _legalEntityRepository = new Mock <ILegalEntityRepository>();
            _accountGateway        = new Mock <IAccountGateway>();

            _commandHandler = new CreateLegalEntityCommandHandler(_legalEntityRepository.Object, _accountGateway.Object);
        }
Ejemplo n.º 2
0
        public void Arrange()
        {
            _accountRepository    = new Mock <IAccountRepository>();
            _membershipRepository = new Mock <IMembershipRepository>();
            _mediator             = new Mock <IMediator>();

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green"
            };

            _agreementView = new EmployerAgreementView
            {
                AccountId                = _owner.AccountId,
                SignedDate               = DateTime.Now,
                SignedByName             = $"{_owner.FirstName} {_owner.LastName}",
                LegalEntityId            = 5246,
                LegalEntityName          = "Test Corp",
                LegalEntityCode          = "3476782638",
                LegalEntityAddress       = "12, test street",
                LegalEntityInceptionDate = DateTime.Now
            };

            _command = new CreateLegalEntityCommand
            {
                HashedAccountId = "ABC123",
                LegalEntity     = new LegalEntity(),
                SignAgreement   = true,
                SignedDate      = DateTime.Now.AddDays(-10),
                ExternalUserId  = "12345"
            };

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

            _accountRepository.Setup(x => x.CreateLegalEntity(_owner.AccountId, _command.LegalEntity))
            .ReturnsAsync(_agreementView);

            _genericEventFactory     = new Mock <IGenericEventFactory>();
            _legalEntityEventFactory = new Mock <ILegalEntityEventFactory>();

            _commandHandler = new CreateLegalEntityCommandHandler(
                _accountRepository.Object,
                _membershipRepository.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _legalEntityEventFactory.Object);
        }
        public virtual void Arrange()
        {
            Command = new CreateLegalEntityCommand
            {
                HashedAccountId = "ABC123",
                SignAgreement   = true,
                SignedDate      = DateTime.Now.AddDays(-10),
                ExternalUserId  = Guid.NewGuid().ToString(),
                Name            = "Org Ltd",
                Code            = "3476782638",
                Source          = OrganisationType.CompaniesHouse,
                Address         = "123 test street"
            };

            AccountRepository = new Mock <IAccountRepository>();
            AccountRepository.Setup(x => x.CreateLegalEntityWithAgreement(It.IsAny <CreateLegalEntityWithAgreementParams>())).ReturnsAsync(new EmployerAgreementView());

            MembershipRepository = new Mock <IMembershipRepository>();
            MembershipRepository.Setup(x => x.GetCaller(Command.HashedAccountId, Command.ExternalUserId)).ReturnsAsync(new MembershipView {
                UserRef = Guid.Parse(Command.ExternalUserId), AccountId = AccountId
            });

            Mediator                = new Mock <IMediator>();
            AuthorizationService    = new Mock <IAuthorizationService>();
            GenericEventFactory     = new Mock <IGenericEventFactory>();
            LegalEntityEventFactory = new Mock <ILegalEntityEventFactory>();
            HashingService          = new Mock <IHashingService>();
            AccountLegalEntityPublicHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            EmployerAgreementRepository            = new Mock <IEmployerAgreementRepository>();
            EventPublisher = new Mock <IEventPublisher>();

            Validator = new Mock <IValidator <CreateLegalEntityCommand> >();
            Validator.Setup(x => x.ValidateAsync(It.IsAny <CreateLegalEntityCommand>())).ReturnsAsync(new ValidationResult()
            {
                IsUnauthorized = false
            });

            CommandHandler = new CreateLegalEntityCommandHandler(
                AccountRepository.Object,
                MembershipRepository.Object,
                Mediator.Object,
                GenericEventFactory.Object,
                LegalEntityEventFactory.Object,
                EventPublisher.Object,
                HashingService.Object,
                AccountLegalEntityPublicHashingService.Object,
                EmployerAgreementRepository.Object,
                Validator.Object,
                AuthorizationService.Object
                );
        }
Ejemplo n.º 4
0
        public void Arrange()
        {
            _accountRepository    = new Mock <IAccountRepository>();
            _membershipRepository = new Mock <IMembershipRepository>();
            _mediator             = new Mock <IMediator>();

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

            _agreementView = new EmployerAgreementView
            {
                Id                       = 123,
                AccountId                = _owner.AccountId,
                SignedDate               = DateTime.Now,
                SignedByName             = $"{_owner.FirstName} {_owner.LastName}",
                LegalEntityId            = 5246,
                LegalEntityName          = "Test Corp",
                LegalEntityCode          = "3476782638",
                LegalEntitySource        = OrganisationType.CompaniesHouse,
                LegalEntityAddress       = "123 test street",
                LegalEntityInceptionDate = DateTime.Now,
                AccountLegalEntityId     = 830
            };

            _command = new CreateLegalEntityCommand
            {
                HashedAccountId = "ABC123",
                SignAgreement   = true,
                SignedDate      = DateTime.Now.AddDays(-10),
                ExternalUserId  = _owner.UserRef,
                Name            = "Org Ltd",
                Code            = "3476782638",
                Source          = OrganisationType.CompaniesHouse,
                Address         = "123 test street"
            };

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

            _accountRepository
            .Setup(x => x.CreateLegalEntityWithAgreement(It.Is <CreateLegalEntityWithAgreementParams>(
                                                             createParams => createParams.AccountId == _owner.AccountId)))
            .ReturnsAsync(_agreementView);

            _genericEventFactory     = new Mock <IGenericEventFactory>();
            _legalEntityEventFactory = new Mock <ILegalEntityEventFactory>();
            _eventPublisher          = new Mock <IEventPublisher>();
            _agreementService        = new Mock <IAgreementService>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(hs => hs.HashValue(It.IsAny <long>())).Returns <long>(value => $"*{value}*");
            _hashingService.Setup(hs => hs.DecodeValue(_command.HashedAccountId)).Returns(_owner.AccountId);

            _accountLegalEntityPublicHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            _accountLegalEntityPublicHashingService.Setup(x => x.HashValue(_agreementView.AccountLegalEntityId)).Returns(ExpectedAccountLegalEntityPublicHashString);

            _employerAgreementRepository = new Mock <IEmployerAgreementRepository>();

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

            _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateLegalEntityCommand>()))
            .ReturnsAsync(new ValidationResult()
            {
                IsUnauthorized = false
            });

            _commandHandler = new CreateLegalEntityCommandHandler(
                _accountRepository.Object,
                _membershipRepository.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _legalEntityEventFactory.Object,
                _eventPublisher.Object,
                _hashingService.Object,
                _accountLegalEntityPublicHashingService.Object,
                _agreementService.Object,
                _employerAgreementRepository.Object,
                _validator.Object
                );
        }