예제 #1
0
        public void When()
        {
            var sb              = new StringBuilder();
            var responseWriter  = new StringWriter(sb);
            var contentProvider = new Mock <ISitemapContentProvider>();

            contentProvider.Setup(s => s.GetSitemapUrls(It.IsAny <Uri>()))
            .Returns(() => new List <SitemapUrl>
            {
                SitemapUrl.Create("http://localtest.me/index.html", DateTimeOffset.UtcNow),
                SitemapUrl.Create("http://localtest.me/search.html", DateTime.Now.AddMinutes(-5)),
                SitemapUrl.Create("http://localtest.me/date.html", DateTime.UtcNow.Date)
            });

            Configure.With(c => c.UsingContentProvider(contentProvider.Object));

            var httpContext = new Mock <HttpContextBase>(MockBehavior.Loose);

            httpContext.Setup(s => s.Request).Returns(() =>
                                                      new HttpRequestWrapper(new HttpRequest("sitemap.xml", "http://localtest.me/sitemap.xml", "")));
            httpContext.Setup(s => s.Response).Returns(() => new HttpResponseWrapper(new HttpResponse(responseWriter)));

            var handler = new SitemapifyHttpHandler();

            handler.ProcessRequest(httpContext.Object);

            var document = XDocument.Parse(sb.ToString());

            (from urls in
             document.Descendants(XName.Get("urlset", SitemapUrl.SitemapNs))
             .Elements(XName.Get("url", SitemapUrl.SitemapNs))
             select urls).Count().Should().Be(3);
        }
예제 #2
0
        protected override SitemapUrl CreateSitemapUrl(object entry, Uri baseUri)
        {
            var ub = new UriBuilder(baseUri)
            {
                Path = "/"
            };

            return(SitemapUrl.Create(ub.Uri.ToString(), changeFreq: SitemapChangeFrequency.Never));
        }
        protected override SitemapUrl CreateSitemapUrl(IPublishedContent entry, Uri baseUri)
        {
            var uri = entry.UrlAbsolute();

            if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute))
            {
                uri = $"{baseUri}{entry.Url()}";
            }

            var absoluteUri = uri.TrimEnd("/");

            return(SitemapUrl.Create(absoluteUri, entry.UpdateDate));
        }
예제 #4
0
        public void SitemapUrlPriorityShouldBeInvariantCulture()
        {
            var sb              = new StringBuilder();
            var responseWriter  = new StringWriter(sb);
            var contentProvider = new Mock <ISitemapContentProvider>();

            contentProvider.Setup(s => s.GetSitemapUrls(It.IsAny <Uri>()))
            .Returns(() => new List <SitemapUrl>
            {
                SitemapUrl.Create("http://localtest.me/index.html", DateTimeOffset.UtcNow, priority: 1.1)
            });

            Configure.With(c => c.UsingContentProvider(contentProvider.Object));

            var httpContext = new Mock <HttpContextBase>(MockBehavior.Loose);

            httpContext.Setup(s => s.Request).Returns(() =>
                                                      new HttpRequestWrapper(new HttpRequest("sitemap.xml", "http://localtest.me/sitemap.xml", "")));
            httpContext.Setup(s => s.Response).Returns(() => new HttpResponseWrapper(new HttpResponse(responseWriter)));

            var handler = new SitemapifyHttpHandler();

            handler.ProcessRequest(httpContext.Object);

            var document = XDocument.Parse(sb.ToString());

            var sitemapUrlElement = (from urls in
                                     document.Descendants(XName.Get("urlset", SitemapUrl.SitemapNs))
                                     .Elements(XName.Get("url", SitemapUrl.SitemapNs))
                                     select urls).First();

            var priority = sitemapUrlElement.Element(XName.Get("priority", SitemapUrl.SitemapNs));

            priority.Should().NotBeNull();
            priority.Value.Should().Be("1.1");
        }