Пример #1
0
        public void DeveAdicionarUmaNotification()
        {
            var notificationBuilder = new DomainNotificationBuilder()
                                      .Comkey("Id")
                                      .ComValue("Id inválido")
                                      .Instanciar();

            _domainNotification.Handle(notificationBuilder, default);

            _domainNotification.GetNotifications().Should().NotBeNull();
            _domainNotification.GetNotifications().Should().HaveCount(1);
            _domainNotification.GetNotifications().Should().BeEquivalentTo(notificationBuilder);
            _domainNotification.HasNotifications().Should().BeTrue();
        }
Пример #2
0
        public Task Handle(RegistrarLancamentoCommand request, CancellationToken cancellationToken)
        {
            var obterContaCorrente = _contaCorrenteRepository.GetEntity(x => x.NumeroConta == request.NumeroConta);

            if (obterContaCorrente == null)
            {
                _notifications.Handle(new DomainNotification("Lancamento", "Conta Corrente Inexistente"), cancellationToken);
                return(Task.CompletedTask);
            }

            var obterUltimoLancamento = _lancamentoRepository.ObterUltimoLancamento(obterContaCorrente.Id);
            var lancamento            = new Model.Lancamentos();

            if (obterUltimoLancamento == null)
            {
                lancamento = Model.Lancamentos.LancamentosFactory.NovoLancamentos(request.Valor, request.TipoOperacao, request.Valor, DateTime.Now, obterContaCorrente.Id);
            }
            else
            {
                var saldoAtualizado = request.TipoOperacao == Enum.TipoOperacao.CREDITO ? obterUltimoLancamento.Saldo + request.Valor : obterUltimoLancamento.Saldo - request.Valor;
                lancamento = Model.Lancamentos.LancamentosFactory.NovoLancamentos(request.Valor, request.TipoOperacao, saldoAtualizado, DateTime.Now, obterContaCorrente.Id);
            }

            if (!lancamento.EhValido())
            {
                NotificarValidacoesErro(lancamento.ValidationResult);
                return(Task.CompletedTask);
            }

            _lancamentoRepository.Add(lancamento);

            Commit();

            return(Task.CompletedTask);
        }
Пример #3
0
 protected void NotificarValidacoesErro(ValidationResult validationResult)
 {
     foreach (var error in validationResult.Errors)
     {
         _notifications.Handle(new DomainNotification(error.PropertyName, error.ErrorMessage), new System.Threading.CancellationToken());
     }
 }
Пример #4
0
        protected Task NotifyError(string code, string message)
        {
            var cancellationToken = new CancellationToken();
            var task = Task.Run(async() => await _notifications.Handle(new DomainNotification(code, message), cancellationToken));

            task.Wait();
            return(Task.CompletedTask);
        }
Пример #5
0
        public Task RaiseEvent <T>(T @event) where T : Event
        {
            if (@event.MessageType == "DomainNotification")
            {
                _domainNotificationHandler.Handle(@event as DomainNotification, CancellationToken.None);
            }

            return(Task.FromResult(true));
        }
Пример #6
0
 public void InitTests()
 {
     _mockMediator = new Mock <IMediatorHandler>();
     _domainNotificationHandler = new DomainNotificationHandler();
     _mockMediator.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())).Callback <DomainNotification>((x) =>
     {
         _domainNotificationHandler.Handle(x, CancellationToken.None);
     });
 }
        public async void DomainNotificationClear_Ok()
        {
            var faker = new Faker();


            var handler = new DomainNotificationHandler();


            var qtError   = faker.Random.Int(min: 3, max: 10);
            var qtSuccess = faker.Random.Int(min: 3, max: 10);


            for (var i = 0; i < qtError; i++)
            {
                var message = faker.Lorem.Sentence();

                var domainNotification = DomainNotification.Fail(message);
                await handler.Handle(domainNotification, new CancellationToken());
            }

            for (var i = 0; i < qtSuccess; i++)
            {
                var message = faker.Lorem.Sentence();

                var domainNotification = DomainNotification.Success(message);
                await handler.Handle(domainNotification, new CancellationToken());
            }

            handler.Clear();

            var notificationsError   = handler.GetNotificationsError();
            var notificationsSuccess = handler.GetNotificationsSuccess();

            Assert.False(handler.HasNotificationsError());
            Assert.False(handler.HasNotificationsSucess());


            Assert.True(notificationsError.Count == 0);
            Assert.True(notificationsSuccess.Count == 0);
        }
