示例#1
0
        public void SetUp()
        {
            MongoFlatMapper.EnableFlatMapping(true);
            MongoDbTestConnectionProvider.ReadModelDb.Drop();

            var mngr = new IdentityManager(new CounterService(MongoDbTestConnectionProvider.ReadModelDb));

            mngr.RegisterIdentitiesFromAssembly(typeof(DocumentDescriptorId).Assembly);

            MongoFlatIdSerializerHelper.Initialize(mngr);

            EventStoreIdentityCustomBsonTypeMapper.Register <DocumentDescriptorId>();
            EventStoreIdentityCustomBsonTypeMapper.Register <DocumentId>();
            StringValueCustomBsonTypeMapper.Register <BlobId>();
            StringValueCustomBsonTypeMapper.Register <DocumentHandle>();
            StringValueCustomBsonTypeMapper.Register <FileHash>();

            _writer = new DocumentWriter(MongoDbTestConnectionProvider.ReadModelDb);
            var _documentDescriptorCollection = new MongoReaderForProjections <DocumentDescriptorReadModel, DocumentDescriptorId>
                                                (
                new MongoStorageFactory(MongoDbTestConnectionProvider.ReadModelDb,
                                        new RebuildContext(true)));
            var _documentDeletedCollection = new CollectionWrapper <DocumentDeletedReadModel, String>
                                             (
                new MongoStorageFactory(MongoDbTestConnectionProvider.ReadModelDb,
                                        new RebuildContext(true)), null);

            _sut = new DocumentProjection(_writer, _documentDescriptorCollection, _documentDeletedCollection);
        }
        public void SetUp()
        {
            Current = new Tenant(new TenantATestSettings());

            var connectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;
            var url    = new MongoUrl(connectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            client.DropDatabase(url.DatabaseName);

            _identityConverter = new IdentityManager(new InMemoryCounterService());
            _identityConverter.RegisterIdentitiesFromAssembly(GetType().Assembly);
            MongoFlatIdSerializerHelper.Initialize(_identityConverter);
            var loggerFactory = Substitute.For <ILoggerFactory>();

            loggerFactory.Create(Arg.Any <Type>()).Returns(NullLogger.Instance);
            _eventStore = new EventStoreFactory(loggerFactory).BuildEventStore(connectionString);
            _sut        = CreateRepository();

            _container = new WindsorContainer();
            _container.AddFacility <TypedFactoryFacility>();
            _container.Register(Component.For <IRepositoryExFactory>().AsFactory());
            _container.Register(Component
                                .For <IRepositoryEx>()
                                .UsingFactoryMethod(() => CreateRepository())
                                .LifestyleTransient());

            _aggregateCachedRepositoryFactory = new AggregateCachedRepositoryFactory(
                _container.Resolve <IRepositoryExFactory>(),
                false);
        }
        public virtual void TestFixtureSetUp()
        {
            _logger = NSubstitute.Substitute.For <ILog>();
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;;
            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            _identityConverter = new IdentityManager(new CounterService(_db));
            _identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);

            ProjectionEngineConfig config = new ProjectionEngineConfig()
            {
                EventStoreConnectionString = _eventStoreConnectionString
            };
            CommitEnhancer commitEnhancer = new CommitEnhancer(_identityConverter);

            sut = new EventUnwinder(config, NullLogger.Instance);

            _unwindedEventCollection = _db.GetCollection <UnwindedDomainEvent>("UnwindedEvents");
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(_identityConverter);
        }
        public void SetUp()
        {
            _db.Drop();

            var mngr = new IdentityManager(new CounterService(MongoDbTestConnectionProvider.ReadModelDb));

            mngr.RegisterIdentitiesFromAssembly(typeof(DocumentDescriptorId).Assembly);
            MongoFlatIdSerializerHelper.Initialize(mngr);
        }
        public virtual void TestFixtureSetUp()
        {
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;

            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            ProjectionEngineConfig config = new ProjectionEngineConfig();

            config.EventStoreConnectionString = _eventStoreConnectionString;
            config.Slots      = new string[] { "*" };
            config.TenantId   = new TenantId("A");
            config.BucketInfo = new List <BucketInfo>();
            config.BucketInfo.Add(new BucketInfo()
            {
                Slots = new[] { "*" }, BufferSize = 10000
            });

            _identityConverter = new IdentityManager(new CounterService(_db));
            _identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);
            ConfigureEventStore();
            CommitEnhancer commitEnhancer = new CommitEnhancer(_identityConverter);

            _eventUnwinder = new EventUnwinder(config, new TestLogger(LoggerLevel.Info));

            _unwindedEventCollection = _db.GetCollection <UnwindedDomainEvent>("UnwindedEvents");
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(_identityConverter);

            var rebuildContext = new RebuildContext(NitroEnabled);

            _storageFactory = new MongoStorageFactory(_db, rebuildContext);

            _reader1 = new MongoReader <SampleReadModel, string>(_db);
            _reader2 = new MongoReader <SampleReadModel2, string>(_db);
            _reader3 = new MongoReader <SampleReadModel3, string>(_db);

            //now configure RebuildProjectionEngine
            _tracker = new ConcurrentCheckpointTracker(_db);


            var projections = BuildProjections().ToArray();

            _tracker.SetUp(projections, 1, false);
            ProjectionEventInspector inspector = new ProjectionEventInspector();

            inspector.AddAssembly(Assembly.GetExecutingAssembly());
            sut        = new RebuildProjectionEngine(_eventUnwinder, _tracker, projections, rebuildContext, config, inspector);
            sut.Logger = new TestLogger(LoggerLevel.Debug);

            _checkpointCollection = _db.GetCollection <Checkpoint>("checkpoints");
        }
