diff --git a/src/SlpModularCms.Core.Tests/Golden/host/WebsitePlaceholder.nl.html b/src/SlpModularCms.Core.Tests/Golden/host/WebsitePlaceholder.nl.html new file mode 100644 index 0000000..ff261f7 --- /dev/null +++ b/src/SlpModularCms.Core.Tests/Golden/host/WebsitePlaceholder.nl.html @@ -0,0 +1,57 @@ + + + + + + + Nog geen website geplaatst + + + +
+

Er staat hier nog geen website

+

+ Het CMS draait, maar er is nog geen publieke website geplaatst. De website + wordt apart aangeleverd en hoort in de map wwwroot/web/ te staan, + met een index.html in de hoofdmap daarvan. +

+

+ Beheerders kunnen inloggen via /admin/. +

+

+ Deze pagina wordt automatisch vervangen zodra de website is geplaatst. +

+
+ + diff --git a/src/SlpModularCms.Core.Tests/Hosting/WebsitePlaceholderTests.cs b/src/SlpModularCms.Core.Tests/Hosting/WebsitePlaceholderTests.cs new file mode 100644 index 0000000..a7899a4 --- /dev/null +++ b/src/SlpModularCms.Core.Tests/Hosting/WebsitePlaceholderTests.cs @@ -0,0 +1,66 @@ +using System.Net; +using FluentAssertions; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using SlpModularCms.Core.Hosting; +using SlpModularCms.Core.Texts; +using Xunit; + +namespace SlpModularCms.Core.Tests.Hosting; + +/// +/// The page a host shows while no website is deployed. The golden file is the page as it was before its sentences moved +/// into the text files (Dutch); the rendered page must stay byte-identical. +/// +public sealed class WebsitePlaceholderTests : IDisposable +{ + private readonly string _root = Path.Combine(Path.GetTempPath(), "slp-placeholder-" + Guid.NewGuid().ToString("N")); + private WebApplication? _app; + + public void Dispose() + { + _app?.DisposeAsync().AsTask().GetAwaiter().GetResult(); + if (Directory.Exists(_root)) Directory.Delete(_root, recursive: true); + } + + private async Task StartAsync(string? language = null) + { + Directory.CreateDirectory(Path.Combine(_root, "wwwroot")); + var builder = WebApplication.CreateBuilder(new WebApplicationOptions + { + EnvironmentName = Environments.Production, + ContentRootPath = _root, + WebRootPath = Path.Combine(_root, "wwwroot"), + }); + builder.WebHost.UseTestServer(); + builder.Logging.ClearProviders(); + if (language is not null) builder.Configuration.AddInMemoryCollection(new Dictionary { ["Texts:DefaultLanguage"] = language }); + builder.Services.AddCmsTexts(builder.Configuration); + + _app = builder.Build(); + _app.UseCmsStaticContent(WebsiteMode.SpaFallback); + _app.MapCmsSpaFallbacks(WebsiteMode.SpaFallback); + await _app.StartAsync(); + return _app.GetTestClient(); + } + + private static string Golden() => + File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Golden", "host", "WebsitePlaceholder.nl.html")).Replace("\r\n", "\n"); + + [Fact] + public async Task WithoutAWebsite_TheDutchPlaceholder_IsByteIdenticalToTheOriginalPage() + { + var client = await StartAsync(); + + var response = await client.GetAsync("/"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + response.Content.Headers.ContentType!.ToString().Should().Be("text/html; charset=utf-8"); + (await response.Content.ReadAsStringAsync()).Replace("\r\n", "\n").Should().Be(Golden()); + } +}