private void VerifyCorrectNewsOnPageWithCategoryFilterAndPaging(HierarchicalTaxon category0, HierarchicalTaxon category1, NewsController newsController, string[] newsTitles)
        {
            ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(category0.Id);
            var    items    = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[3 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[0], StringComparison.CurrentCulture), "The news with this title was found!");

            taxonomy = TaxonomyManager.GetManager().GetTaxon(category1.Id);
            items    = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[4 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[1], StringComparison.CurrentCulture), "The news with this title was found!");
        }
Ejemplo n.º 2
0
 public JobProfileCategoryRepositoryUnitTests()
 {
     fakeSearchService      = A.Fake <ISearchQueryService <JobProfileIndex> >();
     fakeMapper             = A.Fake <IMapper>();
     dummyTaxon             = GetDummyTaxon("categoryTwo");
     fakeTaxonomyRepository = A.Fake <ITaxonomyRepository>();
 }
Ejemplo n.º 3
0
        private HierarchicalTaxon CreateCategory(string categoryName)
        {
            HierarchicalTaxon taxon = SFTaxonomyManager.CreateTaxon <HierarchicalTaxon>();

            taxon.Name    = categoryName;
            taxon.Title   = categoryName;
            taxon.UrlName = Regex.Replace(categoryName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            _categories.Taxa.Add(taxon);
            SFTaxonomyManager.SaveChanges();

            return(taxon);
        }
Ejemplo n.º 4
0
        public static IEnumerable <HierarchicalTaxon> FlattenHierarchy(this HierarchicalTaxon parent)
        {
            yield return(parent);

            foreach (var control in parent.Subtaxa)
            {
                yield return(control);

                foreach (var descendant in control.FlattenHierarchy())
                {
                    yield return(descendant);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds the taxonomies to news.
        /// </summary>
        /// <param name="newsItemId">The news item id.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="tags">The tags.</param>
        public void AddTaxonomiesToNews(Guid newsItemId, IEnumerable <string> categories, IEnumerable <string> tags, string providerName)
        {
            NewsManager newsManager = null;

            if (providerName.IsNullOrEmpty())
            {
                newsManager = NewsManager.GetManager();
            }
            else
            {
                newsManager = NewsManager.GetManager(providerName);
            }

            NewsItem newsItem = newsManager.GetNewsItem(newsItemId);

            if (newsItem == null)
            {
                throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "News item with id {0} was not found.", newsItemId));
            }

            var taxonomyManager = TaxonomyManager.GetManager();

            if (categories != null)
            {
                if (categories.Count() > 0)
                {
                    HierarchicalTaxon category = null;
                    foreach (var c in categories)
                    {
                        category = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == c);
                        newsItem.Organizer.AddTaxa("Category", category.Id);
                    }
                }
            }

            if (tags != null)
            {
                if (tags.Count() > 0)
                {
                    FlatTaxon tag = null;
                    foreach (var tg in tags)
                    {
                        tag = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == tg);
                        newsItem.Organizer.AddTaxa("Tags", tag.Id);
                    }
                }
            }

            newsManager.SaveChanges();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the Root of a HierarchicalTaxon
        /// ** Sitefinitysteve.com Extension **.
        /// </summary>
        /// <param name="currentTaxon">This Taxon.</param>
        /// <returns>
        /// Root Taxon.
        /// </returns>
        public static HierarchicalTaxon GetRootTaxon(this HierarchicalTaxon currentTaxon)
        {
            if (currentTaxon.Parent == null)
            {
                return(currentTaxon);
            }

            HierarchicalTaxon parent = currentTaxon.Parent;

            while (parent.HasParent())
            {
                parent = parent.Parent;
            }
            return(parent);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Searches from Parent to parent to match the taxon name you need, returns the first match
        /// ** Sitefinitysteve.com Extension **.
        /// </summary>
        /// <param name="currentTaxon">Current Node.</param>
        /// <param name="textToFind">Text to locate.</param>
        /// <param name="type">Compare type.</param>
        /// <param name="isCaseSensitive">Case Sensitive check, doesn't apply to Contains.</param>
        /// <returns>
        /// Null if nothing found.
        /// </returns>
        public static HierarchicalTaxon GetFirstParentTaxon(this HierarchicalTaxon currentTaxon, string textToFind, HierarchicalTaxonCompareType type, bool isCaseSensitive)
        {
            StringComparison compareType = (isCaseSensitive) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;

            while (currentTaxon != null)
            {
                if (TextInTaxonTitle(currentTaxon.Title, textToFind, type, compareType))
                {
                    return(currentTaxon);
                }
                currentTaxon = currentTaxon.Parent;
            }

            return(null);
        }
Ejemplo n.º 8
0
        public void Return_True_With_Valid_HierarchicalTaxon_With_Deep_Hierarchy()
        {
            ITaxon taxon;
            int    pageIndex;

            string requestedUrl = "-in-category/category/cat1/cat11/cat22/cat33/cat44";

            var urlParams = requestedUrl.Split('/');

            var tagTaxon = new HierarchicalTaxon();

            var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url.Contains(requestedUrl) ? tagTaxon : null));

            bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex);

            Assert.IsTrue(hasMatch);
        }
