0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-30 18:42:56 +00:00

fix: Seed test data correctly

This commit is contained in:
Alexander Konietzko 2024-08-05 09:16:50 +02:00
parent 1d73b226c2
commit 54062982d7
No known key found for this signature in database
GPG Key ID: BA6905F37AEC2B5B
4 changed files with 50 additions and 13 deletions

View File

@ -18,7 +18,7 @@ public sealed class UserControllerTests
private readonly UserTestFixture _fixture = new();
[OneTimeSetUp]
public async Task Setup() => await GlobalSetupFixture.RespawnDatabaseAsync();
public async Task Setup() => await _fixture.SeedTestData();
[Test, Order(0)]
public async Task Should_Get_All_User()

View File

@ -1,5 +1,43 @@
namespace CleanArchitecture.IntegrationTests.Fixtures;
using CleanArchitecture.Domain.Enums;
using CleanArchitecture.Infrastructure.Database;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using CleanArchitecture.Domain.Constants;
using CleanArchitecture.IntegrationTests.Infrastructure.Auth;
using CleanArchitecture.Domain.Entities;
namespace CleanArchitecture.IntegrationTests.Fixtures;
public sealed class UserTestFixture : TestFixtureBase
{
public async Task SeedTestData()
{
await GlobalSetupFixture.RespawnDatabaseAsync();
using var context = Factory.Services.GetRequiredService<ApplicationDbContext>();
context.Tenants.Add(new Tenant(
Ids.Seed.TenantId,
"Admin Tenant"));
context.Users.Add(new User(
Ids.Seed.UserId,
Ids.Seed.TenantId,
"admin@email.com",
"Admin",
"User",
"$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2",
UserRole.Admin));
context.Users.Add(new User(
TestAuthenticationOptions.TestUserId,
Ids.Seed.TenantId,
TestAuthenticationOptions.Email,
TestAuthenticationOptions.FirstName,
TestAuthenticationOptions.LastName,
TestAuthenticationOptions.Password,
UserRole.Admin));
await context.SaveChangesAsync();
}
}

View File

@ -28,6 +28,10 @@ public sealed class GetUsersByIdsTestFixture : TestFixtureBase
using var context = Factory.Services.GetRequiredService<ApplicationDbContext>();
context.Tenants.Add(new Tenant(
Ids.Seed.TenantId,
"Admin Tenant"));
var user = CreateUser();
context.Users.Add(user);

View File

@ -12,17 +12,12 @@ public sealed class AuthTests
[OneTimeSetUp]
public async Task Setup() => await GlobalSetupFixture.RespawnDatabaseAsync();
[Datapoints]
public string[] values =
[
"/api/v1/user",
"/api/v1/user/me",
"/api/v1/user/d74b112a-ece0-443d-9b4f-85bc418822ca",
"/api/v1/tenant",
"/api/v1/tenant/d74b112a-ece0-443d-9b4f-85bc418822ca"
];
[Theory]
[Test]
[TestCase("/api/v1/user")]
[TestCase("/api/v1/user/me")]
[TestCase("/api/v1/user/d74b112a-ece0-443d-9b4f-85bc418822ca")]
[TestCase("/api/v1/tenant")]
[TestCase("/api/v1/tenant/d74b112a-ece0-443d-9b4f-85bc418822ca")]
public async Task Should_Get_Unauthorized_If_Trying_To_Call_Endpoint_Without_Token(string url)
{
var response = await _fixture.ServerClient.GetAsync(url);