using Koogle.Infrastructure.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using KoogleApp.Data;
namespace Koogle.Tests.Integration;
///
/// Custom WebApplicationFactory for integration testing.
/// Uses the Web project's Program class via assembly reference.
///
///
/// To use this fixture, add `[assembly: InternalsVisibleTo("Koogle.Tests")]`
/// to the Koogle.Web project, or expose Program class publicly.
/// Alternatively, use the standalone integration test approach below.
///
public class StandaloneIntegrationTestBase : IAsyncLifetime
{
protected AppDbContext Context { get; private set; } = null!;
public Task InitializeAsync()
{
var options = new DbContextOptionsBuilder()
.UseInMemoryDatabase($"TestDb_{Guid.NewGuid()}")
.Options;
Context = new AppDbContext(options);
return Task.CompletedTask;
}
public async Task DisposeAsync()
{
await Context.DisposeAsync();
}
}
///
/// Collection fixture for sharing test database across integration tests.
///
[CollectionDefinition("Integration")]
public class IntegrationTestCollection : ICollectionFixture
{
}