0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-30 02:31:08 +00:00

fix: Seeding test data

This commit is contained in:
alex289 2024-04-24 22:10:56 +02:00
parent 2c7748d877
commit dca566cbf6
No known key found for this signature in database
GPG Key ID: 573F77CD2D87F863
2 changed files with 23 additions and 1 deletions

View File

@ -7,7 +7,6 @@ using CleanArchitecture.Domain.Enums;
using CleanArchitecture.Infrastructure.Database;
using CleanArchitecture.IntegrationTests.Infrastructure;
using CleanArchitecture.IntegrationTests.Infrastructure.Auth;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
@ -40,6 +39,28 @@ public class TestFixtureBase : IAsyncLifetime
using var scope = Factory.Services.CreateScope();
await using var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
dbContext.Tenants.Add(new Tenant(
Ids.Seed.TenantId,
"Admin Tenant"));
dbContext.Users.Add(new User(
Ids.Seed.UserId,
Ids.Seed.TenantId,
"admin@email.com",
"Admin",
"User",
"$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2",
UserRole.Admin));
dbContext.Users.Add(new User(
TestAuthenticationOptions.TestUserId,
Ids.Seed.TenantId,
TestAuthenticationOptions.Email,
TestAuthenticationOptions.FirstName,
TestAuthenticationOptions.LastName,
TestAuthenticationOptions.Password,
UserRole.Admin));
SeedTestData(dbContext);
await dbContext.SaveChangesAsync();
}

View File

@ -10,6 +10,7 @@ public sealed class TestAuthenticationOptions : AuthenticationSchemeOptions
public const string Email = "integration@tests.com";
public const string FirstName = "Integration";
public const string LastName = "Tests";
public const string Password = "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2";
public static Guid TestUserId = new("561e4300-94d6-4c3f-adf5-31c1bdbc64df");
public ClaimsIdentity Identity { get; } = new(