| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using Xunit;
- namespace Admin.NET.Plugin.AiDOP.Tests.Infrastructure;
- public class StartupDbInitSkipContractTests
- {
- [Fact]
- public void ExistingSchemaMode_SkipsPluginDatabaseInitializationBeforeSourceBackfill()
- {
- var source = File.ReadAllText(Path.Combine(
- RepoRoot(), "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Startup.cs"));
- var guard = source.IndexOf("Environment.GetEnvironmentVariable(\"DOCKER_SKIP_DBINIT\")", StringComparison.Ordinal);
- var backfill = source.IndexOf("MdpSchemaAligner.EnsureSourceIdentityAsync", StringComparison.Ordinal);
- Assert.True(guard >= 0);
- Assert.True(backfill > guard);
- Assert.Contains("return;", source[guard..backfill], StringComparison.Ordinal);
- }
- [Fact]
- public void ExistingSchemaMode_SkipsApprovalFlowCodeFirstAndSeeds()
- {
- var source = File.ReadAllText(Path.Combine(
- RepoRoot(), "server", "Plugins", "Admin.NET.Plugin.ApprovalFlow", "Startup.cs"));
- var middleware = source.IndexOf("app.UseApprovalFlow()", StringComparison.Ordinal);
- var guard = source.IndexOf("Environment.GetEnvironmentVariable(\"DOCKER_SKIP_DBINIT\")", StringComparison.Ordinal);
- var codeFirst = source.IndexOf("db.CodeFirst.InitTables", StringComparison.Ordinal);
- var seeds = source.IndexOf("EnsureSystemTemplates()", StringComparison.Ordinal);
- Assert.True(middleware >= 0);
- Assert.True(guard > middleware);
- Assert.True(codeFirst > guard);
- Assert.True(seeds > codeFirst);
- Assert.Contains("return;", source[guard..codeFirst], StringComparison.Ordinal);
- }
- private static string RepoRoot()
- {
- var dir = new DirectoryInfo(AppContext.BaseDirectory);
- while (dir != null && !Directory.Exists(Path.Combine(dir.FullName, "server")))
- dir = dir.Parent;
- return dir?.FullName ?? throw new DirectoryNotFoundException("Repository root not found.");
- }
- }
|