Beispiel #1
0
    public void GivenValidationParentNode_WhenContentIndexedUnderDifferentParent_DocumentIsNotIndexed()
    {
        using (GetSynchronousContentIndex(false, out var index, out _, out _, 999))
        {
            var searcher = index.Searcher;

            var contentService = new ExamineDemoDataContentService();
            //get a node from the data repo
            var node = contentService.GetPublishedContentByXPath("//*[string-length(@id)>0 and number(@id)>0]")
                       .Root
                       .Elements()
                       .First();

            var valueSet = node.ConvertToValueSet(IndexTypes.Content);

            // Ignored since the path isn't under 999
            index.IndexItems(new[] { valueSet });
            Assert.AreEqual(0, searcher.CreateQuery().Id(valueSet.Id).Execute().TotalItemCount);

            // Change so that it's under 999 and verify
            var values = valueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());
            values["path"] = new List <object> {
                "-1,999," + valueSet.Id
            };
            var newValueSet = new ValueSet(valueSet.Id, valueSet.Category, valueSet.ItemType, values.ToDictionary(x => x.Key, x => (IEnumerable <object>)x.Value));
            index.IndexItems(new[] { newValueSet });
            Assert.AreEqual(1, searcher.CreateQuery().Id(valueSet.Id).Execute().TotalItemCount);
        }
    }
Beispiel #2
0
    public void Test_Sort_Order_Sorting()
    {
        long totalRecs;
        var  demoData = new ExamineDemoDataContentService(TestFiles.umbraco_sort);
        var  allRecs  = demoData.GetLatestContentByXPath("//*[@isDoc]")
                        .Root
                        .Elements()
                        .Select(x => Mock.Of <IContent>(
                                    m =>
                                    m.Id == (int)x.Attribute("id") &&
                                    m.ParentId == (int)x.Attribute("parentID") &&
                                    m.Level == (int)x.Attribute("level") &&
                                    m.CreatorId == 0 &&
                                    m.SortOrder == (int)x.Attribute("sortOrder") &&
                                    m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                    m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                    m.Name == (string)x.Attribute(UmbracoExamineFieldNames.NodeNameFieldName) &&
                                    m.GetCultureName(It.IsAny <string>()) ==
                                    (string)x.Attribute(UmbracoExamineFieldNames.NodeNameFieldName) &&
                                    m.Path == (string)x.Attribute("path") &&
                                    m.Properties == new PropertyCollection() &&
                                    m.Published == true &&
                                    m.ContentType == Mock.Of <ISimpleContentType>(mt =>
                                                                                  mt.Icon == "test" &&
                                                                                  mt.Alias == x.Name.LocalName &&
                                                                                  mt.Id == (int)x.Attribute("nodeType"))))
                        .ToArray();
        var contentService = Mock.Of <IContentService>(
            x => x.GetPagedDescendants(
                It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out totalRecs, It.IsAny <IQuery <IContent> >(), It.IsAny <Ordering>())
            ==
            allRecs);

        using (GetSynchronousContentIndex(false, out var index, out var contentRebuilder, out _, null, contentService))
        {
            index.CreateIndex();
            contentRebuilder.Populate(index);

            var searcher = index.Searcher;

            Assert.Greater(searcher.CreateQuery().All().Execute().TotalItemCount, 0);

            var numberSortedCriteria = searcher.CreateQuery()
                                       .ParentId(1148)
                                       .OrderBy(new SortableField("sortOrder", SortType.Int));
            var numberSortedResult = numberSortedCriteria.Execute();

            var stringSortedCriteria = searcher.CreateQuery()
                                       .ParentId(1148)
                                       .OrderBy(new SortableField("sortOrder")); //will default to string
            var stringSortedResult = stringSortedCriteria.Execute();

            Assert.AreEqual(12, numberSortedResult.TotalItemCount);
            Assert.AreEqual(12, stringSortedResult.TotalItemCount);

            Assert.IsTrue(IsSortedByNumber(numberSortedResult));
            Assert.IsFalse(IsSortedByNumber(stringSortedResult));
        }
    }
Beispiel #3
0
    public static IContentService GetMockContentService()
    {
        long longTotalRecs;
        var  demoData = new ExamineDemoDataContentService();

        var allRecs = demoData.GetLatestContentByXPath("//*[@isDoc]")
                      .Root
                      .Elements()
                      .Select((xmlElement, index) => Mock.Of <IContent>(
                                  m =>
                                  m.Id == (int)xmlElement.Attribute("id") &&
                                  // have every second one published and include the special one
                                  m.Published == (ExamineDemoDataContentService.ProtectedNode == (int)xmlElement.Attribute("id") ||
                                                  (index % 2 == 0 ? true : false)) &&
                                  m.ParentId == (int)xmlElement.Attribute("parentID") &&
                                  m.Level == (int)xmlElement.Attribute("level") &&
                                  m.CreatorId == 0 &&
                                  m.SortOrder == (int)xmlElement.Attribute("sortOrder") &&
                                  m.CreateDate == (DateTime)xmlElement.Attribute("createDate") &&
                                  m.UpdateDate == (DateTime)xmlElement.Attribute("updateDate") &&
                                  m.Name == (string)xmlElement.Attribute(UmbracoExamineFieldNames.NodeNameFieldName) &&
                                  m.GetCultureName(It.IsAny <string>()) ==
                                  (string)xmlElement.Attribute(UmbracoExamineFieldNames.NodeNameFieldName) &&
                                  m.Path == (string)xmlElement.Attribute("path") &&
                                  m.Properties == new PropertyCollection() &&
                                  m.ContentType == Mock.Of <ISimpleContentType>(mt =>
                                                                                mt.Icon == "test" &&
                                                                                mt.Alias == xmlElement.Name.LocalName &&
                                                                                mt.Id == (int)xmlElement.Attribute("nodeType"))))
                      .ToArray();


        return(Mock.Of <IContentService>(
                   x => x.GetPagedDescendants(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <IQuery <IContent> >(), It.IsAny <Ordering>())
                   == allRecs));
    }