-
Notifications
You must be signed in to change notification settings - Fork 11
/
DbContextBridgeTests.cs
53 lines (43 loc) · 1.58 KB
/
DbContextBridgeTests.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
using System;
using System.Linq;
using System.Collections.Generic;
using Xunit;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Korzh.DbUtils.Tests;
namespace Korzh.DbUtils.EntityFrameworkCore.InMemory.Tests
{
public class DbContextBridgeTests
{
[Fact]
public void SeedDataBaseTest_MustFillDataBase()
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseInMemoryDatabase("test-db");
var dbContext = new AppDbContext(optionsBuilder.Options);
DbInitializer.Create(options => {
options.UseInMemoryDatabase(dbContext);
options.UseJsonImporter();
options.UseResourceFileUnpacker(typeof(TestUtils).Assembly, "Resources\\Nwind");
})
.Seed();
var tableCounts = new Dictionary<string, int>()
{
["Categories"] = 8,
["Customers"] = 91,
["Employees"] = 9,
["Products"] = 77,
["Orders"] = 830,
["Order_Details"] = 2155,
["Suppliers"] = 29,
["Shippers"] = 3
};
foreach (var entityType in dbContext.Model.GetEntityTypes()) {
var tableName = entityType.GetTableName();
var count = tableCounts[tableName];
var realCount = dbContext.Set(entityType.ClrType).Count();
realCount.Should().Be(count, "Wrong number records in {0} table.", tableName);
}
}
}
}