Skip to content

Fix Build for Tests and Update Image Version - #1017

Merged
ardalis merged 5 commits into
mainfrom
kyle/fix-test-container-image
May 27, 2026
Merged

ardalis merged 5 commits into
mainfrom
kyle/fix-test-container-image

Conversation

@KyleMcMaster

Copy link
Copy Markdown
Collaborator

This pull request fixes a build issue by updating the TestContainer builder to pass the image argument into the constructor rather than the WithImage method. It also updates the SQL Server Docker image used for integration testing to a newer version 2025.

Dependency update for test environment:

  • Updated the SQL Server Docker image in the MsSqlBuilder constructor from mcr.microsoft.com/mssql/server:2022-latest to mcr.microsoft.com/mssql/server:2025-latest in CustomWebApplicationFactory.cs, ensuring tests run against the latest SQL Server version.

@MartinHock

Copy link
Copy Markdown
Contributor

I would sugggest a slighly different version of create host.
protected override IHost CreateHost(IHostBuilder builder)
{
builder.UseEnvironment("Testing");

var host = builder.Build();
host.Start();

using var scope = host.Services.CreateScope();
var services = scope.ServiceProvider;

var db = services.GetRequiredService();
var logger = services.GetRequiredService<ILogger<CustomWebApplicationFactory>>();

try
{
if (_dbContainer != null)
{
// SQL Server → run migrations
db.Database.Migrate();
}
else
{
// SQLite fallback
db.Database.EnsureCreated();
}

// 🔥 CRITICAL: run seeding and FAIL HARD if it breaks
SeedData.InitializeAsync(db)
  .GetAwaiter()
  .GetResult();

// 🔍 Verify seeding worked
var contributorCount = db.Contributors.Count();

logger.LogInformation("Seeded {Count} contributors.", contributorCount);

if (contributorCount == 0)
{
  throw new InvalidOperationException(
    "Database seeding completed, but no contributors were created.");
}

}
catch (Exception ex)
{
logger.LogError(ex,
"An error occurred seeding the database. Error: {Message}",
ex.Message);

throw; // 🔥 DO NOT SWALLOW — fail tests immediately

}

return host;
}

@ardalis
ardalis merged commit 74624fb into main May 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants