コード例 #1
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);
        }
コード例 #2
0
        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"]);
        }
コード例 #3
0
        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);
        }