public void FilterGenericFilter2()
        {
            int sourceCounter = 0;
            var sourceQuery = new[] { "aa1", "bb1", "bb2" }.Select(s => { sourceCounter++; return(new SimpleEntity {
                    Name = s
                }); }).AsQueryable();
            var gf = new[] { new FilterCriteria {
                                 Property = "Name", Operation = "StartsWith", Value = "b"
                             } };

            var impRepos = new ImplicitGenericPropertyFilterRepository();

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(0, sourceCounter);

            var exp  = NewRepos(new ExplicitGenericPropertyFilterRepository()).Filter(sourceQuery, gf);
            var exp2 = NewRepos(new ExplicitGenericPropertyFilterRepository2()).Filter(sourceQuery, gf);
            var imp  = NewRepos(impRepos).Filter(sourceQuery, gf);

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(6, sourceCounter);

            Assert.AreEqual("bb1, bb2", TestUtility.Dump(exp));
            Assert.AreEqual("exp2", TestUtility.Dump(exp2));
            Assert.AreEqual("bb1, bb2", TestUtility.Dump(imp));

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(6, sourceCounter);

            Assert.AreEqual("True, True, True", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IList)));
            Assert.AreEqual("False, False, False", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IQueryable)));

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(6, sourceCounter);

            exp  = NewRepos(new ExplicitGenericPropertyFilterRepository()).FilterOrQuery(sourceQuery, gf);
            exp2 = NewRepos(new ExplicitGenericPropertyFilterRepository2()).FilterOrQuery(sourceQuery, gf);
            imp  = NewRepos(impRepos).FilterOrQuery(sourceQuery, gf);

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(6, sourceCounter);

            Assert.AreEqual("bb1, bb2", TestUtility.Dump(exp));
            Assert.AreEqual("exp2", TestUtility.Dump(exp2));
            Assert.AreEqual("bb1, bb2", TestUtility.Dump(imp));

            Assert.AreEqual(0, impRepos.Counter);
            Assert.AreEqual(12, sourceCounter);

            Assert.AreEqual("False, True, False", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IList)));
            Assert.AreEqual("True, False, True", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IQueryable)));
        }
Esempio n. 2
0
        public void LoadGenericFilter2()
        {
            var gf = new[] { new FilterCriteria {
                                 Property = "Name", Operation = "StartsWith", Value = "b"
                             } };

            var impRepos = new ImplicitGenericPropertyFilterRepository();

            Assert.AreEqual(0, impRepos.Counter);

            var exp  = NewRepos(new ExplicitGenericPropertyFilterRepository()).Load(gf);
            var exp2 = NewRepos(new ExplicitGenericPropertyFilterRepository2()).Load(gf);
            var imp  = NewRepos(impRepos).Load(gf);

            Assert.AreEqual(3, impRepos.Counter);

            Assert.AreEqual("exp", TestUtility.Dump(exp));
            Assert.AreEqual("exp2", TestUtility.Dump(exp2));
            Assert.AreEqual("b1, b2", TestUtility.Dump(imp));

            Assert.AreEqual(3, impRepos.Counter);

            Assert.AreEqual("True, True, True", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IList)));
            Assert.AreEqual("False, False, False", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IQueryable)));

            Assert.AreEqual(3, impRepos.Counter);

            exp  = NewRepos(new ExplicitGenericPropertyFilterRepository()).Read(gf, preferQuery: false);
            exp2 = NewRepos(new ExplicitGenericPropertyFilterRepository2()).Read(gf, preferQuery: false);
            imp  = NewRepos(impRepos).Read(gf, preferQuery: false);

            Assert.AreEqual(3, impRepos.Counter);

            Assert.AreEqual("exp", TestUtility.Dump(exp));
            Assert.AreEqual("exp2", TestUtility.Dump(exp2));
            Assert.AreEqual("b1, b2", TestUtility.Dump(imp));

            Assert.AreEqual(6, impRepos.Counter);

            Assert.AreEqual("True, True, False", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IList)));
            Assert.AreEqual("False, False, True", TestUtility.Dump(new object[] { exp, exp2, imp }.Select(o => o is IQueryable)));

            TestUtility.ShouldFail(() => NewRepos(new NullRepository()).Load(gf), "SimpleEntity", "does not implement", "PropertyFilter");
        }