-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIntegration.cs
78 lines (65 loc) · 1.92 KB
/
Integration.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
71
72
73
74
75
76
77
78
using Dapper;
using System.Data;
using Testing.Data.Entities;
namespace Testing.SqlServer;
[TestClass]
public class Integration : IntegrationBase
{
[TestMethod]
public async Task InsertUpdateDelete()
{
var db = GetDatabase();
using var cn = db.GetConnection();
await TestInternalAsync(db, cn);
}
[TestMethod]
public async Task UpdateSpecificColumns()
{
var db = GetDatabase();
using var cn = db.GetConnection();
await cn.ExecuteAsync("DELETE [dbo].[Business] WHERE [UserId] = 'hello1121'");
var biz = await db.Business.SaveAsync(new()
{
UserId = "hello1121",
DisplayName = "anything",
MailingAddress = "3983 Axelrod",
PhoneNumber = "294-2322",
Email = "[email protected]"
});
await db.Business.UpdateAsync(biz.Id, row =>
{
row.PhoneNumber = "123-4567";
row.MailingAddress = null;
});
biz = await db.Business.GetAsync(biz.Id) ?? throw new Exception("row not found");
Assert.AreEqual(biz.PhoneNumber, "123-4567");
Assert.IsTrue(biz.MailingAddress is null);
}
private static async Task TestInternalAsync(LiteInvoiceDatabase db, IDbConnection cn, IDbTransaction? txn = null)
{
var result = await db.Business.SaveAsync(cn, new()
{
UserId = "hello",
DisplayName = "anything",
MailingAddress = "3983 Axelrod",
PhoneNumber = "294-2322",
Email = "[email protected]"
}, txn);
Assert.IsTrue(result.Id != 0);
Assert.IsTrue(result.UserId.Equals("hello"));
result.UserId = "someoneelse";
await db.Business.SaveAsync(cn, result, txn);
result = await db.Business.GetAsync(cn, result.Id, txn) ?? throw new Exception("row not found");
Assert.IsTrue(result.UserId.Equals("someoneelse"));
await db.Business.DeleteAsync(cn, new Business() { Id = result.Id }, txn);
}
[TestMethod]
public async Task InsertUpdateDeleteWithTxn()
{
var db = GetDatabase();
await db.DoTransactionAsync(async (cn, txn) =>
{
await TestInternalAsync(db, cn, txn);
});
}
}