-
Notifications
You must be signed in to change notification settings - Fork 11
/
SqliteBridgeTests.cs
61 lines (49 loc) · 1.82 KB
/
SqliteBridgeTests.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;
using Microsoft.Data.Sqlite;
using Xunit;
using FluentAssertions;
using Korzh.DbUtils.Tests;
using System.Collections.Generic;
namespace Korzh.DbUtils.Sqlite.Tests
{
public class SqliteBridgeTests
{
[Fact]
public void SeedDataBaseTest_MustFillDataBase()
{
var connection = new SqliteConnection("Data Source=:memory:;");
connection.DefaultTimeout = 100;
connection.Open();
//create in-memory test db
using (var command = connection.CreateCommand()) {
command.CommandText = TestUtils.GetResourceAsString(typeof(SqliteBridgeTests).Assembly, "Resources", "db.sql");
command.ExecuteNonQuery();
}
DbInitializer.Create(options => {
options.UseSqlite(connection);
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 tableCount in tableCounts) {
using (var command = connection.CreateCommand())
{
command.CommandText = $"SELECT COUNT(*) FROM {tableCount.Key};";
var count = (long)command.ExecuteScalar();
count.Should().Be(tableCount.Value, "Wrong number records in {0} table.", tableCount.Key);
}
}
}
}
}