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 DeclareCommandQueue_AddsQueue() { // Arrange TestBusContext context = new TestBusContext(); // Act context.DeclareCommandQueue("TestQueue"); // Assert Assert.AreEqual(1, context.CommandQueues.Count); Assert.IsNotNull(context.CommandQueues["TestQueue"]); }
public async Task SendCommandAsync() { TestBusContext context = new TestBusContext(); var sender = (TestCommandSender)context.CreateCommandSender(); var generatedQueue = context.CommandQueues.First().Value; context.DeclareCommandQueue("queue"); var message = new CommandRequestMessage("message", null); var task = sender.SendCommandAsync(message, "queue"); Assert.AreEqual(1, sender.CallbackMapper.Count); var dequeue = context.CommandQueues["queue"].Dequeue(); generatedQueue.Enqueue(new TestBusCommandMessage(new CommandResponseMessage("message", typeof(string).FullName, null), dequeue.Props)); var result = await task; Assert.AreEqual("message", result.Message); }