Ejemplo n.º 1
0
        public static void TestSequence <T, U>(ITransactStoreProvider <T> provider, ITransactStoreProvider <U> relationProvider)
            where T : BaseTestTypesModel <U>, new()
            where U : BaseTestRelationsModel, new()
        {
            var model = GetTestTypesModel <T, U>();

            model.KeyA = Guid.NewGuid();
            provider.Persist(new Create <T>(model));

            var modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));

            AssertAreEqual <T, U>(model, modelCheck);

            UpdateModel <T, U>(model);
            provider.Persist(new Update <T>(model));
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));
            AssertAreEqual <T, U>(model, modelCheck);

            var relationModel = new U();

            relationModel.RelationAKey = Guid.NewGuid();
            relationProvider.Persist(new Create <U>(relationModel));
            var relationModelCheck = (U)relationProvider.Query(new QuerySingle <U>(x => x.RelationAKey == relationModel.RelationAKey));

            Assert.IsNotNull(relationModelCheck);

            model.RelationAKey = relationModel.RelationAKey;
            provider.Persist(new Update <T>(model, new Graph <T>(x => x.RelationAKey)));
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));
            Assert.AreEqual(model.RelationAKey, modelCheck.RelationAKey);
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA, new Graph <T>(x => x.RelationA)));
            Assert.IsNotNull(modelCheck.RelationA);
            Assert.AreEqual(model.RelationAKey, modelCheck.RelationA.RelationAKey);

            TestQuery(provider, model, relationModel);

            model.RelationAKey = null;
            provider.Persist(new Update <T>(model, new Graph <T>(x => x.RelationAKey)));
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));
            Assert.AreEqual(model.RelationAKey, modelCheck.RelationAKey);
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA, new Graph <T>(x => x.RelationA)));
            Assert.IsNull(model.RelationA);

            provider.Persist(new Delete <T>(model));
            modelCheck = (T)provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));
            Assert.IsNull(modelCheck);

            relationProvider.Persist(new Delete <U>(relationModel));
            relationModelCheck = (U)relationProvider.Query(new QuerySingle <U>(x => x.RelationAKey == relationModel.RelationAKey));
            Assert.IsNull(relationModelCheck);
        }
Ejemplo n.º 2
0
        public static void TestQuery <T, U>(ITransactStoreProvider <T> provider, T model, U relationModel)
            where T : BaseTestTypesModel <U>, new()
            where U : BaseTestRelationsModel, new()
        {
            //many
            provider.Query(new QueryMany <T>(x => x.KeyA == model.KeyA));

            //first
            provider.Query(new QueryFirst <T>(x => x.KeyA == model.KeyA));

            //single
            provider.Query(new QuerySingle <T>(x => x.KeyA == model.KeyA));

            //count
            provider.Query(new QueryCount <T>(x => x.KeyA == model.KeyA));

            //any
            provider.Query(new QueryAny <T>(x => x.KeyA == model.KeyA));

            var keyArray = new Guid[] { model.KeyA };

            //array index
            provider.Query(new QuerySingle <T>(x => x.KeyA == keyArray[0]));

            //date
            provider.Query(new QuerySingle <T>(x => x.DateTimeThing > DateTime.Now.AddYears(-1)));

            //date
            provider.Query(new QuerySingle <T>(x => x.DateTimeThing.Year > DateTime.Now.AddYears(-1).Year));

            //time
            provider.Query(new QuerySingle <T>(x => x.TimeSpanThing > TimeSpan.FromMilliseconds(123)));

            //string like
            provider.Query(new QuerySingle <T>(x => x.StringThing.Contains("World")));

            //LINQ contains
            provider.Query(new QuerySingle <T>(x => keyArray.Contains(x.KeyA)));

            //LINQ any
            provider.Query(new QuerySingle <T>(x => x.RelationB.Any(y => y.RelationAKey == relationModel.RelationAKey)));
        }