C# formatting

This commit is contained in:
2026-02-05 20:39:12 +01:00
parent 78cdbfe51e
commit c0756ff2c6
34 changed files with 830 additions and 582 deletions

View File

@@ -1,11 +1,9 @@
using System.Security.Claims;
using GameList.Domain;
using GameList.Infrastructure;
using GameList.Tests.Support;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace GameList.Tests;
@@ -14,16 +12,16 @@ public class IdentityTests
[Fact]
public async Task Sign_in_sets_claims_and_cookie()
{
using var factory = new TestWebApplicationFactory();
var ctx = BuildAuthContext(factory.Services);
await using var factory = new TestWebApplicationFactory();
var ctx = BuildAuthContext();
var player = new Player
{
Id = Guid.NewGuid(),
Username = "claimuser",
NormalizedUsername = "claimuser",
PasswordHash = new byte[] { 1 },
PasswordSalt = new byte[] { 1 },
PasswordHash = [1],
PasswordSalt = [1],
DisplayName = "Claim",
IsAdmin = true
};
@@ -31,15 +29,14 @@ public class IdentityTests
await PlayerIdentityExtensions.SignInPlayerAsync(ctx, player);
var cookies = ctx.Response.Headers["Set-Cookie"];
Assert.NotNull(cookies);
Assert.Contains(cookies!, v => v.Contains(PlayerIdentityExtensions.PlayerCookieName));
Assert.Contains(cookies, v => v != null && v.Contains(PlayerIdentityExtensions.PlayerCookieName));
}
[Fact]
public async Task Sign_out_clears_principal()
{
using var factory = new TestWebApplicationFactory();
var ctx = BuildAuthContext(factory.Services);
await using var factory = new TestWebApplicationFactory();
var ctx = BuildAuthContext();
var player = new Player();
await PlayerIdentityExtensions.SignInPlayerAsync(ctx, player);
@@ -48,15 +45,11 @@ public class IdentityTests
Assert.False(ctx.User.Identity?.IsAuthenticated ?? false);
}
private static DefaultHttpContext BuildAuthContext(IServiceProvider services)
private static DefaultHttpContext BuildAuthContext()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
serviceCollection.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = PlayerIdentityExtensions.PlayerCookieName;
});
serviceCollection.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { options.Cookie.Name = PlayerIdentityExtensions.PlayerCookieName; });
serviceCollection.AddLogging();
var provider = serviceCollection.BuildServiceProvider();