forked from udap-tools/udap-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageFixture.cs
50 lines (40 loc) · 1.6 KB
/
StorageFixture.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
49
50
#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 StorageFixture<TClass, TDbContext, TStoreOption> : IClassFixture<TestDatabaseProvider<TDbContext>>
where TDbContext : DbContext
where TStoreOption : class
{
public static readonly TheoryData<DbContextOptions<TDbContext>> TestDatabaseProviders;
protected static readonly TStoreOption StoreOptions = Activator.CreateInstance<TStoreOption>();
static StorageFixture()
{
TestDatabaseProviders = new TheoryData<DbContextOptions<TDbContext>>
{
// DatabaseProviderBuilder.BuildInMemory<TDbContext, TStoreOption>(typeof(TClass).Name, StoreOptions),
DatabaseProviderBuilder.BuildSqlite<TDbContext, TStoreOption>(typeof(TClass).Name, StoreOptions)
// DatabaseProviderBuilder.BuildLocalDb<TDbContext, TStoreOption>(typeof(TClass).Name, StoreOptions)
};
}
protected StorageFixture(TestDatabaseProvider<TDbContext> fixture)
{
var optionsList = new List<DbContextOptions<TDbContext>>();
foreach (var options in TestDatabaseProviders)
{
optionsList.Add((DbContextOptions<TDbContext>)options);
}
fixture.Options = optionsList;
}
}