public void CanConstructNotEqualsCAMLQuery()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddNotEqual("Name", "Value");

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Neq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Neq></Where>", query.Query);
        }
        public void CanConstructNotEqualsCAMLQueryUsingInt()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddNotEqual("Name", 123);

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Neq><FieldRef Name='Name'/><Value Type='Integer'>123</Value></Neq></Where>", query.Query);
        }
        public void CanConstructNotEqualsCAMLQueryUsingDateTime()
        {
            CAMLQueryBuilder target           = new CAMLQueryBuilder();
            string           expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.MinValue);

            target.AddNotEqual("Name", DateTime.MinValue);

            SPQuery query = target.Build();

            Assert.AreEqual(string.Format("<Where><Neq><FieldRef Name='Name'/><Value Type='DateTime'>{0}</Value></Neq></Where>", expectedDateTime), query.Query);
        }
        public IEnumerable <PartnerSiteDirectoryEntry> GetAllPartnerSites()
        {
            List <PartnerSiteDirectoryEntry> partnerSiteDirectoryEntries = new List <PartnerSiteDirectoryEntry>();

            // Query for items in the Site Directory where the Partner field contains some value
            CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();

            camlQueryBuilder.AddNotEqual("PartnerDirectoryPartnerField", string.Empty);
            SPQuery query  = camlQueryBuilder.Build();
            ILogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>();

            logger.TraceToDeveloper(string.Format(CultureInfo.CurrentCulture,
                                                  "PartnerSiteDirectory FindPartnerMappingForCurrentPartner CAML: {0}",
                                                  query.Query));

            using (SPSite site = new SPSite(partnerDirectoryUrl))
            {
                using (SPWeb siteDirectory = site.OpenWeb())
                {
                    SPList siteCollectionMappingList = siteDirectory.Lists["Sites"];
                    SPListItemCollection items       = siteCollectionMappingList.GetItems(query);

                    foreach (SPListItem item in items)
                    {
                        PartnerSiteDirectoryEntry partnerSiteDirectoryEntry = new PartnerSiteDirectoryEntry();
                        partnerSiteDirectoryEntry.PartnerId = (string)item["PartnerDirectoryPartnerField"];
                        string url = item["URL"].ToString();
                        partnerSiteDirectoryEntry.SiteCollectionUrl = url.Split(",".ToCharArray())[0];
                        partnerSiteDirectoryEntry.Title             = (string)item["Title"];

                        partnerSiteDirectoryEntries.Add(partnerSiteDirectoryEntry);
                    }
                }
            }
            return(partnerSiteDirectoryEntries);
        }