-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathEfClassicTestBaseUsage.cs
More file actions
47 lines (39 loc) · 1.25 KB
/
EfClassicTestBaseUsage.cs
File metadata and controls
47 lines (39 loc) · 1.25 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
public class EfClassicTestBase
{
public class TheDbContext(SqlConnection connection) :
DbContext(connection, false)
{
public DbSet<TheEntity> TestEntities { get; set; } = null!;
protected override void OnModelCreating(DbModelBuilder model) => model.Entity<TheEntity>();
}
#region EfClassicTestBase
[TestFixture]
public abstract class TestBase
{
static SqlInstance<TheDbContext> sqlInstance;
static TestBase() =>
sqlInstance = new(
constructInstance: connection => new(connection));
public static Task<SqlDatabase<TheDbContext>> LocalDb(
[CallerFilePath] string testFile = "",
string? databaseSuffix = null,
[CallerMemberName] string memberName = "") =>
sqlInstance.Build(testFile, databaseSuffix, memberName);
}
public class Tests :
TestBase
{
[Test]
public async Task Test()
{
using var database = await LocalDb();
var entity = new TheEntity
{
Property = "prop"
};
await database.AddData(entity);
AreEqual(1, database.Context.TestEntities.Count());
}
}
#endregion
}