diff --git a/backend.tests/AuthTests.cs b/backend.tests/AuthTests.cs index 9221b55..482c5ca 100644 --- a/backend.tests/AuthTests.cs +++ b/backend.tests/AuthTests.cs @@ -5,14 +5,13 @@ using Xunit; namespace backend.tests; -public class AuthTests(ApiFactory factory) : IClassFixture +public class AuthTests { - private readonly ApiFactory _factory = factory; - [Fact] public async Task Register_then_login_then_me_returns_user() { - var client = _factory.CreateClient(); + using var factory = new ApiFactory(); + var client = factory.CreateClient(); var reg = await client.PostAsJsonAsync("/api/auth/register", new { email = "first@example.com", password = "Passw0rd!" }); @@ -30,7 +29,8 @@ public class AuthTests(ApiFactory factory) : IClassFixture [Fact] public async Task Me_without_login_returns_401() { - var client = _factory.CreateClient(); + using var factory = new ApiFactory(); + var client = factory.CreateClient(); var res = await client.GetAsync("/api/auth/me"); res.StatusCode.Should().Be(HttpStatusCode.Unauthorized); } @@ -38,11 +38,12 @@ public class AuthTests(ApiFactory factory) : IClassFixture [Fact] public async Task First_user_is_admin() { - var client = _factory.CreateClient(); + using var factory = new ApiFactory(); + var client = factory.CreateClient(); await client.PostAsJsonAsync("/api/auth/register", - new { email = "first@example.com", password = "Passw0rd!" }); + new { email = "admin@example.com", password = "Passw0rd!" }); await client.PostAsJsonAsync("/api/auth/login", - new { email = "first@example.com", password = "Passw0rd!" }); + new { email = "admin@example.com", password = "Passw0rd!" }); var me = await client.GetAsync("/api/auth/me"); (await me.Content.ReadAsStringAsync()).Should().Contain("\"isAdmin\":true"); diff --git a/backend/Auth/AuthEndpoints.cs b/backend/Auth/AuthEndpoints.cs index 673b512..39daeb3 100644 --- a/backend/Auth/AuthEndpoints.cs +++ b/backend/Auth/AuthEndpoints.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; namespace backend.Auth; @@ -15,8 +14,7 @@ public static class AuthEndpoints grp.MapPost("/register", async ( [FromBody] RegisterRequest req, - UserManager users, - RoleManager> roles) => + UserManager users) => { var user = new ApplicationUser { UserName = req.Email, Email = req.Email }; var create = await users.CreateAsync(user, req.Password);