Beispiel #1
0
        public async Task CadastrarCervejaHandle_ObjetoNulo_RaiseEvent()
        {
            var unitOfWork   = Substitute.For <IUnitOfWork>();
            var eventHandler = Substitute.For <NotificationHandler>();
            var mediator     = Substitute.For <IMediatorHandler>();
            var handler      = new CervejaCommandHandler(unitOfWork, mediator, eventHandler);
            var command      = CadastrarCervejaCommand.Factory(null);

            await handler.Handle(command, CancellationToken.None);

            await mediator.ReceivedWithAnyArgs(1).RaiseEvent((Notification)null);
        }
Beispiel #2
0
        public async Task ExcluirCervejaHandle_ObjetoNulo_SaveChangesAsync()
        {
            var unitOfWork   = Substitute.For <IUnitOfWork>();
            var eventHandler = Substitute.For <NotificationHandler>();
            var mediator     = Substitute.For <IMediatorHandler>();
            var handler      = new CervejaCommandHandler(unitOfWork, mediator, eventHandler);
            var cerveja      = new Cerveja("Cerveja Teste", "Descrição", "Harmonização",
                                           "Coloração", "Categoria", "Ingredientes", 5, 0, 4, "Imagem.png");
            var command = ExcluirCervejaCommand.Factory(cerveja);

            await handler.Handle(command, CancellationToken.None);

            await unitOfWork.ReceivedWithAnyArgs(1).SaveChangesAsync();
        }
Beispiel #3
0
        public async Task EditarCervejaHandle_CervejaNaoInformada_RaiseEvent()
        {
            var unitOfWork   = Substitute.For <IUnitOfWork>();
            var eventHandler = Substitute.For <NotificationHandler>();
            var mediator     = Substitute.For <IMediatorHandler>();
            var handler      = new CervejaCommandHandler(unitOfWork, mediator, eventHandler);
            var cerveja      = new Cerveja("Cerveja Teste", "Descrição", "Harmonização",
                                           "Coloração", "Categoria", "Ingredientes", 5, 0, 4, "Imagem.png");
            var command = EditarCervejaCommand.Factory(cerveja, null);

            await handler.Handle(command, CancellationToken.None);

            await mediator.ReceivedWithAnyArgs(1).RaiseEvent((Notification)null);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            _commandHandler = new CervejaCommandHandler(
                new CervejaCommandService(
                    new CervejaRepository()
                    )
                );


            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };
            var connection = factory.CreateConnection();

            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "create-cerveja-command-queue",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body    = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    System.Console.WriteLine(" [x] Received {0}", message);
                    var command = JsonConvert.DeserializeObject <CreateCervejaCommand>(message);
                    _commandHandler.Handle(command);
                };
                channel.BasicConsume(queue: "create-cerveja-command-queue",
                                     autoAck: true,
                                     consumer: consumer);
            }

            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "update-cerveja-command-queue",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body    = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    System.Console.WriteLine(" [x] Received {0}", message);
                    var command = JsonConvert.DeserializeObject <UpdateCervejaCommand>(message);
                    _commandHandler.Handle(command);
                };
                channel.BasicConsume(queue: "update-cerveja-command-queue",
                                     autoAck: true,
                                     consumer: consumer);
            }

            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "delete-cerveja-command-queue",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body    = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    System.Console.WriteLine(" [x] Received {0}", message);
                    var command = JsonConvert.DeserializeObject <DeleteCervejaCommand>(message);
                    _commandHandler.Handle(command);
                };
                channel.BasicConsume(queue: "delete-cerveja-command-queue",
                                     autoAck: true,
                                     consumer: consumer);

                System.Console.WriteLine(" Press [enter] to exit.");
                System.Console.ReadLine();
            }
        }