mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Add in-memory configuration for tests.
This commit is contained in:
parent
07ff4cfe64
commit
de00f41115
@ -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<string, string?>
|
||||
{
|
||||
["ApplicationOptions:DbProvider"] = "inmemory"
|
||||
};
|
||||
_builder.Configuration.AddInMemoryCollection(appSettings);
|
||||
|
||||
_builder.Services.AddDbContext<AppDb, TestingDbContext>(
|
||||
contextLifetime: ServiceLifetime.Transient,
|
||||
optionsLifetime: ServiceLifetime.Transient);
|
||||
@ -44,7 +51,6 @@ public class IoCActivator
|
||||
_builder.Services.AddTransient<IEmailSenderEx, EmailSenderEx>();
|
||||
|
||||
_webApp = _builder.Build();
|
||||
ServiceProvider = _webApp.Services;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user