Example #1
0
        public void EnqueueSingleMessage_and_StartListening_must_deal_with_generic_objects()
        {
            QueueMock.ClearAllQueues();

            var message = new Invoice
            {
                AccountReference    = Guid.NewGuid().ToString(),
                CurrencyUsed        = false,
                CustomerOrderNumber = int.MaxValue,
                ForeignRate         = 352.65m,
                InvoiceDate         = DateTime.Now,
                InvoiceNumber       = int.MaxValue,
                ItemsNet            = int.MinValue,
                ItemsTax            = 65645.98m,
                ItemsTotal          = 321564m,
                OrderNumber         = 321123,
            };

            var mockMQConfig = new MemoryMessageConfig(defaultBroker: "MockMQ", defaultBrokerConfigType: typeof(MockMQConfig));

            Messaging.Enqueue("invoices-b", message, mockMQConfig);

            var typedMessage = Messaging.Dequeue <Invoice>("invoices-b", mockMQConfig);

            Assert.AreEqual(message.AccountReference, typedMessage.AccountReference);
            Assert.AreEqual(message.CurrencyUsed, typedMessage.CurrencyUsed);
            Assert.AreEqual(message.CustomerOrderNumber, typedMessage.CustomerOrderNumber);
            Assert.AreEqual(message.ForeignRate, typedMessage.ForeignRate);
            Assert.AreEqual(message.InvoiceDate, typedMessage.InvoiceDate);
            Assert.AreEqual(message.InvoiceNumber, typedMessage.InvoiceNumber);
            Assert.AreEqual(message.ItemsNet, typedMessage.ItemsNet);
            Assert.AreEqual(message.ItemsTax, typedMessage.ItemsTax);
            Assert.AreEqual(message.ItemsTotal, typedMessage.ItemsTotal);
            Assert.AreEqual(message.OrderNumber, typedMessage.OrderNumber);
        }
        public void Client_deve_suportar_injecao_de_configuracao_sem_arquivo()
        {
            var mmc = new MemoryMessageConfig(defaultBroker: "MockMQ", defaultBrokerConfigType: typeof(MockMQConfig))
                      .WithQueue("teste1", "MockMQ")
                      .WithQueue("teste2", "RabbitMQ");

            string queueName = "teste1";
            string sentMsg   = "Teste de configuração em memória";


            Messaging.Enqueue(queueName, sentMsg, mmc);

            string received = "";

            using (var client = new Messaging(mmc))
            {
                client.StartListening(queueName, (args) =>
                {
                    received = args.AsString;
                    return(true);
                });
            }

            Assert.AreEqual(sentMsg, received);
        }
Example #3
0
        public void EnqueueMessage_and_StartListening_must_deal_with_generic_objects()
        {
            QueueMock.ClearAllQueues();

            var message = new Invoice
            {
                AccountReference    = Guid.NewGuid().ToString(),
                CurrencyUsed        = false,
                CustomerOrderNumber = int.MaxValue,
                ForeignRate         = 352.65m,
                InvoiceDate         = DateTime.Now,
                InvoiceNumber       = int.MaxValue,
                ItemsNet            = int.MinValue,
                ItemsTax            = 65645.98m,
                ItemsTotal          = 321564m,
                OrderNumber         = 321123,
            };


            var mockMQConfig = new MemoryMessageConfig(defaultBroker: "MockMQ", defaultBrokerConfigType: typeof(MockMQConfig));

            using (var client = new Messaging(mockMQConfig))
            {
                client.EnqueueMessage("invoices-a", message);
            }


            using (var client = new Messaging(mockMQConfig))
            {
                client.StartListening("invoices-a", (args) =>
                {
                    var typedMessage = args.GetMessage <Invoice>();
                    Assert.AreEqual(message.AccountReference, typedMessage.AccountReference);
                    Assert.AreEqual(message.CurrencyUsed, typedMessage.CurrencyUsed);
                    Assert.AreEqual(message.CustomerOrderNumber, typedMessage.CustomerOrderNumber);
                    Assert.AreEqual(message.ForeignRate, typedMessage.ForeignRate);
                    Assert.AreEqual(message.InvoiceDate, typedMessage.InvoiceDate);
                    Assert.AreEqual(message.InvoiceNumber, typedMessage.InvoiceNumber);
                    Assert.AreEqual(message.ItemsNet, typedMessage.ItemsNet);
                    Assert.AreEqual(message.ItemsTax, typedMessage.ItemsTax);
                    Assert.AreEqual(message.ItemsTotal, typedMessage.ItemsTotal);
                    Assert.AreEqual(message.OrderNumber, typedMessage.OrderNumber);

                    return(true);
                });
                Thread.Sleep(1000);
            }
        }
Example #4
0
        public void Client_deve_permitir_receber_qualquer_IMessagingConfig()
        {
            string mensagem = "Mensagem para teste de fila";
            // por memoria
            var memoryConfig = new MemoryMessageConfig(defaultBroker: "MockMQ", defaultBrokerConfigType: typeof(MockMQConfig)).WithQueue("teste", "MockMQ");

            string receivedByMemory = "";

            Messaging.Enqueue("teste", mensagem, memoryConfig);
            using (var client = new Messaging(memoryConfig))
            {
                client.StartListening("teste", (args) =>
                {
                    receivedByMemory = args.AsString;
                    return(true);
                });
            }

            Assert.AreEqual(mensagem, receivedByMemory);

            // por arquivo
            var fileContent = @"<?xml version='1.0' encoding='utf-8' ?><configuration><configSections>
                    <section name='MessagingConfigSection' type='Benner.Messaging.MessagingFileConfigSection, Benner.Messaging' />
                    </configSections><MessagingConfigSection><queues><queue name='teste-arquivo' broker='MockMQ' /></queues><brokerList default='MockMQ'>
                    <broker name='RabbitMQ' type='Benner.Messaging.RabbitMQConfig, Benner.Messaging'><add key='chave' value='valor' /></broker>
                    <broker name='MockMQ' type='Benner.Messaging.Tests.MockMQConfig, Benner.Messaging.Tests'><add key='chave' value='valor' /></broker>
                    </brokerList></MessagingConfigSection></configuration>";

            var path = Path.Combine(folder, "teste.config");

            File.AppendAllText(path, fileContent);

            var fileConfig = new FileMessagingConfig(path);

            string receivedByFile = "";

            Messaging.Enqueue("teste-arquivo", mensagem, fileConfig);
            receivedByFile = Messaging.Dequeue("teste-arquivo", fileConfig);

            Assert.AreEqual(mensagem, receivedByFile);
        }