private void process(Item itm, UrlSet urlSet, FileDefinition definition) { if (definition.TemplatesToInclude.Count == 0 || definition.TemplatesToInclude.Contains(itm.TemplateID.ToGuid())) { if (definition.LanguageCodesToInclude.Count == 0 || hasAValidLanguage(itm, definition.LanguageCodesToInclude)) { var url = makeUrl(itm, definition); urlSet.Add(url); } } foreach (Item child in itm.Children) { process(child, urlSet, definition); } }
public void UrlSetSerialiser_Serialise_MultipleUrlsGivesCorrectDocument() { var urlSet = new UrlSet(); for (int i = 0; i < 10; i++) { urlSet.Add(new Url(i.ToString())); } var serialiser = new UrlSetSerialiser(); XDocument result = serialiser.Serialise(urlSet); Assert.IsNotNull(result, "Serialise() should always return a valid XML document"); var set = result.Document.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlSetElementName); var urls = set.Elements(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlElementName); Assert.AreEqual(10, urls.Count()); }
public void UrlSetSerialiser_Serialise_SingleUrlGivesValidDocument() { var urlSet = new UrlSet(); urlSet.Add(new Url("123")); var serialiser = new UrlSetSerialiser(); XDocument result = serialiser.Serialise(urlSet); Assert.IsNotNull(result, "Serialise() should always return a valid XML document"); var set = result.Document.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlSetElementName); var urls = set.Elements(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlElementName); Assert.AreEqual(1, urls.Count()); var loc = urls.First().Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlLocationElemenName); Assert.AreEqual("123", loc.Value); }
public void UrlSetSerialiser_Serialise_OverallDocumentHasCorrectFormat() { var urlSet = new UrlSet(); var url = new Url("http://www.com/") { ChangeFrequency = ChangeFrequency.Daily }; url.AlternateUrls.Add(new AlternateUrl() { Url = "http://www.com/en/", Language = "EN-GB" }); urlSet.Add(url); var serialiser = new UrlSetSerialiser(); var xDoc = serialiser.Serialise(urlSet); string s = xDoc.ToString(SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting); Assert.AreEqual("<urlset xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"><url><loc>http://www.com/</loc><changefreq>daily</changefreq><xhtml:link rel=\"alternate\" hreflang=\"EN-GB\" href=\"http://www.com/en/\" /></url></urlset>", s); }