Пример #8
0
        private Task ValidaEntrada(AnaliseCreditoRequest analiseCreditoResquest)
        {
            if (analiseCreditoResquest.QuantidadeParcelas < 5)
            {
                _notifications.Handle(new DomainNotification("Parcelas", "O valor minimo de parcelas é de 5"), new System.Threading.CancellationToken());
            }

            if (analiseCreditoResquest.QuantidadeParcelas > 72)
            {
                _notifications.Handle(new DomainNotification("Parcelas", "O valor maximo de parcelas é de 72"), new System.Threading.CancellationToken());
            }

            if (analiseCreditoResquest.ValorCredito > 1000000)
            {
                _notifications.Handle(new DomainNotification("Valor Credito", "O valor máximo de emprestimo é de R$1.000.000,00"), new System.Threading.CancellationToken());
            }

            if (analiseCreditoResquest.DataVencimento < DateTime.Now.AddDays(15))
            {
                _notifications.Handle(new DomainNotification("Data Vencimento", "Data de vencimento deve ser acima de 15 dias a partir de hoje"), new System.Threading.CancellationToken());
            }

            if (analiseCreditoResquest.DataVencimento > DateTime.Now.AddDays(40))
            {
                _notifications.Handle(new DomainNotification("Data Vencimento", "Data de vencimento deve ser inferior a 40 dias a partir de hoje"), new System.Threading.CancellationToken());
            }

            if (analiseCreditoResquest.TipoCredito == Enum.TipoCreditoTaxa.PJ && analiseCreditoResquest.ValorCredito < 15000)
            {
                _notifications.Handle(new DomainNotification("Valor Credito", "O valor mínimo de emprestimo para PJ é R$15.000,00"), new System.Threading.CancellationToken());
            }

            return(Task.CompletedTask);
        }
        public Task <Unit> Handle(NewAirplaneCommand command)
        {
            if (!command.IsValid())
            {
                command.ValidationResult.Errors.ToList().ForEach(error => _domainNotificationHandler.Handle(new DomainNotification(command.GetType().ToString(), error.ErrorMessage)));
                return(Unit.Task);
            }

            Airplane airplane = new Airplane(command.Airplane.id, command.Airplane.CodigoAviao, command.Airplane.Modelo, command.Airplane.QtdPassageiros);

            _airplaneRepository.Update(airplane);

            return(Unit.Task);
        }
Пример #10
0
        public void Handler_DeveAdicionarNotificacao()
        {
            var chave               = "nome";
            var valor               = "Nome deve possuir conteúdo";
            var notification        = new DomainNotification(chave, valor);
            var notificationHandler = new DomainNotificationHandler();

            notificationHandler.Handle(notification, CancellationToken.None);

            notificationHandler.TemNotificacao().Should().Be(true);
            notificationHandler.ObterNotificacoes().Should().HaveCount(1);
            var notificacaoLancada = notificationHandler.ObterNotificacoes().First();

            notificacaoLancada.Should().NotBeEmpty();
        }
Пример #11
0
        private void NewErrorNotification(string key, string field = "", params string[] parameters)
        {
            var completeMessage = _localizer[key]?.Value;

            if (completeMessage == null)
            {
                return;
            }

            completeMessage = parameters.Length > 0
                ? parameters.Aggregate(completeMessage, (current, item) => current.Replace("'{0}'", item))
                : completeMessage.Replace("'{0}'", string.Empty);

            _notification.Handle(new DomainNotification(field, completeMessage), default(CancellationToken));
        }
Пример #12
0
        public void InitTests()
        {
            db                         = GetDbInstance();
            _unitOfWork                = new UnitOfWork(db);
            _mockChat                  = new Mock <IHubContext <ChatHub> >();
            _userRepository            = new UserRepository(db);
            _mockMediator              = new Mock <IMediatorHandler>();
            _domainNotificationHandler = new DomainNotificationHandler();
            _mockMediator.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())).Callback <DomainNotification>((x) =>
            {
                _domainNotificationHandler.Handle(x, CancellationToken.None);
            });

            _mapper = AutoMapperConfig.RegisterMappings().CreateMapper();
        }
