mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
Added helpers for creating in-memory database contexts for testing
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Tgstation.Server.Host.Database;
|
||||
|
||||
namespace Tgstation.Server.Host.Tests
|
||||
{
|
||||
sealed class MemoryDatabaseContext : DatabaseContext
|
||||
{
|
||||
public MemoryDatabaseContext(DbContextOptions dbContextOptions) : base(dbContextOptions)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
<TargetFramework>$(TgsFrameworkVersion)</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Tgstation.Server.Host\Tgstation.Server.Host.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Tgstation.Server.Host.Database;
|
||||
|
||||
namespace Tgstation.Server.Host.Tests
|
||||
{
|
||||
static class Utils
|
||||
{
|
||||
public static MemoryDatabaseContext CreateDatabaseContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<MemoryDatabaseContext>()
|
||||
.UseInMemoryDatabase(databaseName: "TgsTestDB")
|
||||
.Options;
|
||||
return new MemoryDatabaseContext(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user