예제 #1
0
        public void TestCommandReceiverCreateTest()
        {
            TestBusContext context = new TestBusContext();
            var            target  = context.CreateCommandReceiver("queue");

            Assert.AreEqual("queue", target.QueueName);
        }
예제 #2
0
        public void StartReceivingCommandsTest()
        {
            TestBusContext context = new TestBusContext();
            var            target  = context.CreateCommandReceiver("queue");

            target.DeclareCommandQueue();
            context.DeclareCommandQueue("responseQueue");
            var autoReset = new AutoResetEvent(false);

            target.StartReceivingCommands((cm) =>
            {
                autoReset.Set();
                return(Task.Run(() => new CommandResponseMessage(cm.Message, null, null)));
            });

            context.CommandQueues["queue"].Enqueue(new TestBusCommandMessage(new CommandRequestMessage("message", null), new BasicProperties()
            {
                ReplyTo = "responseQueue"
            }));

            bool succes = autoReset.WaitOne(5000);

            Assert.IsTrue(succes);
            Assert.AreEqual(0, context.CommandQueues["queue"].Count);
            Thread.Sleep(100);
            Assert.AreEqual(1, context.CommandQueues["responseQueue"].Count);
        }
예제 #3
0
        public void PausingEventListenerPausesDeliveryInQueue(string queueName)
        {
            var context  = new TestBusContext();
            var sender   = context.CreateCommandSender();
            var receiver = context.CreateCommandReceiver(queueName);

            receiver.DeclareCommandQueue();

            var command = new CommandMessage
            {
                DestinationQueue = queueName,
                CorrelationId    = Guid.NewGuid(),
                Body             = Encoding.Unicode.GetBytes("Hello World")
            };

            bool messageReceived = false;

            receiver.StartReceivingCommands(e =>
            {
                messageReceived = true;
                return(new CommandMessage());
            });

            // Act
            receiver.Pause();

            sender.SendCommandAsync(command);

            Thread.Sleep(WaitTime);

            // Assert
            Assert.AreEqual(false, messageReceived);
        }
예제 #4
0
        public void SentMessageIsProperlySentAndReceivedWithManipulations(string startMessage, string appendMessage)
        {
            // Arrange
            var context  = new TestBusContext();
            var sender   = context.CreateCommandSender();
            var receiver = context.CreateCommandReceiver("dest.queue");

            receiver.DeclareCommandQueue();

            var command = new CommandMessage
            {
                DestinationQueue = "dest.queue",
                CorrelationId    = Guid.NewGuid(),
                Body             = Encoding.Unicode.GetBytes(startMessage)
            };

            // Act
            receiver.StartReceivingCommands(e =>
            {
                var textBody = Encoding.Unicode.GetString(e.Body);
                return(new CommandMessage {
                    Body = Encoding.Unicode.GetBytes(textBody + appendMessage)
                });
            });

            var result = sender.SendCommandAsync(command);

            // Assert
            Assert.AreEqual(startMessage + appendMessage, Encoding.Unicode.GetString(result.Result.Body));
        }
예제 #5
0
        public void SentMessageIsProperlyReceivedAndReturned(string destQueue, string expected)
        {
            // Arrange
            var context  = new TestBusContext();
            var sender   = context.CreateCommandSender();
            var receiver = context.CreateCommandReceiver(destQueue);

            receiver.DeclareCommandQueue();

            var command = new CommandMessage
            {
                DestinationQueue = destQueue,
                CorrelationId    = Guid.NewGuid()
            };

            // Act
            receiver.StartReceivingCommands(e => new CommandMessage {
                Body = Encoding.Unicode.GetBytes(expected)
            });

            var result = sender.SendCommandAsync(command);

            // Assert
            Assert.AreEqual(expected, Encoding.Unicode.GetString(result.Result.Body));
        }
예제 #6
0
        public void DeclaringQueueTwiceThrowsException()
        {
            TestBusContext context  = new TestBusContext();
            var            receiver = context.CreateCommandReceiver("queue");

            receiver.DeclareCommandQueue();

            Assert.ThrowsException <BusConfigurationException>(() => receiver.DeclareCommandQueue());
        }
예제 #7
0
        public void StartListeningTwiceThrowsException()
        {
            TestBusContext context  = new TestBusContext();
            var            receiver = context.CreateCommandReceiver("queue");

            receiver.DeclareCommandQueue();
            receiver.StartReceivingCommands((cm) => { return(Task.Run(() => new CommandResponseMessage(cm.Message, "", cm.CorrelationId))); });
            Assert.ThrowsException <BusConfigurationException>(() => receiver.StartReceivingCommands((cm) => Task.Run(() => new CommandResponseMessage(cm.Message, "", cm.CorrelationId))));
        }
예제 #8
0
        public void DeclareCommandQueueTest()
        {
            TestBusContext context = new TestBusContext();
            var            target  = context.CreateCommandReceiver("queue");

            target.DeclareCommandQueue();

            Assert.AreEqual(1, context.CommandQueues.Count);
            Assert.AreEqual("queue", context.CommandQueues.First().Key);
        }
예제 #9
0
        public void CreateCommandReceiver_ReturnsTestCommandReceiver()
        {
            // Arrange
            TestBusContext context = new TestBusContext();

            // Act
            var receiver = context.CreateCommandReceiver("TestQueue");

            // Assert
            Assert.IsInstanceOfType(receiver, typeof(TestCommandReceiver));
        }
예제 #10
0
        public void CreateCommandReceiverReturnsCommandReceiver()
        {
            // Arrange
            var context = new TestBusContext();

            // Act
            var result = context.CreateCommandReceiver("test.queue");

            // Assert
            Assert.IsInstanceOfType(result, typeof(TestCommandReceiver));
        }
예제 #11
0
        public async Task TestBusIntegrationTest()
        {
            TestBusContext context  = new TestBusContext();
            var            sender   = context.CreateCommandSender();
            var            receiver = context.CreateCommandReceiver("queue");

            receiver.DeclareCommandQueue();
            receiver.StartReceivingCommands((cm) =>
            {
                var message = "message2";
                return(Task.Run(() => new CommandResponseMessage(message, "", cm.CorrelationId)));
            });

            var mess   = new CommandRequestMessage("message", null);
            var result = await sender.SendCommandAsync(mess, "queue");

            Assert.AreEqual("message2", result.Message);
        }