forked from gongxuegit/tiku-backend.net
fix: make development database seeding reliable
This commit is contained in:
@@ -8,6 +8,7 @@ using Tiku.Infrastructure;
|
|||||||
using Tiku.Infrastructure.Persistence;
|
using Tiku.Infrastructure.Persistence;
|
||||||
using Tiku.Infrastructure.Bootstrap;
|
using Tiku.Infrastructure.Bootstrap;
|
||||||
using Tiku.Application;
|
using Tiku.Application;
|
||||||
|
using Tiku.Application.Security;
|
||||||
|
|
||||||
var builder = Host.CreateApplicationBuilder(args);
|
var builder = Host.CreateApplicationBuilder(args);
|
||||||
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
|
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
|
||||||
@@ -47,6 +48,8 @@ builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();
|
|||||||
|
|
||||||
using var host = builder.Build();
|
using var host = builder.Build();
|
||||||
await using var scope = host.Services.CreateAsyncScope();
|
await using var scope = host.Services.CreateAsyncScope();
|
||||||
|
scope.ServiceProvider.GetRequiredService<ITenantContextInitializer>()
|
||||||
|
.InitializeSystem(null, "Database migration and bootstrap");
|
||||||
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
|
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
|
||||||
await dbContext.Database.MigrateAsync();
|
await dbContext.Database.MigrateAsync();
|
||||||
var catalogSeeder = ActivatorUtilities.CreateInstance<BuiltinBackofficeCatalogSeeder>(scope.ServiceProvider);
|
var catalogSeeder = ActivatorUtilities.CreateInstance<BuiltinBackofficeCatalogSeeder>(scope.ServiceProvider);
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ public static class DevelopmentPlatformAdminSeeder
|
|||||||
IdempotencyKey = "demo-platform-payment-quote",
|
IdempotencyKey = "demo-platform-payment-quote",
|
||||||
Status = PlatformBillingQuoteStatus.Converted,
|
Status = PlatformBillingQuoteStatus.Converted,
|
||||||
Purpose = PlatformBillingOrderPurpose.NewSubscription,
|
Purpose = PlatformBillingOrderPurpose.NewSubscription,
|
||||||
|
OriginalAmountCents = 19900,
|
||||||
TotalAmountCents = 19900,
|
TotalAmountCents = 19900,
|
||||||
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
|
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
|
||||||
};
|
};
|
||||||
@@ -422,6 +423,7 @@ public static class DevelopmentPlatformAdminSeeder
|
|||||||
IdempotencyKey = "demo-platform-payment-order",
|
IdempotencyKey = "demo-platform-payment-order",
|
||||||
Purpose = PlatformBillingOrderPurpose.NewSubscription,
|
Purpose = PlatformBillingOrderPurpose.NewSubscription,
|
||||||
Status = PlatformBillingOrderStatus.PendingPayment,
|
Status = PlatformBillingOrderStatus.PendingPayment,
|
||||||
|
OriginalAmountCents = 19900,
|
||||||
TotalAmountCents = 19900,
|
TotalAmountCents = 19900,
|
||||||
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
|
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ public sealed class PlatformAdminBootstrapperTests
|
|||||||
Assert.Equal(BackendPermissions.Platform.Count, await context.PlatformBackendRolePermissions.CountAsync());
|
Assert.Equal(BackendPermissions.Platform.Count, await context.PlatformBackendRolePermissions.CountAsync());
|
||||||
Assert.Single(context.PlatformBackendUserRoles);
|
Assert.Single(context.PlatformBackendUserRoles);
|
||||||
Assert.Single(context.AuditLogs);
|
Assert.Single(context.AuditLogs);
|
||||||
|
var quote = await context.PlatformBillingQuotes.SingleAsync();
|
||||||
|
Assert.Equal(quote.OriginalAmountCents - quote.DiscountAmountCents, quote.TotalAmountCents);
|
||||||
|
var order = await context.PlatformBillingOrders.SingleAsync();
|
||||||
|
Assert.Equal(order.OriginalAmountCents - order.DiscountAmountCents, order.TotalAmountCents);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user