Exemplo n.º 1
0
        public void test_sample_driver()
        {
            AndCriterium 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));

            Assert.IsNotEmpty(ands);

            string query = SampleDriver.GetQuery(ands);

            DebugHelper.WriteToConsole("query = " + query);
            Assert.AreEqual("id = '2' and id > '2' and id < '2' and id like '%2%'", query);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        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);
        }