public async Task ItWorksInSimpleScenario()
        {
            var events = new ConcurrentQueue<string>();
            var gotMessage = new AutoResetEvent(false);

            _handlerActivator.Handle<BaseMessage>(async msg =>
            {
                events.Enqueue($"Got {msg.GetType().Name} with {msg.Payload}");

                gotMessage.Set();
            });

            await _bus.SendLocal(new SpecializationA { Payload = "a" });
            await _bus.SendLocal(new SpecializationB { Payload = "b" });

            gotMessage.WaitOrDie(BlockingWaitTimeout, "Did not get the first message");
            gotMessage.WaitOrDie(BlockingWaitTimeout, "Did not get the second message");

            Assert.That(events.ToArray(), Is.EqualTo(new[]
            {
                "Got SpecializationA with a",
                "Got SpecializationB with b",
            }));
        }
        public async Task CanHandleObject()
        {
            var events = new ConcurrentQueue<string>();
            var gotMessage = new AutoResetEvent(false);

            _handlerActivator.Handle<object>(async msg =>
            {
                events.Enqueue($"Got {msg.GetType().Name}");
                gotMessage.Set();
            });

            await _bus.SendLocal("hej med dig");

            gotMessage.WaitOrDie(BlockingWaitTimeout);

            Assert.That(events.ToArray(), Is.EqualTo(new[]
            {
                "Got String",
            }));
        }
示例#3
0
        public async Task CanHandleInterface()
        {
            var events = new ConcurrentQueue<string>();
            var gotMessage = new AutoResetEvent(false);

            _handlerActivator.Handle<IMessage>(async msg =>
            {
                events.Enqueue(string.Format("Got {0}", msg.GetType().Name));
                gotMessage.Set();
            });

            await _bus.SendLocal(new ImplementorOfInterface());

            gotMessage.WaitOrDie(TimeSpan.FromSeconds(1));

            Assert.That(events.ToArray(), Is.EqualTo(new[]
            {
                "Got ImplementorOfInterface",
            }));
        }