Ejemplo n.º 9
0
        public void AddTaxonomiesToListItem(Guid listItemId, IEnumerable <string> categories, IEnumerable <string> tags)
        {
            string       transactionName = "AddTaxonomiesToListItem";
            ListsManager listManager     = ListsManager.GetManager(string.Empty, transactionName);

            ListItem listItemMaster = listManager.GetListItems().Where(i => i.Id == listItemId).FirstOrDefault();

            if (listItemMaster == null)
            {
                throw new ItemNotFoundException(string.Format(CultureInfo.CurrentCulture, "List item with id {0} was not found.", listItemId));
            }

            ListItem listItemTemp = listManager.Lifecycle.CheckOut(listItemMaster) as ListItem;

            var taxonomyManager = TaxonomyManager.GetManager();

            if (categories != null)
            {
                if (categories.Count() > 0)
                {
                    HierarchicalTaxon category = null;
                    foreach (var c in categories)
                    {
                        category = taxonomyManager.GetTaxa <HierarchicalTaxon>().Single(t => t.Title == c);
                        listItemTemp.Organizer.AddTaxa("Category", category.Id);
                    }
                }
            }

            if (tags != null)
            {
                if (tags.Count() > 0)
                {
                    FlatTaxon tag = null;
                    foreach (var tg in tags)
                    {
                        tag = taxonomyManager.GetTaxa <FlatTaxon>().Single(t => t.Title == tg);
                        listItemTemp.Organizer.AddTaxa("Tags", tag.Id);
                    }
                }
            }

            listItemMaster = listManager.Lifecycle.CheckIn(listItemTemp) as ListItem;
            listManager.Lifecycle.Publish(listItemMaster);
            TransactionManager.CommitTransaction(transactionName);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a list of the parent Taxon items
        /// ** Sitefinitysteve.com Extension **.
        /// </summary>
        /// <param name="currentTaxon">Current Taxon.</param>
        /// <returns>
        /// List of HierarchicalTaxons linked to this item.  0 index is the closest parent.
        /// </returns>
        public static List <HierarchicalTaxon> GetParentTaxa(this HierarchicalTaxon currentTaxon)
        {
            var taxa = new List <HierarchicalTaxon>();

            if (currentTaxon.Parent != null)
            {
                var parent = currentTaxon.Parent;
                taxa.Add(parent);

                while (parent.HasParent())
                {
                    parent = parent.Parent;
                    taxa.Add(parent);
                }
            }

            return(taxa);
        }
Ejemplo n.º 11
0
        public void Return_False_With_Valid_HierarchicalTaxon_With_Deep_Hierarchy_PageIndex()
        {
            ITaxon taxon;
            int pageIndex;

            string validTaxonUrl = "-in-category/category/cat1/cat11/cat22/cat33/cat44";

            string requestedUrl = "-in-category/category/cat1/cat11/cat22/cat33/cat44/2";

            var urlParams = requestedUrl.Split('/');

            var tagTaxon = new HierarchicalTaxon();

            var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url == validTaxonUrl ? tagTaxon : null));

            bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex);

            Assert.IsFalse(hasMatch);
        }
