Add comprehensive backend test suite and helper access
This commit is contained in:
@@ -43,4 +43,11 @@ internal static class TestClientExtensions
|
||||
var json = await response.Content.ReadFromJsonAsync<JsonElement>();
|
||||
return json.GetProperty("id").GetInt32();
|
||||
}
|
||||
|
||||
public static async Task<Guid> GetProfileIdAsync(this HttpClient client)
|
||||
{
|
||||
var me = await client.GetFromJsonAsync<JsonElement>("/api/me");
|
||||
return Guid.Parse(me.GetProperty("id").GetString()!);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,6 +79,13 @@ internal class TestWebApplicationFactory : WebApplicationFactory<Program>
|
||||
return action(db);
|
||||
}
|
||||
|
||||
public Task<T> WithDbContextAsync<T>(Func<AppDbContext, Task<T>> action)
|
||||
{
|
||||
using var scope = Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
return action(db);
|
||||
}
|
||||
|
||||
public HttpClient CreateClientWithCookies()
|
||||
{
|
||||
return CreateClient(new WebApplicationFactoryClientOptions
|
||||
|
||||
Reference in New Issue
Block a user