Beispiel #1
0
        internal void MaxWithTypedProperty(IMongoFacadeTransaction tx, Maybe <EventID> max)
        {
            Given["a mongo collection"] = () => Env.DB.CreateCollectionAsync("test");

            USING["a transaction"] = () => {
                ITransaction t = DB.StartTransactionAsync().Result;
                tx = DB.UseTransaction(t);
                return(t);
            };

            When["calling Max on an empty collection"] = async() => max = await tx
                                                                          .GetCollection <TypedPropertyClass>("test")
                                                                          .Max(x => x.ID);

            THEN["None<T> is returned"] = () => max.Should().Be(None <EventID> .Value);

            And["a collection with a few items"] = () => tx
                                                   .GetCollection <TypedPropertyClass>("test")
                                                   .InsertManyAsync(new uint[] { 1, 3, 7, 2 }.Select(x => new TypedPropertyClass(id: x)));
            When["calling Max"] = async() => max = await tx
                                                   .GetCollection <TypedPropertyClass>("test")
                                                   .Max(x => x.ID);

            THEN["the maximum value is returned"] = () =>
                                                    max.Value.Serialize().Should().Be(7);
        }
Beispiel #2
0
        internal void MaxWithUntypedProperty(IMongoFacadeTransaction tx, Maybe <object> max, Maybe <EventID> typedMax)
        {
            GIVEN["a ClassMap with custom serializer"] = () => BsonClassMap.RegisterClassMap <UntypedPropertyClass>(m => m
                                                                                                                    .MapIdField(x => x.ID)
                                                                                                                    .SetSerializer(EventIDSerializer.CastInstance));
            Given["a mongo collection"] = () => Env.DB.CreateCollectionAsync("test");

            USING["a transaction"] = () => {
                ITransaction t = DB.StartTransactionAsync().Result;
                tx = DB.UseTransaction(t);
                return(t);
            };

            When["calling Max on an empty collection"] = async() => max = await tx
                                                                          .GetCollection <UntypedPropertyClass>("test")
                                                                          .Max(x => x.ID);

            THEN["None<T> is returned"] = () => max.Should().Be(None <Object> .Value);

            And["a collection with a few items"] = () => tx
                                                   .GetCollection <UntypedPropertyClass>("test")
                                                   .InsertManyAsync(new uint[] { 1, 3, 7, 2 }.Select(x => new UntypedPropertyClass(id: x)));

            When["calling Max"] = async() => max = await tx
                                                   .GetCollection <UntypedPropertyClass>("test")
                                                   .Max(x => x.ID);

            THEN["the maximum value is returned"] = () => {
                max.Value.Should().BeOfType <EventID>();
                max.Value.As <EventID>().Serialize().Should().Be(7);
            };

            When["calling Max on a interface-typed collection"] = async() => typedMax = await tx
                                                                                        .GetCollection <UntypedPropertyClass>("test")
                                                                                        .Max <EventID>("_id");

            THEN["the maximum value is returned"] = () => {
                typedMax.Value.Should().BeOfType <EventID>();
                typedMax.Value.As <EventID>().Serialize().Should().Be(7);
            };
        }
 public MongoEventStoreTransaction(MongoEventStore store, IMongoFacadeTransaction transaction)
 {
     _store       = store;
     _transaction = transaction;
 }
Beispiel #4
0
        public IEventStoreTransaction UseTransaction(ITransaction transaction)
        {
            IMongoFacadeTransaction facadeTx = _db.UseTransaction(transaction);

            return(new MongoEventStoreTransaction(this, facadeTx));
        }