示例#1
0
        public void test_WHEN_2_joins_are_specified_THEN_expressions_are_linked_correctly()
        {
            string xml =
                "<Joins>" +
                "<Join Type=\"LEFT\" ListAlias=\"Customers\">" +
                "<Eq>" +
                "<FieldRef Name=\"CustomerName\" RefType=\"Id\" />" +
                "<FieldRef List=\"Customers\" Name=\"Id\" />" +
                "</Eq>" +
                "</Join>" +
                "<Join Type=\"INNER\" ListAlias=\"CustomerCities\">" +
                "<Eq>" +
                "<FieldRef List=\"Customers\" Name=\"CityName\" RefType=\"Id\" />" +
                "<FieldRef List=\"CustomerCities\" Name=\"Id\" />" +
                "</Eq>" +
                "</Join>" +
                "</Joins>";

            var l = new ReLinkerFromCaml(null, null, null, null, XmlHelper.Get(xml), null);
            var g = new GroupByParams();

            Expression <Func <SPListItem, object> > ex1 = x => x["CustomerName"].ForeignList("Customers");
            Expression <Func <SPListItem, object> > ex2 = x => x["CityName"].PrimaryList("Customers").ForeignList("CustomerCities");
            var expr = l.Link(null, null, null, null, (new[] { new KeyValuePair <LambdaExpression, JoinType>(ex1, JoinType.Left), new KeyValuePair <LambdaExpression, JoinType>(ex2, JoinType.Inner) }).ToList(), null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().Joins().Left(x => x.get_Item(\"CustomerName\").ForeignList(\"Customers\")).Inner(x => x.get_Item(\"CityName\").PrimaryList(\"Customers\").ForeignList(\"CustomerCities\"))"));
        }
示例#2
0
        public void test_WHEN_fluent_part_and_view_fields_are_specified_THEN_exception_is_thrown()
        {
            var l = new ReLinkerFromCaml(null, null, null, null, null, null);
            var g = new GroupByParams();

            l.Link((Expression <Func <SPListItem, bool> >)(x => (int)x["foo"] == 1), null, null, (Expression <Func <SPListItem, object[]> >)(x => new[] { x["field1"], x["field2"] }), null, null, g);
        }
示例#3
0
        public void test_WHEN_where_is_specified_THEN_expressions_are_linked_correctly()
        {
            var l    = new ReLinkerFromCaml(null, null, null, null, null, null);
            var g    = new GroupByParams();
            var expr = l.Link((Expression <Func <SPListItem, bool> >)(x => (int)x["foo"] == 1), null, null, null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().Where(x => (Convert(x.get_Item(\"foo\")) = 1))"));
        }
示例#4
0
        public void test_WHEN_order_by_is_specified_but_is_empty_THEN_expression_is_empty()
        {
            var orderBy =
                "  <OrderBy>" +
                "  </OrderBy>";

            var l    = new ReLinkerFromCaml(null, XmlHelper.Get(orderBy), null, null, null, null);
            var g    = new GroupByParams();
            var expr = l.Link(null, (Expression <Func <SPListItem, object> >)(x => x["Title"] as Camlex.Asc), null, null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query()"));
        }
示例#5
0
        public void test_WHEN_where_and_order_by_are_specified_THEN_expressions_are_linked_correctly()
        {
            var orderBy =
                "  <OrderBy>" +
                "    <FieldRef Name=\"Title\" Ascending=\"True\" />" +
                "  </OrderBy>";

            var l    = new ReLinkerFromCaml(null, XmlHelper.Get(orderBy), null, null, null, null);
            var g    = new GroupByParams();
            var expr = l.Link((Expression <Func <SPListItem, bool> >)(x => (int)x["foo"] == 1), (Expression <Func <SPListItem, object> >)(x => x["Title"] as Camlex.Asc), null, null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().Where(x => (Convert(x.get_Item(\"foo\")) = 1)).OrderBy(x => (x.get_Item(\"Title\") As Asc))"));
        }
示例#6
0
        public void test_WHEN_view_field_is_specified_THEN_expressions_are_linked_correctly()
        {
            string viewFields =
                "<ViewFields>" +
                "<FieldRef Name=\"field1\" />" +
                "</ViewFields>";

            var l    = new ReLinkerFromCaml(null, null, null, XmlHelper.Get(viewFields), null, null);
            var g    = new GroupByParams();
            var expr = l.Link(null, null, null, (Expression <Func <SPListItem, object> >)(x => x["field1"]), null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().ViewFields(x => x.get_Item(\"field1\"), True)"));
        }
示例#7
0
        public void test_WHEN_group_by_is_specified_THEN_expressions_are_linked_correctly()
        {
            var groupBy =
                "  <GroupBy>" +
                "    <FieldRef Name=\"field1\" />" +
                "  </GroupBy>";

            var l    = new ReLinkerFromCaml(null, null, XmlHelper.Get(groupBy), null, null, null);
            var g    = new GroupByParams();
            var expr = l.Link(null, null, (Expression <Func <SPListItem, object> >)(x => x["field1"]), null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().GroupBy(x => x.get_Item(\"field1\"))"));
        }
示例#8
0
        public void test_WHEN_several_order_by_are_specified_THEN_expressions_are_linked_correctly()
        {
            var orderBy =
                "  <OrderBy>" +
                "    <FieldRef Name=\"Title\" />" +
                "    <FieldRef Name=\"Date\" Ascending=\"False\" />" +
                "  </OrderBy>";

            var l    = new ReLinkerFromCaml(null, XmlHelper.Get(orderBy), null, null, null, null);
            var g    = new GroupByParams();
            var expr = l.Link(null, (Expression <Func <SPListItem, object[]> >)(x => new[] { x["Title"], x["Date"] as Camlex.Desc }), null, null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().OrderBy(x => new [] {x.get_Item(\"Title\"), (x.get_Item(\"Date\") As Desc)})"));
        }
示例#9
0
        public void test_WHEN_1_projected_field_is_specified_THEN_expressions_are_linked_correctly()
        {
            string xml =
                "<ProjectedFields>" +
                "<Field Name=\"test\" Type=\"Lookup\" List=\"foo\" ShowField=\"bar\" />" +
                "</ProjectedFields>";

            var l = new ReLinkerFromCaml(null, null, null, null, null, XmlHelper.Get(xml));
            var g = new GroupByParams();

            Expression <Func <SPListItem, object> > ex = x => x["test"].List("foo").ShowField("bar");
            var expr = l.Link(null, null, null, null, null, (new[] { (LambdaExpression)ex }).ToList(), g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().ProjectedFields().Field(x => x.get_Item(\"test\").List(\"foo\").ShowField(\"bar\"))"));
        }
示例#10
0
        public void test_WHEN_group_by_with_collapse_and_group_limit_is_specified_THEN_expressions_are_linked_correctly()
        {
            var groupBy =
                "  <GroupBy Collapse=\"True\" GroupLimit=\"1\">" +
                "    <FieldRef Name=\"field1\" />" +
                "  </GroupBy>";

            var l = new ReLinkerFromCaml(null, null, XmlHelper.Get(groupBy), null, null, null);
            var g = new GroupByParams {
                HasCollapse = true, Collapse = true, HasGroupLimit = true, GroupLimit = 1
            };
            var expr = l.Link(null, null, (Expression <Func <SPListItem, object> >)(x => x["field1"]), null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().GroupBy(x => x.get_Item(\"field1\"), True, 1)"));
        }
示例#11
0
        public void test_WHEN_group_by_with_group_limit_is_specified_with_several_fied_refs_THEN_expressions_are_linked_correctly()
        {
            var groupBy =
                "  <GroupBy GroupLimit=\"1\">" +
                "    <FieldRef Name=\"field1\" />" +
                "    <FieldRef Name=\"field2\" />" +
                "  </GroupBy>";

            var l = new ReLinkerFromCaml(null, null, XmlHelper.Get(groupBy), null, null, null);
            var g = new GroupByParams {
                HasGroupLimit = true, GroupLimit = 1
            };
            var expr = l.Link(null, null, (Expression <Func <SPListItem, object[]> >)(x => new[] { x["field1"], x["field2"] }), null, null, null, g);

            Assert.That(expr.ToString(), Is.EqualTo("Query().GroupBy(x => new [] {x.get_Item(\"field1\"), x.get_Item(\"field2\")}, null, 1)"));
        }