Esempio n. 1
0
        public static async Task Run([NServiceBusTrigger(EndPoint = QueueNames.AccountCreated)] CreatedAccountEvent message, [Inject] IAddAccountHandler handler, [Inject] ILogger <CreatedAccountEvent> log)
        {
            log.LogInformation($"NServiceBus AccountCreated trigger function executed at: {DateTime.Now} for ${message.AccountId}:${message.Name}");
            await handler.Handle(message);

            log.LogInformation($"NServiceBus AccountCreated trigger function finished at: {DateTime.Now} for ${message.AccountId}:${message.Name}");
        }
Esempio n. 2
0
        public async Task Then_The_Service_Is_Called_To_Add_The_Entity(
            CreatedAccountEvent createdAccountEvent,
            [Frozen] Mock <IAccountsService> service,
            AddAccountHandler handler
            )
        {
            //Act
            await handler.Handle(createdAccountEvent);

            //Assert
            service.Verify(x => x.CreateAccount(createdAccountEvent.AccountId, createdAccountEvent.Name));
        }
        public CreatedAccountEventHandlerForReadStoreTestsFixture()
        {
            ReadStoreMediator     = new Mock <IReadStoreMediator>();
            MessageHandlerContext = new Mock <IMessageHandlerContext>();
            MessageHandlerContext.Setup(x => x.MessageId).Returns(MessageId);

            Message = new CreatedAccountEvent
            {
                AccountId = AccountId,
                UserRef   = UserRef,
                Created   = Created
            };

            Handler = new CreatedAccountEventHandler(ReadStoreMediator.Object);
        }
        public async Task Then_The_Message_Will_Be_Handled()
        {
            //Arrange
            var handler = new Mock <IAddAccountHandler>();
            var message = new CreatedAccountEvent {
                AccountId = 1, Name = "Test"
            };

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

            //Assert
            handler.Verify(
                x => x.Handle(
                    It.Is <CreatedAccountEvent>(c => c.Name.Equals(message.Name) &&
                                                c.AccountId.Equals(message.AccountId))));
        }
        public async Task Run()
        {
            Guid userRef   = Guid.Parse("A777F6C7-87BF-42AD-B30A-2B27B9796B3F");
            long accountId = 2134;
            var  role      = UserRole.Viewer;

            var newUserEvent = new CreatedAccountEvent
            {
                AccountId = accountId,
                Name      = "Test User",
                UserRef   = userRef,
                Created   = DateTime.UtcNow
            };

            await _messageSession.Publish(newUserEvent);

            var updateUserEvent = new AccountUserRolesUpdatedEvent(accountId, userRef, role, DateTime.UtcNow);

            await _messageSession.Publish(updateUserEvent);

            var removeUserEvent = new AccountUserRemovedEvent(accountId, userRef, DateTime.UtcNow);

            await _messageSession.Publish(removeUserEvent);
        }
Esempio n. 6
0
 public async Task Handle(CreatedAccountEvent createdAccount)
 {
     await _accountsService.CreateAccount(createdAccount.AccountId, createdAccount.Name);
 }
Esempio n. 7
0
        public async Task <CreateAccountOutputDto> CreateAccount(CreateAccountInputDto request)
        {
            var businessExpection = new BusinessException();

            if ((await this.userRepository.GetAllByCriteria(UserSpecification.GetUserByEmail(request.Email))).Any())
            {
                businessExpection.AddError(new BusinessValidationFailure()
                {
                    ErrorMessage = "E-mail já cadastrado na base, por favor tente outro"
                });
            }

            if ((await this.userRepository.GetAllByCriteria(UserSpecification.GetUserByCPF(request.CPF))).Any())
            {
                businessExpection.AddError(new BusinessValidationFailure()
                {
                    ErrorMessage = "CPF já cadastrado na base, por favor tente outro"
                });
            }

            businessExpection.ValidateAndThrow();

            var user = this.mapper.Map <User>(request);

            user.ApplyStatus(Status.CONFIRMACAO_EMAIL);

            user.Validate();

            user.ApplyPassword();


            using (var transaction = await this.userRepository.CreateTransaction())
            {
                try
                {
                    var ms = ProxyUtils.DownloadFromUrl(String.Format(this.DefaultPhoto, Guid.NewGuid().ToString()));
                    user.Photo = await this.storage.SaveToStorage(AzureCloudImageDirectoryStorageEnum.USER, ms, String.Format("{0}.jpg", Guid.NewGuid().ToString().Replace("-", "")));

                    await this.userRepository.Save(user);

                    await transaction.CommitAsync();

                    var notification = new NotificationMessage(user.Email.Valor, new Message(new
                    {
                        Email    = user.Email.Valor,
                        FullName = user.Name,
                        Id       = user.Id
                    }));


                    CreatedAccountEvent accountEvent = new CreatedAccountEvent(CreatedAccountEvent.CREATE_ACCOUNT_EVENT, notification);

                    await this.EventPublisher.Publish <CreatedAccountEvent>(accountEvent);

                    return(this.mapper.Map <CreateAccountOutputDto>(user));
                }
                catch (Exception)
                {
                    await transaction.RollbackAsync();

                    throw;
                }
            }
        }