Esempio n. 1
0
        public async Task A_subscribed_receiver_can_select_a_handler_based_on_message_type()
        {
            var bus = new InMemoryCommandBus <ICommand <CommandTarget> >(Clock);

            var received = new List <ICommand <CommandTarget> >();

            var handler1 = CommandHandler.Create <CreateCommandTarget>(delivery => received.Add(delivery.Command));
            var handler2 = CommandHandler.Create <UpdateCommandTarget>(delivery => received.Add(delivery.Command));

            bus.Subscribe(handler1);
            bus.Subscribe(handler2);

            await bus.Schedule(new CreateCommandTarget(Guid.NewGuid().ToString()));

            await Clock.AdvanceBy(1.Seconds());

            received.Should()
            .OnlyContain(c => c is CreateCommandTarget)
            .And
            .HaveCount(1);
        }