Ejemplo n.º 12
0
 public static void ProcessCategories(HierarchicalTaxon category, JobFilter jobFilter)
 {
     if (category != null && jobFilter != null)
     {
         jobFilter.ID    = category.Id.ToString().ToUpper();
         jobFilter.Label = category.Title;
         if (category.Subtaxa != null && category.Subtaxa.Count > 0)
         {
             foreach (var subTaxon in category.Subtaxa)
             {
                 var subFilter = new JobFilter()
                 {
                     Filters = new List <JobFilter>()
                 };
                 ProcessCategories(subTaxon, subFilter);
                 jobFilter.Filters.Add(subFilter);
             }
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sfContent">The sf content.</param>
        public DepartmentModel(HierarchicalTaxon sfContent)
        {
            var manager = TaxonomyManager.GetManager();

            Id               = sfContent.Id;
            Title            = sfContent.Title;
            Description      = sfContent.Description;
            FullUrl          = sfContent.FullUrl;
            Ordinal          = sfContent.Ordinal;
            RenderAsLink     = sfContent.RenderAsLink;
            ShowInNavigation = sfContent.ShowInNavigation;
            TaxonName        = sfContent.Taxonomy.TaxonName;
            Slug             = sfContent.UrlName;
            LastModified     = sfContent.LastModified;

            //STORE PARENT DETAILS IF APPLICABLE
            if (sfContent.Parent != null)
            {
                Parent = new ParentModel
                {
                    Id          = sfContent.Parent.Id,
                    Title       = sfContent.Parent.Title,
                    Description = sfContent.Parent.Description,
                    Ordinal     = sfContent.Parent.Ordinal,
                    Slug        = sfContent.Parent.UrlName
                };
            }

            //BUILD CHILDREN CATEGORIES
            Subtaxa = new List <DepartmentModel>();
            sfContent.Subtaxa.ToList().ForEach(c =>
                                               Subtaxa.Add(new DepartmentModel(c)));

            //GET NUMBER OF ITEMS IN CATEGORY
            Count = (int)manager.GetTaxonItemsCount(sfContent.Id, ContentLifecycleStatus.Live);

            // Store original content
            OriginalContent = sfContent;
        }
Ejemplo n.º 14
0
        private void VerifyCorrectItemsOnPageWithCategoryFilterAndPaging(HierarchicalTaxon category0, HierarchicalTaxon category1, DynamicContentController dynamicController, string[] itemsTitles)
        {
            var modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 1);
            var dynamicItems = modelItems.Items.ToList();
            int itemsCount   = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(3), "Number of items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[3 - i], StringComparison.CurrentCulture), "The items with this title was found!");
            }

            modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 2);
            dynamicItems = modelItems.Items.ToList();
            itemsCount   = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
            Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[0], StringComparison.CurrentCulture), "The items with this title was found!");

            modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 1);
            dynamicItems = modelItems.Items.ToList();
            itemsCount   = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(3), "Number of items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[4 - i], StringComparison.CurrentCulture), "The items with this title was found!");
            }

            modelItems   = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 2);
            dynamicItems = modelItems.Items.ToList();
            itemsCount   = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
            Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[1], StringComparison.CurrentCulture), "The items with this title was found!");
        }
 /// <summary>
 /// Lets us know if a Hierarchical taxon object has a parent object
 /// ** Sitefinitysteve.com Extension **
 /// </summary>
 /// <param name="currentTaxon"></param>
 /// <returns></returns>
 private static bool HasParent(this HierarchicalTaxon currentTaxon)
 {
     return((currentTaxon.Parent == null) ? false : true);
 }
        /// <summary>
        /// Searches from Parent to parent to match the taxon name you need, returns the first match
        /// ** Sitefinitysteve.com Extension **
        /// </summary>
        /// <param name="currentTaxon">Current Node</param>
        /// <param name="textToFind">Text to locate</param>
        /// <param name="type">Compare type</param>
        /// <param name="isCaseSensitive">Case Sensitive check, doesn't apply to Contains</param>
        /// <returns>Null if nothing found</returns>
        public static HierarchicalTaxon GetFirstParentTaxon(this HierarchicalTaxon currentTaxon, string textToFind, HierarchicalTaxonCompareType type, bool isCaseSensitive)
        {
            bool found = false;
            HierarchicalTaxon foundTaxon = null;
            var compareType = (isCaseSensitive) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;

            //Check this one, TODO: consolidate this and the one below
            if (type == HierarchicalTaxonCompareType.StartsWith)
            {
                found = currentTaxon.Title.StartsWith(textToFind, compareType);
            }
            else if (type == HierarchicalTaxonCompareType.EndsWith)
            {
                found = currentTaxon.Title.EndsWith(textToFind, compareType);
            }
            else if (type == HierarchicalTaxonCompareType.Equals)
            {
                found = currentTaxon.Title.Equals(textToFind, compareType);
            }
            else if (type == HierarchicalTaxonCompareType.Contains)
            {
                found = currentTaxon.Title.Contains(textToFind);
            }

            if (found)
            {
                return(currentTaxon);
            }


            if (currentTaxon.Parent != null)
            {
                while (currentTaxon != null)
                {
                    switch (type)
                    {
                    case HierarchicalTaxonCompareType.StartsWith:
                        found = currentTaxon.Title.StartsWith(textToFind, compareType);
                        break;

                    case HierarchicalTaxonCompareType.EndsWith:
                        found = currentTaxon.Title.EndsWith(textToFind, compareType);
                        break;

                    case HierarchicalTaxonCompareType.Contains:
                        found = currentTaxon.Title.Contains(textToFind);
                        break;

                    case HierarchicalTaxonCompareType.Equals:
                        found = currentTaxon.Title.Equals(textToFind, compareType);
                        break;
                    }

                    if (found)
                    {
                        foundTaxon = currentTaxon;
                        break;
                    }
                    else
                    {
                        currentTaxon = currentTaxon.Parent;
                    }
                }
            }

            return(foundTaxon);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Lets us know if a Hierarchical taxon object has a parent object
 /// ** Sitefinitysteve.com Extension **.
 /// </summary>
 /// <param name="currentTaxon">The taxon to check.</param>
 /// <returns>
 /// true if parent exists, false if not.
 /// </returns>
 private static bool HasParent(this HierarchicalTaxon currentTaxon)
 {
     return(currentTaxon.Parent != null);
 }
Ejemplo n.º 18
0
        private void CreateHierarchicalSubTaxonIfDoesntExist(SiteInitializer initializer, Guid taxonId, string taxonName,
                                                             string taxonTitle, string taxonDescription, HierarchicalTaxon parent)
        {
            var taxon = initializer.TaxonomyManager.GetTaxa <HierarchicalTaxon>().Where(t => t.Id == taxonId).SingleOrDefault();

            if (taxon == null)
            {
                taxon             = initializer.TaxonomyManager.CreateTaxon <HierarchicalTaxon>(taxonId);
                taxon.Title       = taxonTitle;
                taxon.Name        = taxonName;
                taxon.Description = taxonDescription;
                taxon.Parent      = parent;
                parent.Subtaxa.Add(taxon);
            }
        }
        private void VerifyCorrectItemsOnPageWithCategoryFilterAndPaging(HierarchicalTaxon category0, HierarchicalTaxon category1, DynamicContentController dynamicController, string[] itemsTitles)
        {
            var modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 1);
            var dynamicItems = modelItems.Items.ToList();
            int itemsCount = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(3), "Number of items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[3 - i], StringComparison.CurrentCulture), "The items with this title was found!");
            }

            modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: category0, page: 2);
            dynamicItems = modelItems.Items.ToList();
            itemsCount = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
            Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[0], StringComparison.CurrentCulture), "The items with this title was found!");

            modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 1);
            dynamicItems = modelItems.Items.ToList();
            itemsCount = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(3), "Number of items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(itemsTitles[4 - i], StringComparison.CurrentCulture), "The items with this title was found!");
            }

            modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: category1, page: 2);
            dynamicItems = modelItems.Items.ToList();
            itemsCount = dynamicItems.Count;

            Assert.IsTrue(itemsCount.Equals(1), "Number of items is not correct");
            Assert.IsTrue(dynamicItems[0].Fields.Title.Equals(itemsTitles[1], StringComparison.CurrentCulture), "The items with this title was found!");
        }
        private void VerifyCorrectNewsOnPageWithCategoryFilterAndPaging(HierarchicalTaxon category0, HierarchicalTaxon category1, NewsController newsController, string[] newsTitles)
        {
            ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(category0.Id);
            var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[3 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[0], StringComparison.CurrentCulture), "The news with this title was found!");

            taxonomy = TaxonomyManager.GetManager().GetTaxon(category1.Id);
            items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[4 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[1], StringComparison.CurrentCulture), "The news with this title was found!");
        }