mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-30 02:31:08 +00:00
fix: Seed test data correctly
This commit is contained in:
parent
1d73b226c2
commit
54062982d7
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user