-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathLocalDbTestBase.cs
More file actions
33 lines (27 loc) · 927 Bytes
/
LocalDbTestBase.cs
File metadata and controls
33 lines (27 loc) · 927 Bytes
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
[TestFixture]
public abstract class LocalDbTestBase
{
static SqlInstance<SampleDbContext> sqlInstance;
static LocalDbTestBase() =>
sqlInstance = new(
constructInstance: builder =>
{
builder.EnableRecording();
return new(builder.Options);
},
storage: Storage.FromSuffix<SampleDbContext>("ef"));
public Task<SqlDatabase<SampleDbContext>> LocalDb(string? testSuffix = null) =>
sqlInstance.Build(testFile, null, GetName(testSuffix));
static string GetName(string? testSuffix)
{
var test = TestContext.CurrentContext.Test;
if (testSuffix == null)
{
return test.MethodName!;
}
return $"{test.MethodName}_{testSuffix}";
}
string testFile;
protected LocalDbTestBase([CallerFilePath] string sourceFile = "") =>
testFile = GetType().Name;
}