Skip to content

Commit 28fb2ef

Browse files
committed
fix: Don't apply title multiple times (Fixes #385)
1 parent 36f683b commit 28fb2ef

28 files changed

+64
-57
lines changed

src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
2-
31
namespace LinkDotNet.Blog.Web;
42

53
public sealed record ApplicationConfiguration

src/LinkDotNet.Blog.Web/ConfigurationExtension.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
9-
using Microsoft.Extensions.Options;
109

1110
namespace LinkDotNet.Blog.Web;
1211

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPost.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@using LinkDotNet.Blog.Infrastructure
33
@using LinkDotNet.Blog.Infrastructure.Persistence
44
@using LinkDotNet.Blog.Web.Features.Services
5-
@using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components
65
@using NCronJob
76
@inject IJSRuntime JSRuntime
87
@inject ICacheInvalidator CacheInvalidator
@@ -136,7 +135,7 @@
136135

137136
private string? originalContent = null;
138137
private bool IsContentConverted => !string.IsNullOrWhiteSpace(originalContent);
139-
private string ConvertLabel => !IsContentConverted ? "Convert to markdown" : "Restore";
138+
private string ConvertLabel => !IsContentConverted ? "Convert to markdown" : "Restore";
140139

141140
private bool canSubmit = true;
142141
private IPagedList<ShortCode> shortCodes = PagedList<ShortCode>.Empty;

src/LinkDotNet.Blog.Web/Features/Home/Index.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
@inject IOptions<ApplicationConfiguration> AppConfiguration
1616
@inject NavigationManager NavigationManager
1717

18+
<PageTitle>@AppConfiguration.Value.BlogName</PageTitle>
19+
1820
<OgData Title="@(Markdown.ToPlainText(AppConfiguration.Value.BlogName))"
1921
AbsolutePreviewImageUrl="@ImageUrl"
2022
Description="@(Markdown.ToPlainText(Introduction.Value.Description))"></OgData>

src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Markdig.Syntax;
88
using Markdig.Syntax.Inlines;
99
using Microsoft.AspNetCore.Components;
10-
using MongoDB.Driver.Linq;
1110

1211
namespace LinkDotNet.Blog.Web.Features;
1312

src/LinkDotNet.Blog.Web/Pages/_Layout.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<head>
1010
<meta charset="utf-8"/>
1111
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
12-
<title>@AppConfiguration.Value.BlogName</title>
1312
<base href="~/"/>
1413
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
1514
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
using System;
2+
using System.Linq;
3+
using System.Net.Http;
24
using System.Threading.Tasks;
5+
using AngleSharp.Html.Dom;
6+
using AngleSharp.Html.Parser;
37
using LinkDotNet.Blog.Infrastructure.Persistence;
8+
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
9+
using LinkDotNet.Blog.TestUtilities;
410
using LinkDotNet.Blog.Web;
511
using Microsoft.AspNetCore.Mvc.Testing;
12+
using Microsoft.EntityFrameworkCore;
13+
using Microsoft.Extensions.DependencyInjection;
614
using TestContext = Xunit.TestContext;
715

816
namespace LinkDotNet.Blog.IntegrationTests;
917

1018
public sealed class SmokeTests : IClassFixture<WebApplicationFactory<Program>>, IDisposable, IAsyncDisposable
1119
{
1220
private readonly WebApplicationFactory<Program> factory;
21+
private readonly IServiceScope scope;
22+
private readonly HttpClient client;
1323

1424
public SmokeTests(WebApplicationFactory<Program> factory)
1525
{
1626
this.factory = factory.WithWebHostBuilder(builder =>
1727
{
28+
builder.UseSetting("BlogName", "Tests Title");
1829
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
1930
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
2031
});
32+
33+
scope = this.factory.Services.CreateScope();
34+
client = this.factory.CreateClient();
2135
}
2236

2337
[Fact]
2438
public async Task ShouldBootUpApplication()
2539
{
26-
using var client = factory.CreateClient();
27-
28-
var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);
29-
30-
result.IsSuccessStatusCode.ShouldBeTrue();
31-
}
32-
33-
[Fact]
34-
public async Task ShouldBootUpWithSqlDatabase()
35-
{
36-
await using var sqlFactory = factory.WithWebHostBuilder(builder =>
37-
{
38-
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
39-
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
40-
});
41-
using var client = sqlFactory.CreateClient();
42-
4340
var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);
4441

