From 9c769046bbbbc92282605654b2ef2c2fd32ce15e Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Mon, 13 Nov 2023 18:14:44 -0500 Subject: [PATCH] Added helpers for creating in-memory database contexts for testing --- .../MemoryDatabaseContext.cs | 13 +++++++++++++ .../Tgstation.Server.Host.Tests.csproj | 4 ++++ tests/Tgstation.Server.Host.Tests/Utils.cs | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/Tgstation.Server.Host.Tests/MemoryDatabaseContext.cs create mode 100644 tests/Tgstation.Server.Host.Tests/Utils.cs diff --git a/tests/Tgstation.Server.Host.Tests/MemoryDatabaseContext.cs b/tests/Tgstation.Server.Host.Tests/MemoryDatabaseContext.cs new file mode 100644 index 0000000000..0bc4f8e300 --- /dev/null +++ b/tests/Tgstation.Server.Host.Tests/MemoryDatabaseContext.cs @@ -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) + { + } + } +} diff --git a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj index f921ae5bf0..f0f88a74b5 100644 --- a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj +++ b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj @@ -5,6 +5,10 @@ $(TgsFrameworkVersion) + + + + diff --git a/tests/Tgstation.Server.Host.Tests/Utils.cs b/tests/Tgstation.Server.Host.Tests/Utils.cs new file mode 100644 index 0000000000..3700bff8d6 --- /dev/null +++ b/tests/Tgstation.Server.Host.Tests/Utils.cs @@ -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() + .UseInMemoryDatabase(databaseName: "TgsTestDB") + .Options; + return new MemoryDatabaseContext(options); + } + } +}