public void SetUp()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;
            var url    = new MongoUrl(connectionString);
            var client = new MongoClient(url);
            var _db    = client.GetDatabase(url.DatabaseName);

            _eventsCollection = _db.GetCollection <BsonDocument>(EventStoreFactoryTest.PartitionCollectionName);

            client.DropDatabase(url.DatabaseName);

            var identityConverter = new IdentityManager(new InMemoryCounterService());

            identityConverter.RegisterIdentitiesFromAssembly(GetType().Assembly);
            MongoFlatIdSerializerHelper.Initialize(identityConverter);
            var loggerFactory = Substitute.For <INStoreLoggerFactory>();

            loggerFactory.CreateLogger(Arg.Any <String>()).Returns(NStoreNullLogger.Instance);
            _persistence = new EventStoreFactoryTest(loggerFactory)
                           .BuildEventStore(connectionString)
                           .Result;
            _repositoryEx = CreateRepository();

            var _container = new WindsorContainer();

            _container.AddFacility <TypedFactoryFacility>();
            _container.Register(Component.For <IRepositoryFactory>().AsFactory());
            _container.Register(Component
                                .For <IRepository>()
                                .UsingFactoryMethod(() => CreateRepository())
                                .LifestyleTransient());

            IRepositoryFactory factory = NSubstitute.Substitute.For <IRepositoryFactory>();

            factory.Create().Returns(_repositoryEx);

            _sut = new TouchSampleAggregateHandler
            {
                Repository       = _repositoryEx,
                AggregateFactory = _aggregateFactory,
                AggregateCachedRepositoryFactory = new AggregateCachedRepositoryFactory(factory),
                EventStoreQueryManager           = new DirectMongoEventStoreQueryManager(_db),
            };
        }
        public void repository_command_handler_should_set_context()
        {
            var cmd = new TouchSampleAggregate(new SampleAggregateId(1));

            cmd.SetContextData("key", "value");
            IRepositoryExFactory factory = NSubstitute.Substitute.For <IRepositoryExFactory>();

            factory.Create().Returns(_sut);
            var handler = new TouchSampleAggregateHandler
            {
                Repository       = _sut,
                AggregateFactory = _aggregateFactory,
                AggregateCachedRepositoryFactory = new AggregateCachedRepositoryFactory(factory)
            };

            handler.Handle(cmd);

            var context = handler.Aggregate.ExposeContext;

            Assert.NotNull(context);
            Assert.AreEqual("TouchSampleAggregate", context["command.name"]);
            Assert.AreEqual("value", context["key"]);
        }