Skip to content

Commit

Permalink
fix: Don't apply title multiple times (Fixes #385)
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Nov 30, 2024
1 parent 36f683b commit 28fb2ef
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 57 deletions.
2 changes: 0 additions & 2 deletions src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.ComponentModel.DataAnnotations;

namespace LinkDotNet.Blog.Web;

public sealed record ApplicationConfiguration
Expand Down
1 change: 0 additions & 1 deletion src/LinkDotNet.Blog.Web/ConfigurationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace LinkDotNet.Blog.Web;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@using LinkDotNet.Blog.Infrastructure
@using LinkDotNet.Blog.Infrastructure.Persistence
@using LinkDotNet.Blog.Web.Features.Services
@using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components
@using NCronJob
@inject IJSRuntime JSRuntime
@inject ICacheInvalidator CacheInvalidator
Expand Down Expand Up @@ -136,7 +135,7 @@

private string? originalContent = null;
private bool IsContentConverted => !string.IsNullOrWhiteSpace(originalContent);
private string ConvertLabel => !IsContentConverted ? "Convert to markdown" : "Restore";
private string ConvertLabel => !IsContentConverted ? "Convert to markdown" : "Restore";

private bool canSubmit = true;
private IPagedList<ShortCode> shortCodes = PagedList<ShortCode>.Empty;
Expand Down
2 changes: 2 additions & 0 deletions src/LinkDotNet.Blog.Web/Features/Home/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@inject IOptions<ApplicationConfiguration> AppConfiguration
@inject NavigationManager NavigationManager

<PageTitle>@AppConfiguration.Value.BlogName</PageTitle>

<OgData Title="@(Markdown.ToPlainText(AppConfiguration.Value.BlogName))"
AbsolutePreviewImageUrl="@ImageUrl"
Description="@(Markdown.ToPlainText(Introduction.Value.Description))"></OgData>
Expand Down
1 change: 0 additions & 1 deletion src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using Microsoft.AspNetCore.Components;
using MongoDB.Driver.Linq;

namespace LinkDotNet.Blog.Web.Features;

Expand Down
1 change: 0 additions & 1 deletion src/LinkDotNet.Blog.Web/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>@AppConfiguration.Value.BlogName</title>
<base href="~/"/>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
Expand Down
83 changes: 60 additions & 23 deletions tests/LinkDotNet.Blog.IntegrationTests/SmokeTests.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TestContext = Xunit.TestContext;

namespace LinkDotNet.Blog.IntegrationTests;

public sealed class SmokeTests : IClassFixture<WebApplicationFactory<Program>>, IDisposable, IAsyncDisposable
{
private readonly WebApplicationFactory<Program> factory;
private readonly IServiceScope scope;
private readonly HttpClient client;

public SmokeTests(WebApplicationFactory<Program> factory)
{
this.factory = factory.WithWebHostBuilder(builder =>
{
builder.UseSetting("BlogName", "Tests Title");
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
});

scope = this.factory.Services.CreateScope();
client = this.factory.CreateClient();
}

[Fact]
public async Task ShouldBootUpApplication()
{
using var client = factory.CreateClient();

var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
}

[Fact]
public async Task ShouldBootUpWithSqlDatabase()
{
await using var sqlFactory = factory.WithWebHostBuilder(builder =>
{
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
});
using var client = sqlFactory.CreateClient();

var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
Expand All @@ -48,8 +45,6 @@ public async Task ShouldBootUpWithSqlDatabase()
[Fact]
public async Task ShouldAllowDotsForTagSearch()
{
using var client = factory.CreateClient();

var result = await client.GetAsync("/searchByTag/.NET5", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
Expand All @@ -58,8 +53,6 @@ public async Task ShouldAllowDotsForTagSearch()
[Fact]
public async Task ShouldAllowDotsForFreeTextSearch()
{
using var client = factory.CreateClient();

var result = await client.GetAsync("/search/.NET5", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
Expand All @@ -69,7 +62,6 @@ public async Task ShouldAllowDotsForFreeTextSearch()
public async Task RssFeedShouldBeRateLimited()
{
const int numberOfRequests = 16;
using var client = factory.CreateClient();

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

public void Dispose() => factory?.Dispose();
[Fact]
public async Task ShowingBlogPost_ShouldOnlyHaveOneTitle()
{
var blogPost = new BlogPostBuilder().WithTitle("My Blog Post").Build();
var contextProvider = scope.ServiceProvider.GetRequiredService<IDbContextFactory<BlogDbContext>>();
await using var context = await contextProvider.CreateDbContextAsync(TestContext.Current.CancellationToken);
await context.BlogPosts.AddAsync(blogPost, TestContext.Current.CancellationToken);
await context.SaveChangesAsync(TestContext.Current.CancellationToken);

var result = await client.GetAsync($"/blogPost/{blogPost.Id}", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
var content = await result.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
var document = GetHtmlDocument(content);
var titleTags = document.QuerySelectorAll("title");
titleTags.Length.ShouldBe(1);
titleTags.Single().TextContent.ShouldBe("My Blog Post");
}

[Fact]
public async Task IndexPage_HasTitleFromConfiguration()
{
var result = await client.GetAsync("/", cancellationToken: TestContext.Current.CancellationToken);

result.IsSuccessStatusCode.ShouldBeTrue();
var content = await result.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
var document = GetHtmlDocument(content);
var titleTags = document.QuerySelectorAll("title");
titleTags.Length.ShouldBe(1);
titleTags.Single().TextContent.ShouldBe("Tests Title");
}

public void Dispose()
{
scope.Dispose();
client.Dispose();
factory?.Dispose();
}

public async ValueTask DisposeAsync()
{
scope.Dispose();
client.Dispose();
await factory.DisposeAsync();
}

private static IHtmlDocument GetHtmlDocument(string html)
{
var parser = new HtmlParser();
return parser.ParseDocument(html);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Html.Dom;
using Blazored.Toast.Services;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities.Fakes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Blazored.Toast.Services;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.Components;
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.Blog.Web.Features.ShowBlogPost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.RegistrationExtensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.RegistrationExtensions;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.RegistrationExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using NCronJob;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Linq;
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.Home.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.TestUtilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Authentication.OpenIdConnect;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.Home.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq;
using AngleSharp.Css.Dom;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.Home.Components;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;

namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using AngleSharp.Html.Dom;
using Blazored.Toast.Services;
Expand Down

0 comments on commit 28fb2ef

Please sign in to comment.