Exemplo n.º 1
0
        public EventStoreDbTest()
        {
            Logging.Configure();

            SetConnectionStrings();

            Command <Order> .AuthorizeDefault           = (order, command) => true;
            Command <CustomerAccount> .AuthorizeDefault = (order, command) => true;

            lock (lockObj)
            {
                if (databasesInitialized)
                {
                    return;
                }

                // TODO: (EventStoreDbTest) figure out a db cleanup story
//#if !DEBUG
//            new EventStoreDbContext().Database.Delete();
//            new OtherEventStoreDbContext().Database.Delete();
//            new ReadModelDbContext().Database.Delete();
//            new ReadModels1DbContext().Database.Delete();
//            new ReadModels2DbContext().Database.Delete();
//            new CommandSchedulerDbContext().Database.Delete();
//#endif

                using (var eventStore = new EventStoreDbContext())
                {
                    new EventStoreDatabaseInitializer <EventStoreDbContext>().InitializeDatabase(eventStore);
                }
                using (var db = new CommandSchedulerDbContext())
                {
                    new CommandSchedulerDatabaseInitializer().InitializeDatabase(db);
                }
                using (var eventStore = new OtherEventStoreDbContext())
                {
                    new EventStoreDatabaseInitializer <OtherEventStoreDbContext>().InitializeDatabase(eventStore);
                }
                using (var db = new ReadModelDbContext())
                {
                    new ReadModelDatabaseInitializer <ReadModelDbContext>().InitializeDatabase(db);
                }
                using (var db = new ReadModels1DbContext())
                {
                    new ReadModelDatabaseInitializer <ReadModels1DbContext>().InitializeDatabase(db);
                }
                using (var db = new ReadModels2DbContext())
                {
                    new ReadModelDatabaseInitializer <ReadModels2DbContext>().InitializeDatabase(db);
                }

                databasesInitialized = true;
            }
        }
Exemplo n.º 2
0
        public async Task Two_different_projectors_can_catch_up_to_two_different_event_stores_using_separate_catchups()
        {
            // arrange
            var projector1CallCount = 0;
            var projector2CallCount = 0;
            var projector1          = Projector.Create <Order.ItemAdded>(e => projector1CallCount++).Named(MethodBase.GetCurrentMethod().Name + "1");
            var projector2          = Projector.Create <Order.ItemAdded>(e => projector2CallCount++).Named(MethodBase.GetCurrentMethod().Name + "2");
            var startProjector2AtId = new OtherEventStoreDbContext().DisposeAfter(db => db.HighestEventId()) + 1;

            Events.Write(5, createEventStore: () => EventStoreDbContext());
            Events.Write(5, createEventStore: () => new OtherEventStoreDbContext());

            using (var eventStoreCatchup = new ReadModelCatchup(
                       readModelDbContext: () => ReadModelDbContext(),
                       eventStoreDbContext: () => EventStoreDbContext(),
                       startAtEventId: HighestEventId + 1,
                       projectors: projector1)
            {
                Name = "eventStoreCatchup"
            })
                using (var otherEventStoreCatchup = new ReadModelCatchup(
                           readModelDbContext: () => ReadModelDbContext(),
                           eventStoreDbContext: () => new OtherEventStoreDbContext(),
                           startAtEventId: startProjector2AtId,
                           projectors: projector2)
                {
                    Name = "otherEventStoreCatchup"
                })
                {
                    // act
                    await eventStoreCatchup.SingleBatchAsync();

                    await otherEventStoreCatchup.SingleBatchAsync();
                }

            // assert
            projector1CallCount.Should().Be(5, "projector1 should get all events from event stream");
            projector2CallCount.Should().Be(5, "projector2 should get all events from event stream");
        }