From de00f411151ce310fe9e674722a92245a9959543 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Wed, 21 Feb 2024 10:36:27 -0800 Subject: [PATCH] Add in-memory configuration for tests. --- Tests/Server.Tests/IoCActivator.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/Server.Tests/IoCActivator.cs b/Tests/Server.Tests/IoCActivator.cs index e905efb1..d8e55e67 100644 --- a/Tests/Server.Tests/IoCActivator.cs +++ b/Tests/Server.Tests/IoCActivator.cs @@ -21,7 +21,8 @@ namespace Remotely.Server.Tests; [TestClass] public class IoCActivator { - public static IServiceProvider ServiceProvider { get; set; } = null!; + public static IServiceProvider ServiceProvider => _webApp?.Services ?? + throw new InvalidOperationException("The web application has not been initialized."); private static WebApplicationBuilder? _builder; private static WebApplication? _webApp; @@ -30,6 +31,12 @@ public class IoCActivator { _builder = WebApplication.CreateBuilder(); + var appSettings = new Dictionary + { + ["ApplicationOptions:DbProvider"] = "inmemory" + }; + _builder.Configuration.AddInMemoryCollection(appSettings); + _builder.Services.AddDbContext( contextLifetime: ServiceLifetime.Transient, optionsLifetime: ServiceLifetime.Transient); @@ -44,7 +51,6 @@ public class IoCActivator _builder.Services.AddTransient(); _webApp = _builder.Build(); - ServiceProvider = _webApp.Services; } }