Exemplo n.º 1
0
        public void Test()
        {
            var rawQuery = @"<View Scope=""RecursiveAll"">
                <Query>
                    <Where>
                        <IsNotNull>
                            <FieldRef Name=""ID"" />
                        </IsNotNull>
                    </Where>
                </Query>
            </View>";

            var caml = CAML.FromXml(rawQuery).ModifyWhere().AppendAnd().TextField("Title").IsNotNull().ToString();

            string expected = @"<View Scope=""RecursiveAll"">
                <Query>
                    <Where>
                        <And>
                            <IsNotNull>
                                <FieldRef Name=""ID"" />
                            </IsNotNull>
                            <IsNotNull>
                                <FieldRef Name=""Title"" />
                            </IsNotNull>
                        </And>
                    </Where>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 2
0
        public void Test()
        {
            string caml = CAML.Where()
                          .Any(
                CAML.Expression().TextField("Email").EqualTo("*****@*****.**"),
                CAML.Expression().TextField("Email").EqualTo("*****@*****.**"),
                CAML.Expression().TextField("Title").BeginsWith("[Google]"),
                CAML.Expression().TextField("Content").Contains("Google")
                )
                          .ToString();

            string expected = @"<Where>
                    <Or>
                        <Eq><FieldRef Name=""Email"" /><Value Type=""Text"">[email protected]</Value></Eq>
                        <Or>
                            <Eq><FieldRef Name=""Email"" /><Value Type=""Text"">[email protected]</Value></Eq>
                            <Or>
                                <BeginsWith><FieldRef Name=""Title"" /><Value Type=""Text"">[Google]</Value></BeginsWith>
                                <Contains><FieldRef Name=""Content"" /><Value Type=""Text"">Google</Value></Contains>
                            </Or>
                        </Or>
                    </Or>
                </Where>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 3
0
        public void Test()
        {
            var caml = CAML.Where()
                       .LookupField("Category").Id().In(new int[] { 2, 3, 10 })
                       .And()
                       .DateField("ExpirationDate").GreaterThan(CamlValues.Now)
                       .OrderBy("ExpirationDate")
                       .ToString();

            string expected = @"<Where>
                  <And>
                    <In>
                      <FieldRef Name=""Category"" LookupId=""True"" />
                      <Values>
                        <Value Type=""Integer"">2</Value>
                        <Value Type=""Integer"">3</Value>
                        <Value Type=""Integer"">10</Value>
                      </Values>
                    </In>
                    <Gt>
                      <FieldRef Name=""ExpirationDate"" />
                      <Value Type=""DateTime"">
                        <Now />
                      </Value>
                    </Gt>
                  </And>
                </Where>
                <OrderBy>
                  <FieldRef Name=""ExpirationDate"" />
                </OrderBy>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 4
0
        public void Test()
        {
            var caml = CAML.Where()
                       .UserField("AssignedTo").EqualToCurrentUser()
                       .Or()
                       .UserField("AssignedTo").IsInCurrentUserGroups()
                       .GroupBy("Category")
                       .OrderBy("Priority").ThenBy("Title")
                       .ToString();

            string expected = @"<Where>
                    <Or>
                        <Eq><FieldRef Name=""AssignedTo"" LookupId=""True"" /><Value Type=""Integer""><UserID /></Value></Eq>
                        <Membership Type=""CurrentUserGroups""><FieldRef Name=""AssignedTo"" /></Membership>
                    </Or>
                </Where>
                <GroupBy>
                    <FieldRef Name=""Category"" />
                </GroupBy>
                <OrderBy>
                    <FieldRef Name=""Priority"" /><FieldRef Name=""Title"" />
                </OrderBy>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 5
0
        public void Test()
        {
            var caml = CAML
                       .View(new string[] { "Category" }, (AggregationType.Count, "ID"), (AggregationType.Sum, "Amount"))
                       .Query()
                       .GroupBy("Category", true, 100)
                       .ToString();

            string expected = @"<View>
                <ViewFields>
                    <FieldRef Name=""Category"" />
                </ViewFields>
                <Aggregations Value=""On"">
                    <FieldRef Name=""ID"" Type=""COUNT"" />
                    <FieldRef Name=""Amount"" Type=""SUM"" />
                </Aggregations>
                <Query>
                    <GroupBy Collapse=""TRUE"" GroupLimit=""100"">
						<FieldRef Name=""Category"" />
                    </GroupBy>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 6
0
        public void Test()
        {
            var caml = CAML.Where().DateTimeField("Created").GreaterThan(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToString();

            string expected = @"<Where>
                <Gt>
                    <FieldRef Name=""Created"" />
                    <Value IncludeTimeValue=""True"" Type=""DateTime"">2013-01-01T00:00:00.000Z</Value>
                </Gt>
            </Where>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 7
0
        public void Test()
        {
            var caml = CAML.Where().CounterField("ID").In(new int[] { 1, 2, 3 }).ToString();

            string expected = @"<Where>
                <In>
                    <FieldRef Name=""ID"" />
                    <Values>
                        <Value Type=""Counter"">1</Value>
                        <Value Type=""Counter"">2</Value>
                        <Value Type=""Counter"">3</Value>
                    </Values>
                </In>
            </Where>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 8
0
        public void Test()
        {
            var caml = CAML
                       .View()
                       .Query()
                       .OrderBy("ID")
                       .ToString();

            string expected = @"<View>
                <Query>
                    <OrderBy>
						<FieldRef Name=""ID"" />
                    </OrderBy>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 9
0
        public void Test()
        {
            var expression = CAML.Expression().BooleanField("Enabled").IsTrue();

            var caml = CAML.View().Query().Where().All(expression).OrderBy("Priority").ToString();

            string expected = @"<View>
                    <Query>
                        <Where>
                            <Eq><FieldRef Name=""Enabled"" /><Value Type=""Integer"">1</Value></Eq>
                        </Where>
                        <OrderBy>
                            <FieldRef Name=""Priority"" />
                        </OrderBy>
                    </Query>
                </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 10
0
        public void Test()
        {
            var caml = CAML.Expression()
                       .All(
                CAML.Expression().DateField("BroadcastExpires").GreaterThanOrEqualTo(CamlValues.Today),
                CAML.Expression().Any(
                    CAML.Expression().UserField("BroadcastTo").IsInCurrentUserGroups(),
                    CAML.Expression().UserField("BroadcastTo").EqualToCurrentUser()
                    ),
                CAML.Expression().DateRangesOverlap(DateRangesOverlapType.Year, new DateTime().ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"))
                )
                       .ToString();

            string expected = @"<And>
                <Geq>
                    <FieldRef Name=""BroadcastExpires"" />
                    <Value Type=""DateTime"">
                        <Today />
                    </Value>
                </Geq>
                <And>
                    <Or>
                        <Membership Type=""CurrentUserGroups"">
                        <FieldRef Name=""BroadcastTo"" />
                        </Membership>
                        <Eq>
                        <FieldRef Name=""BroadcastTo"" LookupId=""True"" />
                        <Value Type=""Integer""><UserID /></Value>
                        </Eq>
                    </Or>
                    <DateRangesOverlap>
                        <FieldRef Name=""EventDate"" />
                        <FieldRef Name=""EndDate"" />
                        <FieldRef Name=""RecurrenceID"" />
                        <Value Type=""DateTime"">
                        <Year />
                        </Value>
                    </DateRangesOverlap>
                </And>
            </And>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 11
0
        public void Test()
        {
            var caml = CAML
                       .View()
                       .Scope(ViewScope.RecursiveAll)
                       .Query()
                       .Where().NumberField("ID").IsNotNull()
                       .ToString();

            string expected = @"<View Scope=""RecursiveAll"">
                <Query>
                    <Where>
                        <IsNotNull>
                            <FieldRef Name=""ID"" />
                        </IsNotNull>
                    </Where>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
        public void Test()
        {
            var rawQuery = @"<View Scope=""RecursiveAll"">
                <Query>
                    <Where>
                        <Eq>
                            <FieldRef Name=""ID"" />
                            <Value Type=""Number"">10</Value>
                        </Eq>
                    </Where>
                    <OrderBy>
                        <FieldRef Name=""Date"" />
                    </OrderBy>
                </Query>
            </View>";

            var caml = CAML.FromXml(rawQuery).ModifyWhere().AppendOr().TextField("Title").Contains("Summer").ToString();

            string expected = @"<View Scope=""RecursiveAll"">
                <Query>
                    <OrderBy>
                        <FieldRef Name=""Date"" />
                    </OrderBy>
                    <Where>
                        <Or>
                            <Eq>
                                <FieldRef Name=""ID"" />
                                <Value Type=""Number"">10</Value>
                            </Eq>
                            <Contains>
                                <FieldRef Name=""Title"" />
                                <Value Type=""Text"">Summer</Value>
                            </Contains>
                        </Or>
                    </Where>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 13
0
        public void Test()
        {
            var caml = CAML
                       .View(new string[] { "Title", "Country", "Population" })
                       .LeftJoin("Country", "Country").Select("y4r6", "Population")
                       .Query()
                       .Where().NumberField("Population").LessThan(10)
                       .ToString();

            string expected = @"<View>
                <ViewFields>
                    <FieldRef Name=""Title"" />
                    <FieldRef Name=""Country"" />
                    <FieldRef Name=""Population"" />
                </ViewFields>
                <Joins>
                    <Join Type=""LEFT"" ListAlias=""Country"">
                        <Eq>
                            <FieldRef Name=""Country"" RefType=""ID"" />
                            <FieldRef Name=""ID"" List=""Country"" />
                        </Eq>
                    </Join>
                </Joins>
                <ProjectedFields>
                    <Field ShowField=""y4r6"" Type=""Lookup"" Name=""Population"" List=""Country"" />
                </ProjectedFields>
                <Query>
                    <Where>
                        <Lt>
                            <FieldRef Name=""Population"" />
                            <Value Type=""Number"">10</Value>
                        </Lt>
                    </Where>
                </Query>
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
        public void Test()
        {
            var caml = CAML.Where()
                       .All(
                CAML.Expression().All(
                    CAML.Expression().BooleanField("Enabled").IsTrue(),
                    CAML.Expression().UserMultiField("TargetAudience").IncludesSuchItemThat().ValueAsText().EqualTo("55").Or().UserMultiField("TargetAudience").IncludesSuchItemThat().ValueAsText().EqualTo("66")
                    ),
                CAML.Expression().Any(
                    CAML.Expression().TextField("NotificationScope").EqualTo("77"),
                    CAML.Expression().TextField("NotificationScope").EqualTo("88").And().TextField("ScopeWebRelativeUrl").EqualTo("99")
                    )
                )
                       .ToString();

            string expected = @"<Where>
                    <And>
                        <And>
                            <Eq><FieldRef Name=""Enabled"" /><Value Type=""Integer"">1</Value></Eq>
                            <Or>
                                <Eq><FieldRef Name=""TargetAudience"" /><Value Type=""Text"">55</Value></Eq>
                                <Eq><FieldRef Name=""TargetAudience"" /><Value Type=""Text"">66</Value></Eq>
                            </Or>
                        </And>
                        <Or>
                            <Eq><FieldRef Name=""NotificationScope"" /><Value Type=""Text"">77</Value></Eq>
                            <And>
                                <Eq><FieldRef Name=""NotificationScope"" /><Value Type=""Text"">88</Value></Eq>
                                <Eq><FieldRef Name=""ScopeWebRelativeUrl"" /><Value Type=""Text"">99</Value></Eq>
                            </And>
                        </Or>
                    </And>
                </Where>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
Exemplo n.º 15
0
        public void Test()
        {
            var caml = CAML
                       .View(new string[] { "Title", "CustomerCity" })
                       .LeftJoin("CustomerName", "customers")
                       .LeftJoin("CityName", "customerCities", "customers")
                       .Select("Title", "CustomerCity")
                       .Query()
                       .ToString();

            string expected = @"<View>
                <ViewFields>
                    <FieldRef Name=""Title"" />
                    <FieldRef Name=""CustomerCity"" />
                </ViewFields>
                <Joins>
                  <Join Type=""LEFT"" ListAlias=""customers"">
                    <Eq>
                      <FieldRef Name=""CustomerName"" RefType=""ID"" />
                      <FieldRef Name=""ID"" List=""customers"" />
                    </Eq>
                  </Join>
                  <Join Type=""LEFT"" ListAlias=""customerCities"">
                    <Eq>
                      <FieldRef Name=""CityName"" RefType=""ID"" List=""customers"" />
                      <FieldRef Name=""ID"" List=""customerCities"" />
                    </Eq>
                  </Join>
                </Joins>
                <ProjectedFields>
                    <Field ShowField=""Title"" Type=""Lookup"" Name=""CustomerCity"" List=""customerCities"" />
                </ProjectedFields>
                <Query />
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));

            caml = CAML
                   .View(new string[] { "Title", "CustomerName", "CustomerCity" })
                   .LeftJoin("CustomerName", "customers")
                   .Select("Title", "CustomerName")
                   .LeftJoin("CityName", "customerCities", "customers")
                   .Select("Title", "CustomerCity")
                   .Query()
                   .ToString();

            expected = @"<View>
                <ViewFields>
                    <FieldRef Name=""Title"" />
                    <FieldRef Name=""CustomerName"" />
                    <FieldRef Name=""CustomerCity"" />
                </ViewFields>
                <Joins>
                  <Join Type=""LEFT"" ListAlias=""customers"">
                    <Eq>
                      <FieldRef Name=""CustomerName"" RefType=""ID"" />
                      <FieldRef Name=""ID"" List=""customers"" />
                    </Eq>
                  </Join>
                  <Join Type=""LEFT"" ListAlias=""customerCities"">
                    <Eq>
                      <FieldRef Name=""CityName"" RefType=""ID"" List=""customers"" />
                      <FieldRef Name=""ID"" List=""customerCities"" />
                    </Eq>
                  </Join>
                </Joins>
                <ProjectedFields>
                    <Field ShowField=""Title"" Type=""Lookup"" Name=""CustomerName"" List=""customers"" />
                    <Field ShowField=""Title"" Type=""Lookup"" Name=""CustomerCity"" List=""customerCities"" />
                </ProjectedFields>
                <Query />
            </View>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }
        public void Test()
        {
            var categories = new List <string>()
            {
                "Platform Support", "Research and Strategy"
            };
            var purposes = new List <string>()
            {
                "Application and User Lists", "How To", "Support Information"
            };

            var categoriesExpressions = new List <IExpression>();

            foreach (var category in categories)
            {
                categoriesExpressions.Add(CAML.Expression().TextField("ContentCategory").EqualTo(category));
            }

            var purposesExpressions = new List <IExpression>();

            foreach (var purpose in purposes)
            {
                purposesExpressions.Add(CAML.Expression().TextField("ContentPurpose").EqualTo(purpose));
            }

            var caml = CAML.Where()
                       .All(
                CAML.Expression().Any(categoriesExpressions.ToArray()),
                CAML.Expression().Any(purposesExpressions.ToArray())
                )
                       .ToString();

            string expected = @"<Where>
                    <And>
                        <Or>
                            <Eq>
                                <FieldRef Name=""ContentCategory"" />
                                <Value Type=""Text"">Platform Support</Value>
                            </Eq>
                            <Eq>
                                <FieldRef Name=""ContentCategory"" />
                                <Value Type=""Text"">Research and Strategy</Value>
                            </Eq>
                        </Or>
                        <Or>
                            <Eq>
                                <FieldRef Name=""ContentPurpose"" />
                                <Value Type=""Text"">Application and User Lists</Value>
                            </Eq>
                            <Or>
                                <Eq>
                                    <FieldRef Name=""ContentPurpose"" />
                                    <Value Type=""Text"">How To</Value>
                                </Eq>
                                <Eq>
                                    <FieldRef Name=""ContentPurpose"" />
                                    <Value Type=""Text"">Support Information</Value>
                                </Eq>
                            </Or>
                        </Or>
                    </And>
                </Where>";

            Assert.AreEqual(Beautify.Xml(expected), Beautify.Xml(caml));
        }