protected override async Task Given(AllDependencyResolversTestContext context)
        {

            await base.Given(context);

            var clock = new SystemClock();
            var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace});
            var serializer = new DataContractSerializer(typeProvider);
            var replyQueueNameSetting = new ReplyQueueNameSetting(
                new ApplicationNameSetting {Value = "TestApplication"},
                new InstanceNameSetting {Value = "TestInstance"});

            var handlerMap = new HandlerMapper(typeProvider).GetFullHandlerMap(typeof (IHandleCommand<>));

            _brokeredMessageFactory = new BrokeredMessageFactory(new MaxLargeMessageSizeSetting(),
                                                                 new MaxSmallMessageSizeSetting(),
                                                                 replyQueueNameSetting,
                                                                 clock,
                                                                 new NullCompressor(),
                                                                 new DispatchContextManager(),
                                                                 new UnsupportedLargeMessageBodyStore(),
                                                                 serializer,
                                                                 typeProvider);

            _commandDispatcher = new CommandMessageDispatcher(_brokeredMessageFactory,
                                                              new SystemClock(),
                                                              Subject,
                                                              new NullInboundInterceptorFactory(),
                                                              new NullLogger(),
                                                              handlerMap);
        }
        public async Task Command1ShouldBeDispatchedToTheCorrectHandler(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            MethodCallCounter.ReceivedCallsWithAnyArg<BrokerTestCommandHandler>(h => h.Handle(null))
                             .Select(c => c.Single())
                             .Cast<FooCommand>()
                             .Select(c => c.Id)
                             .ShouldContain(_id1);
        }
        public async Task ResolvingTheSecondFooHandlerViaNameShouldGiveTheCorrectType(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            using (var scope = Subject.CreateChildScope())
            {
                var componentName = typeof (SecondFooRequestHandler).FullName;
                var handler = scope.Resolve<IHandleRequest<FooRequest, FooResponse>>(componentName);
                handler.ShouldBeTypeOf<SecondFooRequestHandler>();
            }
        }
        public async Task ResolvingTheFirstFooHandlerViaNameShouldGiveTheCorrectType(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            using (var scope = Subject.CreateChildScope())
            {
                var componentName = typeof (FirstFooEventHandler).FullName;
                var handler = scope.Resolve<IHandleMulticastEvent<FooEvent>>(componentName);
                handler.ShouldBeTypeOf<FirstFooEventHandler>();
            }
        }
        public async Task TheHandlerTypeShouldBeCorrect(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            using (var scope = Subject.CreateChildScope())
            {
                var componentName = typeof (BrokerTestCommandHandler).FullName;
                var handler = scope.Resolve<IHandleCommand<FooCommand>>(componentName);
                handler.ShouldBeTypeOf<BrokerTestCommandHandler>();
            }
        }
        public async Task TheHandlerShouldBeDisposedAfterTheScopeIsDisposed(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            DisposableHandler handler;
            using (var scope = Subject.CreateChildScope())
            {
                var componentName = typeof (DisposableHandler).FullName;
                handler = (DisposableHandler) scope.Resolve<IHandleCommand<NullCommand>>(componentName);
            }

            handler.IsDisposed.ShouldBe(true);
        }
        public async Task BothInstancesOfTheCommandHandlerShouldHaveBeenDisposed(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            var calls = MethodCallCounter.ReceivedCallsWithAnyArg<BrokerTestCommandHandler>(h => h.Dispose());
            calls.Count().ShouldBe(_expectedCallCount);
        }
        public async Task ATotalOfTwoCallsToHandleShouldBeReceived(AllDependencyResolversTestContext context)
        {
            await Given(context);
            await When();

            var calls = MethodCallCounter.ReceivedCallsWithAnyArg<BrokerTestCommandHandler>(h => h.Handle(null));
            calls.Count().ShouldBe(_expectedCallCount);
        }
 protected virtual async Task Given(AllDependencyResolversTestContext context)
 {
     _context = context;
     Subject = await context.Create();
 }