public async Task Then_The_Service_Is_Called_To_Add_The_Entity()
        {
            //Arrange
            _validator.Setup(x => x.ValidateAsync(It.IsAny <AddedLegalEntityEvent>()))
            .ReturnsAsync(new ValidationResult());

            var accountLegalEntityAddedEvent = new AddedLegalEntityEvent
            {
                AccountId            = 65,
                LegalEntityId        = 4434,
                OrganisationName     = "Test",
                AccountLegalEntityId = 5
            };

            //Act
            await _handler.Handle(accountLegalEntityAddedEvent);

            //Assert
            _service.Verify(x => x.AddAccountLegalEntity(It.Is <AddedLegalEntityEvent>(
                                                             c => c.AccountLegalEntityId.Equals(accountLegalEntityAddedEvent.AccountLegalEntityId) &&
                                                             c.AccountId.Equals(accountLegalEntityAddedEvent.AccountId) &&
                                                             c.LegalEntityId.Equals(accountLegalEntityAddedEvent.LegalEntityId) &&
                                                             c.OrganisationName.Equals(accountLegalEntityAddedEvent.OrganisationName)
                                                             )));
        }
예제 #2
0
        public static async Task Run([NServiceBusTrigger(EndPoint = QueueNames.LegalEntityAdded)] AddedLegalEntityEvent message, [Inject] IAddAccountLegalEntityHandler handler, [Inject] ILogger <AddedLegalEntityEvent> log)
        {
            log.LogInformation($"NServiceBus LegalEntityAdded trigger function executed at: {DateTime.Now} for ${message.AccountLegalEntityId}:${message.OrganisationName}");
            await handler.Handle(message);

            log.LogInformation($"NServiceBus LegalEntityAdded trigger function finished at: {DateTime.Now} for ${message.AccountLegalEntityId}:${message.OrganisationName}");
        }
예제 #3
0
 private AccountLegalEntity MapAccountLegalEntity(AddedLegalEntityEvent accountLegalEntity)
 {
     return(new AccountLegalEntity
     {
         Id = Guid.NewGuid(),
         AccountLegalEntityId = accountLegalEntity.AccountLegalEntityId,
         AccountId = accountLegalEntity.AccountId,
         LegalEntityId = accountLegalEntity.LegalEntityId,
         AccountLegalEntityName = accountLegalEntity.OrganisationName
     });
 }
        public Task RunEvent([NServiceBusTrigger(Endpoint = QueueNames.LegalEntityAdded)] AddedLegalEntityEvent message)
        {
            var addRequest = new AddRequest
            {
                AccountId            = message.AccountId,
                AccountLegalEntityId = message.AccountLegalEntityId,
                LegalEntityId        = message.LegalEntityId,
                OrganisationName     = message.OrganisationName
            };

            return(_legalEntitiesService.Add(addRequest));
        }
예제 #5
0
        public async Task Handle(AddedLegalEntityEvent accountLegalEntityAddedEvent)
        {
            var validationResult = await _validator.ValidateAsync(accountLegalEntityAddedEvent);

            if (validationResult.IsValid())
            {
                await _service.AddAccountLegalEntity(accountLegalEntityAddedEvent);
            }
            else
            {
                _logger.LogWarning($"Could not add legal entity to database because it is invalid for the following reasons: {validationResult}");
            }
        }
