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);
        }
コード例 #2
0
        public void Setup()
        {
            _membershipRepository = new Mock <IMembershipRepository>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(It.IsAny <string>())).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     = 56465
            };

            _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>();

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

            _command = new SignEmployerAgreementCommand
            {
                HashedAccountId   = "1AVCFD",
                HashedAgreementId = "2EQWE34",
                ExternalUserId    = Guid.NewGuid().ToString(),
                SignedDate        = DateTime.Now
            };

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

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