C# formatting
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using GameList.Data;
|
||||
using GameList.Infrastructure;
|
||||
using GameList.Tests.Support;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -13,7 +12,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Register_trims_limits_and_sets_cookie_and_normalized_username()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
var response = await client.PostAsJsonAsync("/api/auth/register", new
|
||||
@@ -25,8 +24,7 @@ public class AuthTests
|
||||
});
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
Assert.True(response.Headers.TryGetValues("Set-Cookie", out var cookies) &&
|
||||
cookies.Any(c => c.Contains(PlayerIdentityExtensions.PlayerCookieName)));
|
||||
Assert.True(response.Headers.TryGetValues("Set-Cookie", out var cookies) && cookies.Any(c => c.Contains(PlayerIdentityExtensions.PlayerCookieName)));
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
{
|
||||
@@ -41,7 +39,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Register_rejects_overlength_username_or_display_name()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
var tooLongUser = new string('u', 25);
|
||||
@@ -67,7 +65,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Login_sets_last_login_and_fills_missing_display_name()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("loginfill");
|
||||
|
||||
@@ -93,7 +91,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Register_with_admin_key_sets_admin_flag()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
var response = await client.RegisterAsync("adminuser", admin: true);
|
||||
@@ -106,7 +104,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Register_duplicate_username_returns_conflict()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
var first = await client.RegisterAsync("duplicate");
|
||||
@@ -120,7 +118,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Login_with_wrong_password_returns_unauthorized()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
await client.RegisterAsync("player1");
|
||||
@@ -133,20 +131,31 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Register_validates_required_fields()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
|
||||
var missing = await client.PostAsJsonAsync("/api/auth/register", new { Username = "", Password = "", DisplayName = "" });
|
||||
var missing = await client.PostAsJsonAsync("/api/auth/register", new
|
||||
{
|
||||
Username = "",
|
||||
Password = "",
|
||||
DisplayName = ""
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, missing.StatusCode);
|
||||
|
||||
var badKey = await client.PostAsJsonAsync("/api/auth/register", new { Username = "u", Password = "p", DisplayName = "d", AdminKey = "wrong" });
|
||||
var badKey = await client.PostAsJsonAsync("/api/auth/register", new
|
||||
{
|
||||
Username = "u",
|
||||
Password = "p",
|
||||
DisplayName = "d",
|
||||
AdminKey = "wrong"
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, badKey.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Non_admin_cannot_access_admin_routes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var player = factory.CreateClientWithCookies();
|
||||
await player.RegisterAsync("regular");
|
||||
|
||||
@@ -157,7 +166,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Admin_can_access_admin_routes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("adminuser", admin: true);
|
||||
|
||||
@@ -168,7 +177,7 @@ public class AuthTests
|
||||
[Fact]
|
||||
public async Task Logout_clears_cookie()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("logoutme");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user