public void TestCommandReceiverCreateTest() { TestBusContext context = new TestBusContext(); var target = context.CreateCommandReceiver("queue"); Assert.AreEqual("queue", target.QueueName); }
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); }
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); }
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)); }
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)); }
public void DeclaringQueueTwiceThrowsException() { TestBusContext context = new TestBusContext(); var receiver = context.CreateCommandReceiver("queue"); receiver.DeclareCommandQueue(); Assert.ThrowsException <BusConfigurationException>(() => receiver.DeclareCommandQueue()); }
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)))); }
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); }
public void CreateCommandReceiver_ReturnsTestCommandReceiver() { // Arrange TestBusContext context = new TestBusContext(); // Act var receiver = context.CreateCommandReceiver("TestQueue"); // Assert Assert.IsInstanceOfType(receiver, typeof(TestCommandReceiver)); }
public void CreateCommandReceiverReturnsCommandReceiver() { // Arrange var context = new TestBusContext(); // Act var result = context.CreateCommandReceiver("test.queue"); // Assert Assert.IsInstanceOfType(result, typeof(TestCommandReceiver)); }
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); }