public async Task CanSendCommandsToHandler()
        {
            // arrange
            var sync = new CountdownEvent(6);

            var ctx = DomainContext.Configure()
                      .Bus(b =>
                           b.WithProcessor(p =>
                                           p.Endpoint("p1")
                                           .RegisterHandler(new TestCommandHandler(cmd => sync.Signal())))
                           )
                      .Start();

            // act
            using (ctx)
            {
                await ctx.CommandBus.Send(new Command <DoSimple>("cmd1", new DoSimple {
                }));

                await ctx.CommandBus.Send(new Command <DoComplex>("cmd2", new DoComplex {
                }));

                await ctx.CommandBus.Send(new Command <DoSimpleStuff>("cmd3", DoSimpleStuff.Create()));

                await ctx.CommandBus.Send(new Command <DoComplexStuff>("cmd4", DoComplexStuff.Create()));

                await ctx.CommandBus.Send(new Command <DoGenericStuff <DoComplexStuff> >("cmd5", new DoGenericStuff <DoComplexStuff> {
                    Stuff = DoComplexStuff.Create()
                }));

                await ctx.CommandBus.Send(new Command <DoNonGenericStuff>("cmd6", new DoNonGenericStuff {
                    Stuff = DoSimpleStuff.Create()
                }));

                sync.Wait(TimeSpan.FromSeconds(2));
            }

            // assert
            Assert.AreEqual(0, sync.CurrentCount); // asserts all messages were received
        }
        public async Task CommandsAreProperlySerialized()
        {
            // arrange
            var cmds = new ConcurrentDictionary <Type, SentReceivedMessage>();

            cmds[typeof(Command <DoSimple>)] = new SentReceivedMessage
            {
                Sent = new Command <DoSimple>("cmd1", new DoSimple {
                    Value = "0"
                })
            };
            cmds[typeof(Command <DoComplex>)] = new SentReceivedMessage
            {
                Sent = new Command <DoComplex>("cmd2", new DoComplex {
                    IntValue = 10, StringValue = "abc"
                })
            };
            cmds[typeof(Command <DoSimpleStuff>)] = new SentReceivedMessage
            {
                Sent = new Command <DoSimpleStuff>("cmd3", DoSimpleStuff.Create())
            };
            cmds[typeof(Command <DoComplexStuff>)] = new SentReceivedMessage
            {
                Sent = new Command <DoComplexStuff>("cmd4", DoComplexStuff.Create())
            };
            cmds[typeof(Command <DoGenericStuff <DoComplexStuff> >)] = new SentReceivedMessage
            {
                Sent = new Command <DoGenericStuff <DoComplexStuff> >("cmd5", new DoGenericStuff <DoComplexStuff> {
                    Stuff = DoComplexStuff.Create()
                })
            };
            cmds[typeof(Command <DoNonGenericStuff>)] = new SentReceivedMessage
            {
                Sent = new Command <DoNonGenericStuff>("cmd6", new DoNonGenericStuff {
                    Stuff = DoSimpleStuff.Create()
                })
            };

            var sync = new CountdownEvent(cmds.Count);

            var ctx = DomainContext.Configure()
                      .Bus(b =>
                           b.WithProcessor(p =>
                                           p.Endpoint("p1")
                                           .RegisterHandler(new TestCommandHandler(cmd =>
            {
                // stores the received message and signals completion
                cmds[cmd.GetType()].Received = cmd;
                sync.Signal();
            })))
                           )
                      .Start();

            // act
            using (ctx)
            {
                foreach (var cmd in cmds)
                {
                    await ctx.CommandBus.Send(cmd.Value.Sent as ICommand);
                }

                sync.Wait(TimeSpan.FromSeconds(2));
            }

            // assert
            // check that the sent message is the same as the received message
            // by serializing each and comparing the string
            Assert.AreEqual(0, sync.CurrentCount); // asserts all messages were received

            foreach (var cmd in cmds)
            {
                Assert.AreEqual(
                    JsonConvert.SerializeObject(cmd.Value.Sent),
                    JsonConvert.SerializeObject(cmd.Value.Received));
            }
        }