4542
result.IsSuccessStatusCode.ShouldBeTrue();
@@ -48,8 +45,6 @@ public async Task ShouldBootUpWithSqlDatabase()
4845
[Fact]
4946
public async Task ShouldAllowDotsForTagSearch()
5047
{
51-
using var client = factory.CreateClient();
52-
5348
var result = await client.GetAsync("/searchByTag/.NET5", cancellationToken: TestContext.Current.CancellationToken);
5449

5550
result.IsSuccessStatusCode.ShouldBeTrue();
@@ -58,8 +53,6 @@ public async Task ShouldAllowDotsForTagSearch()
5853
[Fact]
5954
public async Task ShouldAllowDotsForFreeTextSearch()
6055
{
61-
using var client = factory.CreateClient();
62-
6356
var result = await client.GetAsync("/search/.NET5", cancellationToken: TestContext.Current.CancellationToken);
6457

6558
result.IsSuccessStatusCode.ShouldBeTrue();
@@ -69,7 +62,6 @@ public async Task ShouldAllowDotsForFreeTextSearch()
6962
public async Task RssFeedShouldBeRateLimited()
7063
{
7164
const int numberOfRequests = 16;
72-
using var client = factory.CreateClient();
7365

7466
for (var i = 0; i < numberOfRequests - 1; i++)
7567
{
@@ -81,10 +73,55 @@ public async Task RssFeedShouldBeRateLimited()
8173
lastResult.IsSuccessStatusCode.ShouldBeFalse();
8274
}
8375

84-
public void Dispose() => factory?.Dispose();
76+
[Fact]
77+
public async Task ShowingBlogPost_ShouldOnlyHaveOneTitle()
78+
{
79+
var blogPost = new BlogPostBuilder().WithTitle("My Blog Post").Build();
80+
var contextProvider = scope.ServiceProvider.GetRequiredService<IDbContextFactory<BlogDbContext>>();
81+
await using var context = await contextProvider.CreateDbContextAsync(TestContext.Current.CancellationToken);
82+
await context.BlogPosts.AddAsync(blogPost, TestContext.Current.CancellationToken);
83+
await context.SaveChangesAsync(TestContext.Current.CancellationToken);
84+
85+
var result = await client.GetAsync($"/blogPost/{blogPost.Id}", cancellationToken: TestContext.Current.CancellationToken);
86+
87+
result.IsSuccessStatusCode.ShouldBeTrue();
88+
var content = await result.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
89+
var document = GetHtmlDocument(content);
90+
var titleTags = document.QuerySelectorAll("title");
91+
titleTags.Length.ShouldBe(1);
92+
titleTags.Single().TextContent.ShouldBe("My Blog Post");
93+
}
94+
95+
[Fact]
96+
public async Task IndexPage_HasTitleFromConfiguration()
97+
{
98+
var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);
99+
100+
result.IsSuccessStatusCode.ShouldBeTrue();
101+
var content = await result.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
102+
var document = GetHtmlDocument(content);
103+
var titleTags = document.QuerySelectorAll("title");
104+
titleTags.Length.ShouldBe(1);
105+
titleTags.Single().TextContent.ShouldBe("Tests Title");
106+
}
107+
108+
public void Dispose()
109+
{
110+
scope.Dispose();
111+
client.Dispose();
112+
factory?.Dispose();
113+
}
85114

86115
public async ValueTask DisposeAsync()
87116
{
117+
scope.Dispose();
118+
client.Dispose();
88119
await factory.DisposeAsync();
89120
}
121+
122+
private static IHtmlDocument GetHtmlDocument(string html)
123+
{
124+
var parser = new HtmlParser();
125+
return parser.ParseDocument(html);
126+
}
90127
}

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/ShortCodes/ShortCodesPageTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using System.Threading.Tasks;
3-
using AngleSharp.Html.Dom;
43
using Blazored.Toast.Services;
54
using LinkDotNet.Blog.Domain;
65
using LinkDotNet.Blog.TestUtilities.Fakes;

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/Components/SimilarBlogPostSectionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Generic;
21
using System.Threading.Tasks;
32
using LinkDotNet.Blog.Domain;
43
using LinkDotNet.Blog.Infrastructure.Persistence;

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using Blazored.Toast.Services;
43
using LinkDotNet.Blog.Domain;
54
using LinkDotNet.Blog.Infrastructure;
65
using LinkDotNet.Blog.Infrastructure.Persistence;
76
using LinkDotNet.Blog.TestUtilities;
8-
using LinkDotNet.Blog.Web;
97
using LinkDotNet.Blog.Web.Features.Components;
108
using LinkDotNet.Blog.Web.Features.Services;
119
using LinkDotNet.Blog.Web.Features.ShowBlogPost;

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SimilarBlogPostJobTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using LinkDotNet.Blog.Domain;
44
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
55
using LinkDotNet.Blog.TestUtilities;
6-
using LinkDotNet.Blog.Web;
76
using LinkDotNet.Blog.Web.Features;
87
using Microsoft.Extensions.Logging;
98
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.IntegrationTests/Web/RegistrationExtensions/RavenDbRegistrationExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using LinkDotNet.Blog.Domain;
22
using LinkDotNet.Blog.Infrastructure.Persistence;
33
using LinkDotNet.Blog.TestUtilities;
4-
using LinkDotNet.Blog.Web;
54
using LinkDotNet.Blog.Web.RegistrationExtensions;
65
using Microsoft.Extensions.DependencyInjection;
76
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.IntegrationTests/Web/RegistrationExtensions/SqliteRegistrationExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using LinkDotNet.Blog.Domain;
22
using LinkDotNet.Blog.Infrastructure.Persistence;
33
using LinkDotNet.Blog.TestUtilities;
4-
using LinkDotNet.Blog.Web;
54
using LinkDotNet.Blog.Web.RegistrationExtensions;
65
using Microsoft.Extensions.Options;
76
using Microsoft.Extensions.DependencyInjection;

tests/LinkDotNet.Blog.IntegrationTests/Web/RegistrationExtensions/StorageProviderExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using LinkDotNet.Blog.Domain;
44
using LinkDotNet.Blog.Infrastructure.Persistence;
55
using LinkDotNet.Blog.TestUtilities;
6-
using LinkDotNet.Blog.Web;
76
using LinkDotNet.Blog.Web.RegistrationExtensions;
87
using Microsoft.Extensions.Configuration;
98
using Microsoft.Extensions.DependencyInjection;

tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using LinkDotNet.Blog.Domain;
55
using LinkDotNet.Blog.Infrastructure.Persistence;
66
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
7-
using Microsoft.AspNetCore.Components;
87
using Microsoft.Extensions.DependencyInjection;
98
using NCronJob;
109

tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Linq;
22
using AngleSharp.Html.Dom;
3-
using LinkDotNet.Blog.Domain;
43
using LinkDotNet.Blog.TestUtilities;
5-
using LinkDotNet.Blog.Web;
64
using LinkDotNet.Blog.Web.Features.Home.Components;
75
using Microsoft.AspNetCore.Components;
86
using Microsoft.Extensions.DependencyInjection;

tests/LinkDotNet.Blog.TestUtilities/SupportMeConfigurationBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
21
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
32

43
namespace LinkDotNet.Blog.TestUtilities;

tests/LinkDotNet.Blog.UnitTests/Web/ApplicationConfigurationTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using LinkDotNet.Blog.Domain;
33
using LinkDotNet.Blog.TestUtilities;
4-
using LinkDotNet.Blog.Web;
54
using LinkDotNet.Blog.Web.Authentication.OpenIdConnect;
65
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
76
using Microsoft.Extensions.Configuration;

tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/FooterTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using LinkDotNet.Blog.Domain;
21
using LinkDotNet.Blog.TestUtilities;
3-
using LinkDotNet.Blog.Web;
42
using LinkDotNet.Blog.Web.Features.Home.Components;
53
using Microsoft.Extensions.DependencyInjection;
64
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/IntroductionCardTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using AngleSharp.Css.Dom;
3-
using LinkDotNet.Blog.Domain;
43
using LinkDotNet.Blog.TestUtilities;
54
using LinkDotNet.Blog.Web.Features.Home.Components;
65
using Microsoft.Extensions.DependencyInjection;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/CommentSectionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LinkDotNet.Blog.TestUtilities;
2-
using LinkDotNet.Blog.Web;
32
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
43
using Microsoft.Extensions.DependencyInjection;
54
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/DisqusTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using LinkDotNet.Blog.TestUtilities;
3-
using LinkDotNet.Blog.Web;
43
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/DonationSectionTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using LinkDotNet.Blog.TestUtilities;
2-
using LinkDotNet.Blog.Web;
3-
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
42
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
53
using Microsoft.Extensions.DependencyInjection;
64
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/GiscusTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using LinkDotNet.Blog.TestUtilities;
3-
using LinkDotNet.Blog.Web;
43
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.Options;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/GithubSponsorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using AngleSharp.Html.Dom;
2-
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
32
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
43

54
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/KofiTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using AngleSharp.Html.Dom;
2-
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
32
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
43

54
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/PatreonTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using AngleSharp.Html.Dom;
2-
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
32
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
43

54
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.Linq.Expressions;
31
using System.Threading.Tasks;
42
using AngleSharp.Html.Dom;
53
using Blazored.Toast.Services;

0 commit comments

Comments
 (0)