Ejemplo n.º 1
0
        public void AssociationToFilteredEntityFunc([IncludeDataSources(false, TestProvName.AllSQLite)] string context)
        {
            var testData = GenerateTestData();

            Expression <Func <ISoftDelete, MyDataContext, bool> > softDeleteCheck = (e, dc) => !dc.IsSoftDeleteFilterEnabled || !e.IsDeleted;
            var builder = new MappingSchema().GetFluentMappingBuilder();

            builder.Entity <MasterClass>().HasQueryFilter <MyDataContext>((q, dc) => q.Where(e => softDeleteCheck.Compile()(e, dc)));
            builder.Entity <DetailClass>().HasQueryFilter <MyDataContext>((q, dc) => q.Where(e => softDeleteCheck.Compile()(e, dc)));

            var ms = builder.MappingSchema;

            using (new AllowMultipleQuery())
                using (var db = new MyDataContext(context, ms))
                    using (db.CreateLocalTable(testData.Item1))
                        using (db.CreateLocalTable(testData.Item2))
                            using (db.CreateLocalTable(testData.Item3))
                            {
                                var query = from m in db.GetTable <MasterClass>().IgnoreFilters()
                                            from d in m.Details
                                            select d;

                                CheckFiltersForQuery(db, query);
                            }
        }
Ejemplo n.º 2
0
        public void EntityFilterTestsCache([IncludeDataSources(false, TestProvName.AllSQLite)] string context, [Values(1, 2, 3)] int iteration, [Values] bool filtered)
        {
            var testData = GenerateTestData();

            using (var db = new MyDataContext(context, _filterMappingSchema))
                using (db.CreateLocalTable(testData.Item1))
                {
                    var currentMissCount = Query <MasterClass> .CacheMissCount;

                    var query = from m in db.GetTable <MasterClass>()
                                select m;

                    ((DcParams)db.Params).IsSoftDeleteFilterEnabled = filtered;

                    var result = query.ToList();

                    if (filtered)
                    {
                        result.Count.Should().BeLessThan(testData.Item1.Length);
                    }
                    else
                    {
                        result.Count.Should().Be(testData.Item1.Length);
                    }

                    if (iteration > 1)
                    {
                        Query <MasterClass> .CacheMissCount.Should().Be(currentMissCount);
                    }
                }
        }
Ejemplo n.º 3
0
        public void EntityFilterTests([IncludeDataSources(false, TestProvName.AllSQLite)] string context)
        {
            var testData = GenerateTestData();

            var builder = new MappingSchema().GetFluentMappingBuilder();

            builder.Entity <MasterClass>().HasQueryFilter <MyDataContext>((q, dc) => q.Where(e => !dc.IsSoftDeleteFilterEnabled || !e.IsDeleted));
            builder.Entity <DetailClass>().HasQueryFilter <MyDataContext>((q, dc) => q.Where(e => !dc.IsSoftDeleteFilterEnabled || !e.IsDeleted));

            var ms = builder.MappingSchema;

            using (var db = new MyDataContext(context, ms))
                using (db.CreateLocalTable(testData.Item1))
                    using (db.CreateLocalTable(testData.Item2))
                        using (db.CreateLocalTable(testData.Item3))
                        {
                            var query = from m in db.GetTable <MasterClass>()
                                        select m;

                            CheckFiltersForQuery(db, query);
                        }
        }
Ejemplo n.º 4
0
        public void AssociationToFilteredEntityMethod([IncludeDataSources(false, TestProvName.AllSQLite)] string context)
        {
            var testData = GenerateTestData();

            var builder = new MappingSchema().GetFluentMappingBuilder();

            builder.Entity <MasterClass>().HasQueryFilter <MyDataContext>(FilterDeletedCondition);
            builder.Entity <DetailClass>().HasQueryFilter <MyDataContext>(FilterDeletedCondition);

            var ms = builder.MappingSchema;

            using (var db = new MyDataContext(context, ms))
                using (db.CreateLocalTable(testData.Item1))
                    using (db.CreateLocalTable(testData.Item2))
                        using (db.CreateLocalTable(testData.Item3))
                        {
                            var query = from m in db.GetTable <MasterClass>().IgnoreFilters()
                                        from d in m.Details !
                                        select d;

                            CheckFiltersForQuery(db, query);
                        }
        }