-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathSitemapServiceTests.cs
41 lines (35 loc) · 1.49 KB
/
SitemapServiceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.IO;
using System.Threading.Tasks;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.Admin.Sitemap.Services;
using Microsoft.AspNetCore.Components;
using TestContext = Xunit.TestContext;
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared.Services;
public sealed class SitemapServiceTests : SqlDatabaseTestBase<BlogPost>
{
private readonly SitemapService sut;
public SitemapServiceTests()
=> sut = new SitemapService(Repository);
[Fact]
public async Task ShouldSaveSitemapUrlInCorrectFormat()
{
var publishedBlogPost = new BlogPostBuilder()
.WithTitle("Title 1")
.WithUpdatedDate(new DateTime(2024, 12, 24))
.IsPublished()
.Build();
var unpublishedBlogPost = new BlogPostBuilder()
.IsPublished(false)
.Build();
await Repository.StoreAsync(publishedBlogPost);
await Repository.StoreAsync(unpublishedBlogPost);
var sitemap = await sut.CreateSitemapAsync("https://www.linkdotnet.blog");
sitemap.Urls.Count.ShouldBe(3);
sitemap.Urls.ShouldContain(u => u.Location == "https://www.linkdotnet.blog/");
sitemap.Urls.ShouldContain(u => u.Location == "https://www.linkdotnet.blog/archive");
sitemap.Urls.ShouldContain(u => u.Location == "https://www.linkdotnet.blog/blogPost/" + publishedBlogPost.Id);
}
}