public void unsubscribe_should_not_remove_other_handlers()
        {
            var  bus           = new CommandBus("local");
            long proccessedCmd = 0;
            var  hndl          = new AdHocCommandHandler <TestCommands.TestCommand>(
                cmd =>
            {
                Interlocked.Increment(ref proccessedCmd);
                return(true);
            });

            bus.Subscribe(hndl);
            bus.Subscribe(new AdHocCommandHandler <TestCommands.TestCommand2>(
                              cmd =>
            {
                Interlocked.Increment(ref proccessedCmd);
                return(true);
            }));
            bus.Fire(new TestCommands.TestCommand(Guid.NewGuid(), null));
            bus.Unsubscribe(hndl);
            Assert.Throws <CommandNotHandledException>(
                () => bus.Fire(new TestCommands.TestCommand(Guid.NewGuid(), null)));

            bus.Fire(new TestCommands.TestCommand2(Guid.NewGuid(), null));
            Assert.IsOrBecomesTrue(
                () => Interlocked.Read(ref proccessedCmd) == 2,
                msg: "Expected command handled twice, got" + proccessedCmd);
        }
        public void command_handler_acks_command_message()
        {
            var  bus    = new CommandBus("temp");
            long gotCmd = 0;
            long gotAck = 0;
            var  hndl   =
                new AdHocCommandHandler <TestCommands.TestCommand>(
                    cmd => Interlocked.Exchange(ref gotCmd, 1) == 0);

            bus.Subscribe(hndl);
            var ackHndl =
                new AdHocHandler <AckCommand>(
                    cmd => Interlocked.Exchange(ref gotAck, 1));

            bus.Subscribe(ackHndl);
            bus.Fire(new TestCommands.TestCommand(Guid.NewGuid(), null));
            Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotAck) == 1);
            Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotCmd) == 1);
        }