forked from udap-tools/udap-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDatabaseProvider.cs
48 lines (38 loc) · 1.13 KB
/
TestDatabaseProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#region (c) 2023 Joseph Shook. All rights reserved.
// /*
// Authors:
// Joseph Shook [email protected]
//
// See LICENSE in the project root for license information.
// */
#endregion
//
// This code was inspired from Duende Identity Server Tests
//
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.
using Microsoft.EntityFrameworkCore;
namespace UdapServer.Tests;
public class TestDatabaseProvider<T> : IDisposable where T : DbContext
{
public List<DbContextOptions<T>>? Options;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (Options != null) // null check since fixtures are created even when tests are skipped
{
foreach (var option in Options.ToList())
{
using var context = (T)Activator.CreateInstance(typeof(T), option)!;
context!.Database.EnsureDeleted();
}
}
}
}
}