forked from SimonCropp/LocalDb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEfSnippetTests.cs
61 lines (53 loc) · 1.4 KB
/
EfSnippetTests.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
51
52
53
54
55
56
57
58
59
60
61
using System.Threading.Tasks;
using EfLocalDb;
using Xunit;
public class EfSnippetTests
{
static SqlInstance<MyDbContext> sqlInstance;
static EfSnippetTests()
{
sqlInstance = new SqlInstance<MyDbContext>(
builder => new MyDbContext(builder.Options));
}
#region EfTest
[Fact]
public async Task TheTest()
{
#region EfBuildDatabase
using (var database = await sqlInstance.Build())
{
#endregion
#region EfBuildContext
using (var dbContext = database.NewDbContext())
{
#endregion
var entity = new TheEntity
{
Property = "prop"
};
dbContext.Add(entity);
dbContext.SaveChanges();
}
using (var dbContext = database.NewDbContext())
{
Assert.Single(dbContext.TestEntities);
}
}
}
#endregion
[Fact]
public async Task TheTestWithDbName()
{
#region EfWithDbName
using (var database = await sqlInstance.Build("TheTestWithDbName"))
{
#endregion
var entity = new TheEntity
{
Property = "prop"
};
await database.AddData(entity);
Assert.Single(database.Context.TestEntities);
}
}
}