/// <summary> /// Gets the Navigation Model (Sitemap) for a given Localization. /// </summary> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Model (Sitemap root Item).</returns> public SitemapItem GetNavigationModel(Localization localization) { using (new Tracer(localization)) { var cachedNavModel = SiteConfiguration.CacheProvider.GetOrAdd( $"GetNavigationModel:{localization.Id}", CacheRegions.DynamicNavigation, () => { var navModel = SiteConfiguration.ModelServiceProvider.GetSitemapItem(localization) ?? FallbackNavigationProvider.GetNavigationModel(localization); RebuildParentRelationships(navModel.Items, navModel); return(navModel); } ); if (cachedNavModel != null && cachedNavModel.Items.Count > 0 && cachedNavModel.Items.First().Parent == null) { RebuildParentRelationships(cachedNavModel.Items, cachedNavModel); } return(cachedNavModel); } }
/// <summary> /// Gets the Navigation Model (Sitemap) for a given Localization. /// </summary> /// <param name="localization">The Localization.</param> /// <returns>The Navigation Model (Sitemap root Item).</returns> public SitemapItem GetNavigationModel(Localization localization) { using (new Tracer(localization)) { string navTaxonomyUri = GetNavigationTaxonomyUri(localization); if (string.IsNullOrEmpty(navTaxonomyUri)) { // No Navigation Taxonomy found in this Localization; fallback to the StaticNavigationProvider. return(_fallbackNavigationProvider.GetNavigationModel(localization)); } return(SiteConfiguration.CacheProvider.GetOrAdd( localization.Id, // key CacheRegions.DynamicNavigation, () => BuildNavigationModel(navTaxonomyUri, localization), new [] { navTaxonomyUri } // dependency on Taxonomy )); } }
public void GetNavigationModel_Success() { ILocalization testLocalization = TestFixture.ParentLocalization; SitemapItem rootSitemapItem = _testNavigationProvider.GetNavigationModel(testLocalization); Assert.IsNotNull(rootSitemapItem, "Root SitemapItem"); Assert.AreEqual("Home", rootSitemapItem.Title, "Root SitemapItem.Title"); Assert.AreEqual("StructureGroup", rootSitemapItem.Type, "Root SitemapItem.Type"); Assert.AreEqual(testLocalization.Path + "/", rootSitemapItem.Url, "Root SitemapItem.Url"); Assert.IsFalse(rootSitemapItem.Visible, "Root SitemapItem.Visible"); Assert.IsNull(rootSitemapItem.PublishedDate, "Root SitemapItem.PublishedDate"); Assert.IsTrue(rootSitemapItem.Items.Count > 0, "Root SitemapItem.Items (count)"); SitemapItem homePageSitemapItem = rootSitemapItem.Items.FirstOrDefault(si => si.Type == "Page" && si.Title == "Home"); Assert.IsNotNull(homePageSitemapItem, "Home Page SitemapItem"); Assert.AreEqual(rootSitemapItem.Url + "index", homePageSitemapItem.Url, "Home Page SitemapItem.Url"); Assert.IsTrue(homePageSitemapItem.Visible, "Root SitemapItem.Visible"); Assert.IsNotNull(homePageSitemapItem.PublishedDate, "Home Page SitemapItem.PublishedDate"); }
public void GetNavigationModel_Success() { Localization testLocalization = TestFixture.ParentLocalization; SitemapItem rootSitemapItem = _testNavigationProvider.GetNavigationModel(testLocalization); Assert.IsNotNull(rootSitemapItem, "Root SitemapItem"); OutputJson(rootSitemapItem); TaxonomyNode rootNode = rootSitemapItem as TaxonomyNode; Assert.IsNotNull(rootNode, "rootSitemapItem is not of type TaxonomyNode"); StringAssert.Matches(rootNode.Id, new Regex(@"t\d+"), "rootNode.Id"); Assert.AreEqual(SitemapItem.Types.TaxonomyNode, rootNode.Type, "rootNode.Type"); Assert.AreEqual("Test Taxonomy [Navigation]", rootNode.Title, "rootNode.Title"); Assert.AreEqual("Test Taxonomy to be used for Navigation purposes", rootNode.Description, "rootNode.Description"); Assert.IsNull(rootNode.Url, "rootNode.Url"); Assert.IsFalse(rootNode.Visible, "rootNode.Visible"); Assert.IsTrue(rootNode.IsAbstract, "rootNode.IsAbstract"); Assert.IsTrue(rootNode.HasChildNodes, "rootNode.HasChildNodes"); Assert.AreEqual(4, rootNode.ClassifiedItemsCount, "rootNode.ClassifiedItemsCount"); Assert.IsNotNull(rootNode.Items, "rootNode.Items"); Assert.AreEqual(2, rootNode.Items.OfType <TaxonomyNode>().Count(), "rootNode.Items.OfType<TaxonomyNode>().Count()"); TaxonomyNode topLevelKeyword1 = rootNode.Items.OfType <TaxonomyNode>().FirstOrDefault(i => i.Title == TestFixture.TopLevelKeyword1Title); Assert.IsNotNull(topLevelKeyword1, "topLevelKeyword1"); Assert.IsNotNull(topLevelKeyword1.Items, "topLevelKeyword1.Items"); Assert.IsNull(topLevelKeyword1.Url, "topLevelKeyword1.Url"); Assert.IsFalse(topLevelKeyword1.Visible, "topLevelKeyword1.Visible"); TaxonomyNode keyword12 = topLevelKeyword1.Items.OfType <TaxonomyNode>().FirstOrDefault(i => i.Title == "Keyword 1.2"); Assert.IsNotNull(keyword12, "keyword12"); Assert.IsNotNull(keyword12.Items, "keyword12.Items"); Assert.AreEqual(3, keyword12.ClassifiedItemsCount, "keyword12.ClassifiedItemsCount"); Assert.AreEqual(3, keyword12.Items.Count, "keyword12.Items.Count"); for (int i = 0; i < keyword12.Items.Count; i++) { AssertProperSitemapItemForPage(keyword12.Items[i], string.Format("keyword12.Items[{0}]", i)); } // The Pages should be sorted by CM Page title (incl. sequence prefix), but not have the sequence prefix. Assert.AreEqual("Navigation Taxonomy Index Page", keyword12.Items[0].Title, "keyword12.Items[0].Title"); Assert.AreEqual("Navigation Taxonomy Test Page 2", keyword12.Items[1].Title, "keyword12.Items[1].Title"); Assert.AreEqual("Navigation Taxonomy Test Page 1", keyword12.Items[2].Title, "keyword12.Items[2].Title"); TaxonomyNode topLevelKeyword2 = rootNode.Items.OfType <TaxonomyNode>().FirstOrDefault(i => i.Title == TestFixture.TopLevelKeyword2Title); Assert.IsNotNull(topLevelKeyword2, "topLevelKeyword2"); Assert.IsNotNull(topLevelKeyword2.Items, "topLevelKeyword2.Items"); Assert.AreEqual(3, topLevelKeyword2.Items.Count, "topLevelKeyword2.Items.Count"); SitemapItem navTestPage3 = topLevelKeyword2.Items[2]; Assert.AreEqual("Navigation Taxonomy Test Page 3", navTestPage3.Title, "navTestPage3.Title"); Assert.IsFalse(navTestPage3.Visible, "navTestPage3.Visible"); // It does not have a sequence prefix // TaxonomyNode should get the URL from its Index Page: string indexPageUrl = keyword12.Items[0].Url; Assert.AreEqual(indexPageUrl.Substring(0, indexPageUrl.Length - "/index".Length), keyword12.Url, "keyword12.Url"); Assert.IsFalse(keyword12.Visible, "keyword12.Visible"); // It has a URL, but no sequence prefix in CM. Assert.AreEqual(indexPageUrl.Substring(0, indexPageUrl.Length - "/index".Length), topLevelKeyword2.Url, "topLevelKeyword2.Url"); Assert.IsTrue(topLevelKeyword2.Visible, "topLevelKeyword2.Visible"); // It has a URL and a sequence prefix in CM }