Ejemplo n.º 1
0
        public void CAMLSimpleWhereGroupBy()
        {
            const string textQuery   = "WHERE Test=\"Value\" AND Other=2 GROUPBY Column1";
            const string spectedCAML = "<Query>" +
                                       "<Where>" +
                                       "<And>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "<Value Type=\"Text\">Value</Value>" +
                                       "</Eq>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Other\" />" +
                                       "<Value Type=\"Numeric\">2</Value>" +
                                       "</Eq>" +
                                       "</And>" +
                                       "</Where>" +
                                       "<Group>" +
                                       "<FieldRef Name=\"Column1\" />" +
                                       "</Group>" +
                                       "</Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 2
0
        public void Reload(IEnumerable <TextAsset> assets)
        {
            // combined text asset
            var text = string.Join("\n", assets.Select(a => a.text));

            code = NParser.Parse(text);
        }
Ejemplo n.º 3
0
        public void CAMLSimpleWhereParenthesis1()
        {
            const string textQuery = "WHERE ((Column1 = \"Value1\") AND " +
                                     "(Column2 = #01/01/2007#)) ";
            const string spectedCAML = "<Query>" +
                                       "<Where>" +
                                       "<And>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Column1\" />" +
                                       "<Value Type=\"Text\">Value1</Value>" +
                                       "</Eq>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Column2\" />" +
                                       "<Value Type=\"DateTime\">01/01/2007</Value>" +
                                       "</Eq>" +
                                       "</And>" +
                                       "</Where>" +
                                       "</Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 4
0
        public void Iterator_Test2()
        {
            var input = "ORDERBY Column1,Column2 DESC,Column3";

            var parser = new NParser(input);
            var caml   = parser.Parse();

            IEnumerable <ASTNode> ienumerable = ASTNodeIterator.PreOrderWalk(caml);

            Type[] typeNodes =
            {
                typeof(Query),
                typeof(Sequence),
                typeof(Sequence),
                typeof(OrderBy),
                typeof(FieldList),
                typeof(FieldNode),
                typeof(FieldList),
                typeof(FieldNode),
                typeof(FieldList),
                typeof(FieldNode),
                typeof(Sequence)
            };

            int checkType = 0;

            foreach (ASTNode node in ienumerable)
            {
                Type type = typeNodes[checkType++];
                Assert.AreEqual(type, node.GetType());

                Console.WriteLine(node.GetType());
            }
        }
Ejemplo n.º 5
0
        public void CAMLSimpleWhereParenthesisException()
        {
            const string textQuery = "WHERE Test=\"Value\" OR (Other=2 AND Test=1";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();
        }
Ejemplo n.º 6
0
        public void CAMLSimpleWhereParenthesis2()
        {
            const string textQuery = "WHERE ((Column1 = \"Value1\") AND " +
                                     "(Column2 = #01/01/2007#)) OR " +
                                     "((Column3 = 10) AND (Column3 <> 10)) " +
                                     "ORDERBY Column1, Column2 ASC, Column3 DESC " +
                                     "GROUPBY Column1 ";

            const string spectedCAML = "<Query>" +
                                       "<Where>" +
                                       "<Or>" +
                                       "<And>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Column1\" />" +
                                       "<Value Type=\"Text\">Value1</Value>" +
                                       "</Eq>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Column2\" />" +
                                       "<Value Type=\"DateTime\">01/01/2007</Value>" +
                                       "</Eq>" +
                                       "</And>" +
                                       "<And>" +
                                       "<Eq>" +
                                       "<FieldRef Name=\"Column3\" />" +
                                       "<Value Type=\"Numeric\">10</Value>" +
                                       "</Eq>" +
                                       "<Neq>" +
                                       "<FieldRef Name=\"Column3\" />" +
                                       "<Value Type=\"Numeric\">10</Value>" +
                                       "</Neq>" +
                                       "</And>" +
                                       "</Or>" +
                                       "</Where>" +
                                       "<Order>" +
                                       "<FieldRef Name=\"Column1\" />" +
                                       "<FieldRef Name=\"Column2\" Ascending=\"True\" />" +
                                       "<FieldRef Name=\"Column3\" Ascending=\"False\" />" +
                                       "</Order>" +
                                       "<Group>" +
                                       "<FieldRef Name=\"Column1\" />" +
                                       "</Group>" +
                                       "</Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 7
0
        public void WhereExpression_Test()
        {
            var input = "WHERE Column1 = \"Value1\" ";

            var parser = new NParser(input);
            var caml   = parser.Parse();

            Assert.IsInstanceOfType(typeof(Query), caml);
            Assert.IsInstanceOfType(typeof(Sequence), caml.LeftNode);
            Assert.IsInstanceOfType(typeof(Where), caml.LeftNode.LeftNode);

            Assert_WellFormedExpression(caml.LeftNode.LeftNode.LeftNode);
        }
Ejemplo n.º 8
0
        public void CAMLSimpleOrderBy()
        {
            const string textQuery   = "ORDERBY Test";
            const string spectedCAML = "<Query><Order>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "</Order></Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);
            Debug.WriteLine(generator.Code);
            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 9
0
        public void CAMLSimpleWhere()
        {
            const string textQuery   = "WHERE Test=\"Value\"";
            const string spectedCAML = "<Query><Where><Eq>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "<Value Type=\"Text\">Value</Value>" +
                                       "</Eq></Where></Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 10
0
        public void Iterator_Test()
        {
            var input = "WHERE Column1 = \"Value1\" OR Column2=2 AND Column3=#01/01/01#";

            var parser = new NParser(input);
            var caml   = parser.Parse();

            IEnumerable <ASTNode> ienumerable = ASTNodeIterator.PreOrderWalk(caml);

            Type[] typeNodes =
            {
                typeof(Query),
                typeof(Sequence),
                typeof(Where),
                typeof(BooleanOr),
                typeof(Expression),
                typeof(OpEqual),
                typeof(FieldNode),
                typeof(ValueNode),
                typeof(BooleanAnd),
                typeof(Expression),
                typeof(OpEqual),
                typeof(FieldNode),
                typeof(ValueNode),
                typeof(Expression),
                typeof(OpEqual),
                typeof(FieldNode),
                typeof(ValueNode),
                typeof(Sequence),
                typeof(Sequence)
            };

            int checkType = 0;

            foreach (ASTNode node in ienumerable)
            {
                Type type = typeNodes[checkType++];
                Assert.AreEqual(type, node.GetType());

                Console.WriteLine(node.GetType());
            }
        }
Ejemplo n.º 11
0
        public void CAMLSimpleWhere2()
        {
            const string textQuery   = "WHERE Test <> NULL";
            const string spectedCAML = "<Query>" +
                                       "<Where>" +
                                       "<IsNotNull>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "</IsNotNull>" +
                                       "</Where>" +
                                       "</Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            CodeGenerator generator = new CodeGenerator(parser.Parse());

            Assert.IsNotNull(generator);

            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 12
0
        public void CAMLSimpleGroupBy_Fields()
        {
            const string textQuery   = "GROUPBY Test,Column2,Column3";
            const string spectedCAML = "<Query><Group>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "<FieldRef Name=\"Column2\" />" +
                                       "<FieldRef Name=\"Column3\" />" +
                                       "</Group></Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            Query query = parser.Parse();

            CodeGenerator generator = new CodeGenerator(query);

            Assert.IsNotNull(generator);
            Debug.WriteLine(generator.Code);
            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 13
0
        public void CAMLSimpleOrderBy_Fields_AscendingDescending()
        {
            const string textQuery   = "ORDERBY Test, Column2 DESC,Column3";
            const string spectedCAML = "<Query><Order>" +
                                       "<FieldRef Name=\"Test\" />" +
                                       "<FieldRef Name=\"Column2\" Ascending=\"False\" />" +
                                       "<FieldRef Name=\"Column3\" />" +
                                       "</Order></Query>";

            NParser parser = new NParser(textQuery, new ASTNodeCAMLFactory());

            Query query = parser.Parse();

            CodeGenerator generator = new CodeGenerator(query);

            Assert.IsNotNull(generator);
            Debug.WriteLine(generator.Code);
            generator.Generate();

            Assert.AreEqual(spectedCAML, generator.Code);
        }
Ejemplo n.º 14
0
        public void WhereExpression_Test_Or_And_Parenthesis()
        {
            var input = "WHERE (Column1 = \"Value1\" OR Column2=2) AND Column3=#01/01/01#";

            var parser = new NParser(input);
            var caml   = parser.Parse();

            Assert.IsInstanceOfType(typeof(Query), caml);
            Assert.IsInstanceOfType(typeof(Sequence), caml.LeftNode);
            Assert.IsInstanceOfType(typeof(Where), caml.LeftNode.LeftNode);

            Where where = caml.LeftNode.LeftNode as Where;

            Assert.IsInstanceOfType(typeof(BooleanAnd), where.LeftNode);
            Assert.IsInstanceOfType(typeof(BooleanOr), where.LeftNode.LeftNode);

            Assert_WellFormedExpression(where.LeftNode.RightNode);

            Assert_WellFormedExpression(where.LeftNode.LeftNode.LeftNode);
            Assert_WellFormedExpression(where.LeftNode.LeftNode.RightNode);
        }
Ejemplo n.º 15
0
        public void Constructor()
        {
            var parser = new NParser("TEST");

            Assert.IsNotNull(parser);
        }