This commit is contained in:
Paul Schneider 2026-04-20 00:35:51 +01:00
commit 6cc0c519d2
15 changed files with 81 additions and 187 deletions

View file

@ -53,8 +53,6 @@ namespace yavscTests
public void HaveConfigurationRoot()
{
var builder = new ConfigurationBuilder();
builder.AddJsonFile( "appsettings.json", false);
builder.AddJsonFile( "appsettings.Development.json", true);
configurationRoot = builder.Build();
}

View file

@ -25,20 +25,18 @@ namespace yavscTests
[Fact]
public void SendEMailSynchrone()
{
AssertAsync.CompletesIn(2, () =>
{
using IServiceScope scope = _serverFixture.Services.CreateScope();
ITrueEmailSender mailSender = scope.ServiceProvider.GetRequiredService<ITrueEmailSender>();
output.WriteLine("SendEMailSynchrone ...");
mailSender.SendEmailAsync
(
_serverFixture.SiteSettings.Owner.Name,
_serverFixture.SiteSettings.Owner.EMail,
$"monthly email",
"test boby monthly email").Wait();
});
}
using IServiceScope scope = _serverFixture.Services.CreateScope();
ITrueEmailSender mailSender = scope.ServiceProvider.GetRequiredService<ITrueEmailSender>();
output.WriteLine("SendEMailSynchrone ...");
mailSender.SendEmailAsync
(
_serverFixture.SiteSettings.Owner.Name,
_serverFixture.SiteSettings.Owner.EMail,
$"monthly email",
"test boby monthly email").Wait();
}
}
}

View file

@ -1,37 +0,0 @@
using System;
using System.Threading.Tasks;
namespace yavscTests {
public static class AssertAsync {
/// <summary>
/// Completes In
/// </summary>
/// <param name="timeoutFromSecond"></param>
/// <param name="action"></param>
public static void CompletesIn(int timeoutFromSecond, Action action)
{
var task = Task.Run(action);
var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeoutFromSecond));
if (task.Exception != null)
{
if (task.Exception.InnerExceptions.Count == 1)
{
throw task.Exception.InnerExceptions[0];
}
throw task.Exception;
}
if (!completedInTime)
{
throw new TimeoutException($"Task did not complete in {timeoutFromSecond} seconds.");
}
}
}
}

View file

@ -1,4 +1,4 @@
using IdentityServer8.EntityFramework.DbContexts;
using IdentityServer8.EntityFramework.Entities;
using IdentityServer8.Models;
using Microsoft.AspNetCore.Builder;
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -137,28 +137,16 @@ namespace isnd.tests
var builder = WebApplication.CreateBuilder();
builder.Environment.EnvironmentName = "Development";
// Set ContentRoot to the Yavsc.Org project directory so WebRootPath resolves correctly
var testAssemblyLocation = AppDomain.CurrentDomain.BaseDirectory;
var yavscOrgPath = Path.GetFullPath(Path.Combine(testAssemblyLocation, "../../src/Yavsc.Org"));
builder.Environment.ContentRootPath = yavscOrgPath;
ConfigureLogger();
builder.Configuration
var config = builder.Configuration
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: false)
.AddEnvironmentVariables()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["UseInMemoryDatabase"] = "true",
["UseTestEmailSender"] = "true",
["Smtp:Host"] = "localhost",
["Smtp:Port"] = "25",
["Smtp:SenderName"] = "Yavsc Test",
["Smtp:SenderEmail"] = "test@example.com",
["Site:Audience"] = "https://localhost",
["Site:Authority"] = "https://localhost"
});
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: false)
.AddEnvironmentVariables().Build();
// Configure Kestrel for HTTPS with self-signed certificate on a dynamic port
builder.WebHost.ConfigureKestrel(options =>
@ -174,6 +162,7 @@ namespace isnd.tests
_app = builder.ConfigureWebAppServices();
Services = _app.Services;
SiteSettings = _app.Services.GetRequiredService<IOptions<SiteSettings>>().Value;
String cxStr = config.GetConnectionString(Constants.YavscConnectionStringName) ?? throw new InvalidOperationException("DefaultConnection string is not configured.");
using (var migrationScope = _app.Services.CreateScope())
{
@ -181,7 +170,7 @@ namespace isnd.tests
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
TestingUserName = "Tester";
TestingUserPassword = "tesT456+*";
TestingUserPassword = "Test123!";
TestClientId = "testClientId";
TestingUserEmail = "test@no-reply.com";
TestingUser = null;

View file

@ -1,6 +1,7 @@
{
"Site": {
"Authority": "https://localhost",
"Audience": "https://localhost",
"Authority": "https://mercure.pschneider.fr",
"Title": "Yavsc dev",
"Slogan": "Yavsc : WIP.",
"Banner": "/images/yavsc.png",
@ -26,14 +27,11 @@
}
},
"Smtp": {
"Host": "localhost",
"Port": 25,
"EnableSSL": false
"Server": "localhost",
"Port": 465
},
"Logging": {
"IncludeScopes": {
},
"IncludeScopes": {},
"LogLevel": {
"Default": "Debug",
"System": "Warning",
@ -41,8 +39,8 @@
}
},
"ConnectionStrings": {
"YavscConnection": "Server=lame-NpgsqlHostName;Port=5432;Database=lame-DataBase;Username=lame-Username;Password=lame-dbPassword;"
},
"YavscConnection": "Server=localhost;Port=5432;Database=testingYavsc;Username=lame-Username;Password=lame-dbPassword;"
},
"DataProtection": {
"Keys": {
"Dir": "DataProtection-Keys"
@ -56,14 +54,14 @@
"Default": "lame-default-connection-string",
"DatabaseCtor": "lame-database-ctor-connection-string"
},
"YavscWebPath": "../../src/Yavsc",
"YavscWebPath": "../../src/Yavsc",
"ValidCreds": {
"UserName": "lame-user",
"Password": "lame-password"
"UserName": "lame-user",
"Password": "lame-password"
},
"InvalidCreds": {
"UserName": "fakeuser",
"Password": "f/\\kePassw0rd"
"UserName": "fakeuser",
"Password": "f/\\kePassw0rd"
}
}
}
}

View file

@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>Yavsc.Tests</RootNamespace>
<UserSecretsId>78a4efec-68dc-4745-ba06-d8545ef9ee91</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" />
@ -29,6 +30,11 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.*.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Yavsc.Org\Yavsc.Org.csproj" />
<ProjectReference Include="..\..\src\Yavsc.Abstract\Yavsc.Abstract.csproj" />
@ -37,4 +43,5 @@
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>