Esempio n. 1
0
        public void test_less_than_visit()
        {
            CriteriaVisitor visitor = new CriteriaVisitor();
            LessThanCriteria criteria = new LessThanCriteria("id", 2);

            string shard = criteria.GetShard(visitor);

            DebugHelper.WriteToConsole("shard = " + shard);
            Assert.AreEqual("id < '2'", shard);
        }
Esempio n. 2
0
        public void test_like_visit()
        {
            CriteriaVisitor visitor = new CriteriaVisitor();
            LikeCriteria criteria = new LikeCriteria("id", 2);

            string shard = criteria.GetShard(visitor);

            DebugHelper.WriteToConsole("shard = " + shard);
            Assert.AreEqual("id like '%2%'", shard);
        }
Esempio n. 3
0
        public void test_equals_visit()
        {
            CriteriaVisitor visitor = new CriteriaVisitor();
            EqualsCriteria criteria = new EqualsCriteria("id", 2);

            string shard = criteria.GetShard(visitor);

            DebugHelper.WriteToConsole("shard = " + shard);
            Assert.AreEqual("id = '2'", shard);
        }
Esempio n. 4
0
        public static string GetQuery(AndCriterium criterium)
        {
            CriteriaVisitor visitor = new CriteriaVisitor();

            StringBuilder sb = new StringBuilder();

            int loop = 0;
            foreach (ICriteria criteria in criterium)
            {
                sb.Append(criteria.GetShard(visitor));

                if (loop == criterium.Count - 1) break;

                sb.Append(" and ");
                loop++;
            }

            return sb.ToString();
        }
        public void test_criterium_shards()
        {
            CriteriaVisitor visitor = new CriteriaVisitor();

            AbstractCriterium ands = new AndCriterium();

            ands.Add(new EqualsCriteria("id", 2));
            ands.Add(new GreaterThanCriteria("id", 2));
            ands.Add(new LessThanCriteria("id", 2));
            ands.Add(new LikeCriteria("id", 2));

            List<string> shards = new List<string>();
            foreach(ICriteria criteria in ands)
                shards.Add( criteria.GetShard(visitor) );

            Assert.IsNotEmpty(shards);

            string joined = String.Empty;
            foreach(string shard in shards)
                joined += shard + ",";

            DebugHelper.WriteToConsole("joined = " + joined);
            Assert.AreEqual("id = '2',id > '2',id < '2',id like '%2%',", joined);
        }