コード例 #1
0
        private static MongoEventStore CreateStore(
            List <StreamConfiguration> streams,
            MongoFake db = null,
            BatchIDGenerator idGenerator = null,
            bool preserveLog             = false,
            bool callUpgrade             = true
            )
        {
            db          = db ?? new MongoFake();
            idGenerator = idGenerator ?? new LoggingIDGenerator();

            ConfigureSerialization(new GuidSerializer(BsonType.Binary));

            MongoEventStore store = new MongoEventStore(
                db,
                new EventStoreSettings(streams),
                idGenerator
                );

            if (callUpgrade)
            {
                store.Upgrade().Wait();
            }

            if (!preserveLog)
            {
                db.Log.Clear();
            }

            return(store);
        }
コード例 #2
0
        public void Upgrade(MongoEventStore store)
        {
            MongoFake db = default;

            GIVEN["an empty DB and one configured stream"] = () => store = CreateStore(
                new List <StreamConfiguration> {
                new StreamConfiguration(typeof(Order), "order")
            },
                db = new MongoFake(),
                new PresetIDGenerator(),
                callUpgrade: false
                );

            When["calling Upgrade"] = () => store.Upgrade();

            THEN["the Events collection is created with index on StreamID"] = () => db.Log.Should().Contain(b => b
                                                                                                            .CreateCollection("Events")
                                                                                                            .CreateIndex("Events", "StreamID"));


            GIVEN["a proper configuration"] = () => {
                store = CreateStore(
                    new List <StreamConfiguration> {
                    new StreamConfiguration(typeof(Customer), "customer"),
                    new StreamConfiguration(typeof(Order), "order"),
                    new StreamConfiguration(typeof(OrderProcessor), "order_processor")
                },
                    db,
                    new PresetIDGenerator(),
                    callUpgrade: false,
                    preserveLog: true
                    );
            };

            When["calling Upgrade"] = () => store.Upgrade();

            THEN["the missing collections are created"] = () => {
                db.Log.Should().Contain(b => b
                                        .CreateCollection("customer_Info")
                                        .CreateCollection("order_processor_Info"));
            };
        }