示例#6
0
        public virtual void TestFixtureSetUp()
        {
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;
            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            var identityConverter = new IdentityManager(new CounterService(_db));

            identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(identityConverter);
        }
示例#7
0
 public static void RegisterSerializerForFlatId <T>() where T : EventStoreIdentity
 {
     if (_manager == null)
     {
         var systemDb = TestHelper.CreateNew(ConfigurationManager.ConnectionStrings["system"].ConnectionString);
         _manager = new IdentityManager(new CounterService(systemDb));
         _manager.RegisterIdentitiesFromAssembly(Assembly.GetExecutingAssembly());
         MongoFlatIdSerializerHelper.Initialize(_manager);
     }
     if (!_registeredTypes.Contains(typeof(T)))
     {
         _registeredTypes.Add(typeof(T));
         BsonSerializer.RegisterSerializer(typeof(T), new TypedEventStoreIdentityBsonSerializer <T>());
         EventStoreIdentityCustomBsonTypeMapper.Register <T>();
     }
 }
        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),
            };
        }
示例#9
0
        public void This_is_run_before_ANY_tests()
        {
            var overrideTestDb = Environment.GetEnvironmentVariable("TEST_MONGODB");

            if (!String.IsNullOrEmpty(overrideTestDb))
            {
                var overrideTestDbQueryString = Environment.GetEnvironmentVariable("TEST_MONGODB_QUERYSTRING");
                var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "log", "ds-tests-logs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.quartz", "ds-tests-quartz");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.queue", "ds-tests-queues");

                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.log.host", "ds-logs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.quartz.host", "ds-quartz");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.queue.host", "ds-queues");

                //<!-- Tenant 1-->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.originals", "ds-tests-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.descriptors", "ds-tests-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.artifacts", "ds-tests-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.system", "ds-tests");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.events", "ds-tests");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.readmodel", "ds-tests");

                //<!-- Tenant DOCS -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.originals", "ds-docs-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.descriptors", "ds-docs-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.artifacts", "ds-docs-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.system", "ds-docs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.events", "ds-docs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.readmodel", "ds-docs");

                //<!-- Tenant DEMO -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.originals", "ds-demo-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.descriptors", "ds-demo-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.artifacts", "ds-demo-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.system", "ds-demo");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.events", "ds-demo");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.readmodel", "ds-demo");

                //<!-- Tenant Tickets -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.originals", "ds-tickets-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.descriptors", "ds-tickets-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.artifacts", "ds-tickets-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.system", "ds-tickets");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.events", "ds-tickets");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.readmodel", "ds-tickets");

                config.Save();
                ConfigurationManager.RefreshSection("connectionStrings");
            }
            try
            {
                var mngr = new IdentityManager(new CounterService(MongoDbTestConnectionProvider.ReadModelDb));
                mngr.RegisterIdentitiesFromAssembly(typeof(DocumentDescriptorId).Assembly);
                mngr.RegisterIdentitiesFromAssembly(typeof(TenantId).Assembly);
                mngr.RegisterIdentitiesFromAssembly(typeof(QueuedJobId).Assembly);

                MongoFlatIdSerializerHelper.Initialize(mngr);
                //BsonSerializer.RegisterSerializationProvider(new EventStoreIdentitySerializationProvider());
                //BsonSerializer.RegisterSerializationProvider(new StringValueSerializationProvider());
                MongoFlatMapper.EnableFlatMapping(true);
            }
            catch (ReflectionTypeLoadException rle)
            {
                foreach (var ex in rle.LoaderExceptions)
                {
                    Console.WriteLine("Exception In typeloading: " + ex.Message);
                }
                Console.WriteLine("Exception in Global Setup: " + rle.ToString());
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in Global Setup: " + ex.ToString());
                throw;
            }
        }
示例#10
0
 static void EnableFlatIdMapping(IdentityManager converter)
 {
     MongoFlatIdSerializerHelper.Initialize(converter);
 }