From c2814e289d2002cc42d0f94c204e9be2c16449fb Mon Sep 17 00:00:00 2001 From: "a.civier" Date: Fri, 17 May 2024 16:35:40 +0200 Subject: [PATCH] remove in memory database --- Directory.Build.props | 2 -- Directory.Packages.props | 1 - src/Api/Api.csproj | 10 ------ .../Data/ApplicationDbContextInitialiser.cs | 2 -- ...plicationDbContextInitialiserExtensions.cs | 3 +- src/Infrastructure/DependencyInjection.cs | 4 --- src/Infrastructure/Infrastructure.csproj | 1 - .../CustomWebApplicationFactory.cs | 4 --- .../InMemoryTestDatabase.cs | 34 ------------------- .../TestDatabaseFactory.cs | 5 --- 10 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 tests/Application.FunctionalTests/InMemoryTestDatabase.cs diff --git a/Directory.Build.props b/Directory.Build.props index 7856694..e446765 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,8 +5,6 @@ enable enable Don't Nod - - $(DefineConstants);USE_SQL_LITE \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index a144dbd..907bfc1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -25,7 +25,6 @@ https://devblogs.microsoft.com/nuget/introducing-central-package-management/ --> - diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj index 647c698..58abb9f 100644 --- a/src/Api/Api.csproj +++ b/src/Api/Api.csproj @@ -14,20 +14,10 @@ - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - diff --git a/src/Infrastructure/Data/ApplicationDbContextInitialiser.cs b/src/Infrastructure/Data/ApplicationDbContextInitialiser.cs index e1e4ce9..7191c59 100644 --- a/src/Infrastructure/Data/ApplicationDbContextInitialiser.cs +++ b/src/Infrastructure/Data/ApplicationDbContextInitialiser.cs @@ -6,7 +6,6 @@ public class ApplicationDbContextInitialiser(ILogger logger, ApplicationDbContext context) { -#if USE_SQL_LITE public async Task InitialiseAsync() { try @@ -19,7 +18,6 @@ public async Task InitialiseAsync() throw; } } -#endif public async Task SeedAsync() { diff --git a/src/Infrastructure/Data/ApplicationDbContextInitialiserExtensions.cs b/src/Infrastructure/Data/ApplicationDbContextInitialiserExtensions.cs index c2635e2..fac118c 100644 --- a/src/Infrastructure/Data/ApplicationDbContextInitialiserExtensions.cs +++ b/src/Infrastructure/Data/ApplicationDbContextInitialiserExtensions.cs @@ -10,9 +10,8 @@ public static async Task InitialiseDatabaseAsync(this WebApplication app) using var scope = app.Services.CreateScope(); var initialiser = scope.ServiceProvider.GetRequiredService(); -#if USE_SQL_LITE + await initialiser.InitialiseAsync(); -#endif await initialiser.SeedAsync(); } diff --git a/src/Infrastructure/DependencyInjection.cs b/src/Infrastructure/DependencyInjection.cs index 60a552e..8082f99 100644 --- a/src/Infrastructure/DependencyInjection.cs +++ b/src/Infrastructure/DependencyInjection.cs @@ -22,11 +22,7 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti { options.AddInterceptors(sp.GetServices()); -#if USE_SQL_LITE options.UseSqlite(connectionString); -#else - options.UseInMemoryDatabase("AppDatabase"); -#endif }); services.AddScoped(provider => provider.GetRequiredService()); diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 8f8f50e..434f921 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -10,7 +10,6 @@ - diff --git a/tests/Application.FunctionalTests/CustomWebApplicationFactory.cs b/tests/Application.FunctionalTests/CustomWebApplicationFactory.cs index bafaf79..f3ca30e 100644 --- a/tests/Application.FunctionalTests/CustomWebApplicationFactory.cs +++ b/tests/Application.FunctionalTests/CustomWebApplicationFactory.cs @@ -33,11 +33,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) .AddDbContext((sp, options) => { options.AddInterceptors(sp.GetServices()); -#if USE_SQL_LITE options.UseSqlite(connection); -#else - options.UseInMemoryDatabase("AppDatabase"); -#endif }); }); } diff --git a/tests/Application.FunctionalTests/InMemoryTestDatabase.cs b/tests/Application.FunctionalTests/InMemoryTestDatabase.cs deleted file mode 100644 index b08031d..0000000 --- a/tests/Application.FunctionalTests/InMemoryTestDatabase.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace WebAppStarter.Application.FunctionalTests; - -using System.Data.Common; -using Microsoft.EntityFrameworkCore; -using WebAppStarter.Infrastructure.Data; - -public class InMemoryTestDatabase : ITestDatabase -{ - public Task InitialiseAsync() - { - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase("TestDatabase") - .Options; - - var context = new ApplicationDbContext(options); - - return Task.CompletedTask; - } - - public DbConnection GetConnection() - { - return null!; - } - - public async Task ResetAsync() - { - await InitialiseAsync(); - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/tests/Application.FunctionalTests/TestDatabaseFactory.cs b/tests/Application.FunctionalTests/TestDatabaseFactory.cs index 1d56b6e..dbada42 100644 --- a/tests/Application.FunctionalTests/TestDatabaseFactory.cs +++ b/tests/Application.FunctionalTests/TestDatabaseFactory.cs @@ -4,12 +4,7 @@ public static class TestDatabaseFactory { public static async Task CreateAsync() { -#if USE_SQL_LITE var database = new SqliteTestDatabase(); -#else - - var database = new InMemoryTestDatabase(); -#endif await database.InitialiseAsync();