public async Task <ActionResult> SitemapIndex() { // Get projects int pageCount = await _projectService.GetSitemapPageCountAsync(); // Build sitemap index var sitemapIndex = new SitemapIndexModel(); for (int i = 0; i < pageCount; ++i) { sitemapIndex.Sitemaps.Add(new SitemapIndexItem { Location = Url.RouteUrl(RouteNames.Sitemap, new { page = i }, Request.Url != null ? Request.Url.Scheme : "http") }); } // Serialize var serializer = new XmlSerializer(typeof(SitemapIndexModel)); var xmlns = new XmlSerializerNamespaces(); xmlns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); var xmlStream = new MemoryStream(); serializer.Serialize(xmlStream, sitemapIndex, xmlns); xmlStream.Seek(0, SeekOrigin.Begin); return(File(xmlStream, "text/xml")); }
public void CreateSitemapIndex_CreatesSitemapIndexXmlResult() { List<SitemapIndexNode> indexNodes = new List<SitemapIndexNode> { new SitemapIndexNode("/relative") }; SitemapIndexModel sitemapIndexModel = new SitemapIndexModel(indexNodes); var result = sitemapProvider.CreateSitemapIndex(sitemapIndexModel); result.Should().BeOfType<XmlResult<SitemapIndexModel>>(); }
public void CreateSitemapIndex_CreatesSitemapIndexXmlResult() { List <SitemapIndexNode> indexNodes = new List <SitemapIndexNode> { new SitemapIndexNode("/relative") }; SitemapIndexModel sitemapIndexModel = new SitemapIndexModel(indexNodes); var result = sitemapProvider.CreateSitemapIndex(sitemapIndexModel); result.Should().BeOfType <XmlResult <SitemapIndexModel> >(); }
public void Serialize_SitemapIndexModel() { SitemapIndexModel sitemapIndex = new SitemapIndexModel(new List<SitemapIndexNode> { new SitemapIndexNode { Url = "abc" }, new SitemapIndexNode { Url = "def" } }); string result = _serializer.Serialize(sitemapIndex); result.Should().BeXmlEquivalent("Samples/sitemap-index.xml"); }
public void Serialize_SitemapIndexModel() { SitemapIndexModel sitemapIndex = new SitemapIndexModel(new List <SitemapIndexNode> { new SitemapIndexNode { Url = "abc" }, new SitemapIndexNode { Url = "def" } }); string result = serializer.Serialize(sitemapIndex); result.Should().BeXmlEquivalent("sitemap-index.xml"); }