Пример #13
0
        public ICommandResult Handle(NewClient command)
        {
            if (!command.IsValid(_clientRepository))
            {
                command.ValidationResult.Errors.ToList().ForEach(error => _domainNotificationHandler.Handle(new DomainNotification(command.GetType().ToString(), error.ErrorMessage)));
                return(null);
            }

            var client = new Client(command.Name, command.UserName, command.Email, command.Password, command.Clienteuniqueid);

            _clientRepository.Add(client);
            return(new ClientResult
            {
                Id = client.Id,
                Name = client.Name,
                ClientUniqueId = client.ClientUniqueId
            });
        }
        public async void AddDomainNotificationError_Ok()
        {
            var faker = new Faker();

            var message = faker.Lorem.Sentence();

            var handler = new DomainNotificationHandler();

            var domainNotification = DomainNotification.Fail(message);

            await handler.Handle(domainNotification, new CancellationToken());

            var notifications = handler.GetNotificationsError();

            Assert.True(handler.HasNotificationsError());

            Assert.True(notifications.Count == 1);
        }
        public async void GetNotificationsError_Ok()
        {
            var faker = new Faker();

            var message = faker.Lorem.Sentence();

            var handler = new DomainNotificationHandler();

            var domainNotification = DomainNotification.Fail(message);

            await handler.Handle(domainNotification, new CancellationToken());

            var notifications = handler.GetNotificationsError();

            var result = notifications.Select(x => x.Value);


            Assert.Contains(message, result);
        }
Пример #16
0
        public void InitTests()
        {
            db                         = GetDbInstance();
            _unitOfWork                = new UnitOfWork(db);
            _userRepository            = new UserRepository(db);
            _mockMediator              = new Mock <IMediatorHandler>();
            _domainNotificationHandler = new DomainNotificationHandler();
            _mockMediator.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())).Callback <DomainNotification>((x) =>
            {
                _domainNotificationHandler.Handle(x, CancellationToken.None);
            });

            _mapper = AutoMapperConfig.RegisterMappings().CreateMapper();

            _userRepository.Add(new User
            {
                Email    = "*****@*****.**",
                Name     = "Test",
                Password = Cryptography.PasswordEncrypt("123456")
            });
            _unitOfWork.Commit();

            var mockConfig = new Mock <IConfiguration>();

            mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Issuer"))])
            .Returns("Test");

            mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Duration"))])
            .Returns("120");

            mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Key"))])
            .Returns("IZpipYfLNJro403p");

            _loginService = new LoginService(_userRepository, mockConfig.Object);
            handler       = new LoginHandler(_unitOfWork, _userRepository, _mockMediator.Object, _mapper, _loginService);
        }
Пример #17
0
 protected void NotifyError(string code, string message)
 {
     _notifications.Handle(new DomainNotification(code, message));
 }
Пример #18
0
 public Task Publish <TNotification>(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification
 {
     _notifications.Handle(notification as DomainNotification, cancellationToken);
     return(Task.CompletedTask);
 }
Пример #19
0
 protected void NotifyError(string code, string message)
 {
     _notifications.Handle(new DomainNotification(code, message),
                           new System.Threading.CancellationToken()).GetAwaiter().GetResult();
 }
Пример #20
0
 protected void NotificarErro(string codigo, string mensagem)
 {
     _notifications.Handle(new DomainNotification(codigo, mensagem));
 }
Пример #21
0
 protected void NotifyError(string code, string message) => _notifications.Handle(new DomainNotification(code, message), new CancellationToken());
 public void AddNotification(DomainNotification notification)
 {
     _notifications.Handle(notification);
 }
Пример #23
0
 protected void NotifyError(string code, string message)
 {
     _notifications.Handle(new DomainNotification(code, message), default(CancellationToken));
 }
Пример #24
0
 protected async Task NotifyError(string code, string message)
 => await _notifications.Handle(DomainNotification.Factory.Create(code, message), default(CancellationToken));