Cleaned up various fixtures. Skip publish-image for now.
This commit is contained in:
@@ -1,20 +1,11 @@
|
||||
using JSMR.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JSMR.Tests.Fixtures;
|
||||
|
||||
public class CreatorSearchProviderFixture : MariaDbFixture
|
||||
public sealed class CreatorSearchProviderFixture(MariaDbContainerFixture container) : SearchProviderFixture(container)
|
||||
{
|
||||
protected override async Task OnInitializedAsync(AppDbContext context)
|
||||
protected override async Task SeedAsync(AppDbContext context)
|
||||
{
|
||||
await SeedAsync(context);
|
||||
}
|
||||
|
||||
private static async Task SeedAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.Tags.AnyAsync())
|
||||
return;
|
||||
|
||||
context.Creators.AddRange(
|
||||
new() { CreatorId = 1, Name = "John Smith" },
|
||||
new() { CreatorId = 2, Name = "John Doe", Favorite = true },
|
||||
@@ -23,47 +14,4 @@ public class CreatorSearchProviderFixture : MariaDbFixture
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public sealed class CreatorSearchProviderFixture2(MariaDbContainerFixture container) : IAsyncLifetime
|
||||
{
|
||||
public AppDbContext? DbContext { get; private set; }
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
//DbContext = await MariaTestDb.CreateIsolatedAsync(
|
||||
// container.RootConnectionString,
|
||||
// seed: SeedAsync);
|
||||
|
||||
var newDb = $"t_{DateTime.UtcNow:yyyyMMddHHmmss}_{Guid.NewGuid():N}";
|
||||
|
||||
DbContext = await MariaDbClone.CloneFromTemplateAsync(
|
||||
container.RootConnectionString,
|
||||
container.TemplateDbName,
|
||||
newDbName: newDb,
|
||||
seed: SeedAsync);
|
||||
}
|
||||
|
||||
private static async Task SeedAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.Tags.AnyAsync())
|
||||
return;
|
||||
|
||||
context.Creators.AddRange(
|
||||
new() { CreatorId = 1, Name = "John Smith" },
|
||||
new() { CreatorId = 2, Name = "John Doe", Favorite = true },
|
||||
new() { CreatorId = 3, Name = "Jane Doe", Blacklisted = true }
|
||||
);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (DbContext is not null)
|
||||
{
|
||||
await DbContext.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user