-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathIntegrationTest.cs
More file actions
66 lines (56 loc) · 2.67 KB
/
Copy pathIntegrationTest.cs
File metadata and controls
66 lines (56 loc) · 2.67 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Copyright (c) 2024 HigginsSoft, Alexander Higgins - https://github.com/alexhiggins732/
Copyright (c) 2018, Brock Allen & Dominick Baier. All rights reserved.
Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
Source code and license this software can be found
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Runtime.InteropServices;
using Xunit;
namespace IdentityServer8.EntityFramework.IntegrationTests;
/// <summary>
/// Base class for integration tests, responsible for initializing test database providers & an xUnit class fixture
/// </summary>
/// <typeparam name="TClass">The type of the class.</typeparam>
/// <typeparam name="TDbContext">The type of the database context.</typeparam>
/// <typeparam name="TStoreOption">The type of the store option.</typeparam>
/// <seealso cref="DatabaseProviderFixture{T}" />
public class IntegrationTest<TClass, TDbContext, TStoreOption> : IClassFixture<DatabaseProviderFixture<TDbContext>>
where TDbContext : DbContext
{
public static readonly TheoryData<DbContextOptions<TDbContext>> TestDatabaseProviders;
protected readonly TStoreOption StoreOptions = Activator.CreateInstance<TStoreOption>();
static IntegrationTest()
{
var config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine($"Running Local Tests for {typeof(TClass).Name}");
TestDatabaseProviders = new TheoryData<DbContextOptions<TDbContext>>
{
DatabaseProviderBuilder.BuildInMemory<TDbContext>(typeof(TClass).Name),
//DatabaseProviderBuilder.BuildSqlite<TDbContext>(typeof(TClass).Name),
//DatabaseProviderBuilder.BuildLocalDb<TDbContext>(typeof(TClass).Name)
};
}
else
{
TestDatabaseProviders = new TheoryData<DbContextOptions<TDbContext>>
{
DatabaseProviderBuilder.BuildInMemory<TDbContext>(typeof(TClass).Name),
DatabaseProviderBuilder.BuildSqlite<TDbContext>(typeof(TClass).Name)
};
Console.WriteLine("Skipping DB integration tests on non-Windows");
}
}
protected IntegrationTest(DatabaseProviderFixture<TDbContext> fixture)
{
fixture.Options = (TestDatabaseProviders as IEnumerable<DbContextOptions<TDbContext>>).ToList();
fixture.StoreOptions = StoreOptions;
}
}