-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlServerDatabaseInitializerTest.cs
70 lines (52 loc) · 2.88 KB
/
SqlServerDatabaseInitializerTest.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
62
63
64
65
66
67
68
69
70
//-----------------------------------------------------------------------
// <copyright file="SqlServerDatabaseInitializerTest.cs" company="P.O.S Informatique">
// Copyright (c) P.O.S Informatique. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace PosInformatique.Testing.Databases.SqlServer.Tests
{
[Collection("PosInformatique.Testing.Databases.SqlServer.Tests")]
public class SqlServerDatabaseInitializerTest : IClassFixture<SqlServerDatabaseInitializer>
{
private const string ConnectionString = $"Data Source=(localDB)\\posinfo-tests; Initial Catalog={nameof(SqlServerDatabaseInitializerTest)}; Integrated Security=True";
private readonly SqlServerDatabase database;
public SqlServerDatabaseInitializerTest(SqlServerDatabaseInitializer initializer)
{
this.database = initializer.Initialize("Testing.Databases.SqlServer.Tests.DacPac.dacpac", ConnectionString);
var table = this.database.ExecuteQuery("SELECT * FROM MyTable");
table.Rows.Should().BeEmpty();
this.database.InsertInto("MyTable", new { Id = 1, Name = "Name 1" });
this.database.InsertInto("MyTable", new { Id = 2, Name = "Name 2" });
}
[Fact]
public void Test1()
{
var currentUser = this.database.ExecuteQuery("SELECT SUSER_NAME()");
currentUser.Rows[0][0].Should().Be($"{Environment.UserDomainName}\\{Environment.UserName}");
// Check the constructor has been called
var table = this.database.ExecuteQuery("SELECT * FROM MyTable");
table.Rows.Should().HaveCount(2);
table.Rows[0]["Id"].Should().Be(1);
table.Rows[0]["Name"].Should().Be("Name 1");
table.Rows[1]["Id"].Should().Be(2);
table.Rows[1]["Name"].Should().Be("Name 2");
// Insert a row which should not be use in other tests.
this.database.InsertInto("MyTable", new { Id = 99, Name = "Should not be here for the next test" });
}
[Fact]
public void Test2()
{
var currentUser = this.database.ExecuteQuery("SELECT SUSER_NAME()");
currentUser.Rows[0][0].Should().Be($"{Environment.UserDomainName}\\{Environment.UserName}");
// Check the constructor has been called
var table = this.database.ExecuteQuery("SELECT * FROM MyTable");
table.Rows.Should().HaveCount(2);
table.Rows[0]["Id"].Should().Be(1);
table.Rows[0]["Name"].Should().Be("Name 1");
table.Rows[1]["Id"].Should().Be(2);
table.Rows[1]["Name"].Should().Be("Name 2");
// Insert a row which should not be use in other tests.
this.database.InsertInto("MyTable", new { Id = 99, Name = "Should not be here for the next test" });
}
}
}