forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntitiesTests.DatabaseFixture.cs
More file actions
45 lines (37 loc) · 1.14 KB
/
EntitiesTests.DatabaseFixture.cs
File metadata and controls
45 lines (37 loc) · 1.14 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
using System.Threading.Tasks;
using Testcontainers.MsSql;
using Xunit;
namespace System.Linq.Dynamic.Core.Tests;
/// <summary>
/// https://blog.jetbrains.com/dotnet/2023/10/24/how-to-use-testcontainers-with-dotnet-unit-tests/
/// </summary>
public class EntitiesTestsDatabaseFixture : IAsyncLifetime
{
// https://github.com/microsoft/mssql-docker/issues/892
private readonly Lazy<MsSqlContainer> _msSqlContainer = new(() => new MsSqlBuilder().WithImage("mcr.microsoft.com/mssql/server:2022-latest").Build());
public string ConnectionString => _msSqlContainer.Value.GetConnectionString();
public bool UseInMemory
{
get
{
var useInMemory = Environment.GetEnvironmentVariable("UseInMemory");
return bool.TryParse(useInMemory, out var value) && value;
}
}
public async Task InitializeAsync()
{
if (UseInMemory)
{
return;
}
await _msSqlContainer.Value.StartAsync();
}
public async Task DisposeAsync()
{
if (UseInMemory)
{
return;
}
await _msSqlContainer.Value.DisposeAsync();
}
}