예제 #6
0
        public async Task Then_Message_Will_Be_Handled()
        {
            //Arrange
            var handler = new Mock <IAddAccountLegalEntityHandler>();
            var message = new AddedLegalEntityEvent {
                AccountId = 123
            };

            //Act
            await HandleAddedLegalEntityEvent.Run(message, handler.Object, Mock.Of <ILogger <AddedLegalEntityEvent> >());

            //Assert
            handler.Verify(s => s.Handle(It.Is <AddedLegalEntityEvent>(c => c.AccountId.Equals(message.AccountId))), Times.Once);
        }
 private bool B(AddedLegalEntityEvent e)
 {
     return(e.AccountId.Equals(_owner.AccountId) &&
            e.AgreementId.Equals(_agreementView.Id) &&
            e.LegalEntityId.Equals(_agreementView.LegalEntityId) &&
            e.AccountLegalEntityId.Equals(_agreementView.AccountLegalEntityId) &&
            e.AccountLegalEntityPublicHashedId.Equals(ExpectedAccountLegalEntityPublicHashString) &&
            e.OrganisationName.Equals(Command.Name) &&
            e.UserName.Equals(_owner.FullName()) &&
            e.UserRef.Equals(_owner.UserRef) &&
            e.OrganisationReferenceNumber.Equals(_agreementView.LegalEntityCode) &&
            e.OrganisationAddress.Equals(_agreementView.LegalEntityAddress) &&
            e.OrganisationType.ToString().Equals(_agreementView.LegalEntitySource.ToString()));
 }
        public async Task ThenIfHasNoOrganisationNameWillFailValidation()
        {
            //Arrange
            var validator = new AddAccountLegalEntityValidator();
            var @event    = new AddedLegalEntityEvent
            {
                AccountId            = 12,
                AccountLegalEntityId = 1,
                LegalEntityId        = 2
            };

            //Act
            var result = await validator.ValidateAsync(@event);

            //Assert
            Assert.IsFalse(result.IsValid());
            Assert.IsTrue(result.ValidationDictionary.ContainsKey(nameof(AddedLegalEntityEvent.OrganisationName)));
        }
        public async Task ThenIfValidWillPassValidation()
        {
            //Arrange
            var validator = new AddAccountLegalEntityValidator();
            var @event    = new AddedLegalEntityEvent
            {
                AccountId            = 12,
                AccountLegalEntityId = 1,
                LegalEntityId        = 2,
                OrganisationName     = "test"
            };

            //Act
            var result = await validator.ValidateAsync(@event);

            //Assert
            Assert.IsTrue(result.IsValid());
        }
예제 #10
0
        public AddedLegalEntityEventHandlerTestsFixture()
        {
            Message = new AddedLegalEntityEvent
            {
                AccountId                        = AccountId,
                UserRef                          = UserRef,
                Created                          = Created,
                AccountLegalEntityId             = AccountLegalEntityId,
                AccountLegalEntityPublicHashedId = AccountLegalEntityPublicHashedId,
                AgreementId                      = AgreementId,
                LegalEntityId                    = LegalEntityId,
                OrganisationAddress              = OrganisationAddress,
                OrganisationName                 = OrganisationName,
                OrganisationReferenceNumber      = OrganisationReferenceNumber,
                OrganisationType                 = OrganisationType,
                UserName                         = UserName
            };

            Mediator = new Mock <IMediator>();
            Handler  = new AddedLegalEntityEventHandler(Mediator.Object);
        }
        public async Task Then_The_Event_Is_Mapped_To_The_Entity_And_Repository_Called()
        {
            //Arrange
            var accountLegalEntityAddedEvent = new AddedLegalEntityEvent
            {
                AccountLegalEntityId = 23432,
                AccountId            = 9786,
                LegalEntityId        = 543,
                OrganisationName     = "Test Account"
            };

            //Act
            await _service.AddAccountLegalEntity(accountLegalEntityAddedEvent);

            //Assert
            _repository.Verify(x => x.Add(It.Is <AccountLegalEntity>(c =>
                                                                     !c.AgreementSigned &&
                                                                     c.AccountLegalEntityId.Equals(accountLegalEntityAddedEvent.AccountLegalEntityId) &&
                                                                     c.AccountId.Equals(accountLegalEntityAddedEvent.AccountId) &&
                                                                     c.AccountLegalEntityName.Equals(accountLegalEntityAddedEvent.OrganisationName) &&
                                                                     c.LegalEntityId.Equals(accountLegalEntityAddedEvent.LegalEntityId)
                                                                     )), Times.Once);
        }
        public async Task Then_The_Service_Is_Not_Called_If_Validation_Fails()
        {
            //Arrange
            _validator.Setup(x => x.ValidateAsync(It.IsAny <AddedLegalEntityEvent>()))
            .ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string> {
                    { "test", "error" }
                }
            });

            var accountLegalEntityAddedEvent = new AddedLegalEntityEvent
            {
                AccountId            = 65,
                LegalEntityId        = 4434,
                OrganisationName     = "Test",
                AccountLegalEntityId = 5
            };

            //Act
            await _handler.Handle(accountLegalEntityAddedEvent);

            //Assert
            _service.Verify(x => x.AddAccountLegalEntity(It.IsAny <AddedLegalEntityEvent>()), Times.Never());
        }
예제 #13
0
 public async Task AddAccountLegalEntity(AddedLegalEntityEvent accountLegalEntity)
 {
     await _repository.Add(MapAccountLegalEntity(accountLegalEntity));
 }