Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit ba997a6

Browse files
committed
Add async tests for [AutoId]
1 parent bc2e87f commit ba997a6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/ServiceStack.OrmLite.Tests/AutoIdTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using NUnit.Framework;
34
using ServiceStack.DataAnnotations;
45

@@ -43,6 +44,31 @@ public void Does_populate_and_return_new_guid_on_insert()
4344
}
4445
}
4546

47+
[Test]
48+
public async Task Does_populate_and_return_new_guid_on_insert_Async()
49+
{
50+
using (var db = OpenDbConnection())
51+
{
52+
db.DropAndCreateTable<GuidAutoId>();
53+
54+
var guidA = new GuidAutoId { Name = "A" };
55+
var guidB = new GuidAutoId { Name = "B" };
56+
57+
await db.InsertAsync(guidA);
58+
await db.InsertAsync(guidB);
59+
60+
Assert.That(guidA.Id, Is.Not.EqualTo(new Guid()));
61+
Assert.That(guidB.Id, Is.Not.EqualTo(new Guid()));
62+
Assert.That(guidA.Id, Is.Not.EqualTo(guidB));
63+
64+
var dbA = await db.SingleByIdAsync<GuidAutoId>(guidA.Id);
65+
Assert.That(dbA.Name, Is.EqualTo(guidA.Name));
66+
67+
var dbB = await db.SingleByIdAsync<GuidAutoId>(guidB.Id);
68+
Assert.That(dbB.Name, Is.EqualTo(guidB.Name));
69+
}
70+
}
71+
4672
[Test]
4773
public void Does_populate_and_return_new_guid_on_save()
4874
{
@@ -68,6 +94,31 @@ public void Does_populate_and_return_new_guid_on_save()
6894
}
6995
}
7096

97+
[Test]
98+
public async Task Does_populate_and_return_new_guid_on_save_Async()
99+
{
100+
using (var db = OpenDbConnection())
101+
{
102+
db.DropAndCreateTable<GuidAutoId>();
103+
104+
var guidA = new GuidAutoId { Name = "A" };
105+
var guidB = new GuidAutoId { Name = "B" };
106+
107+
await db.SaveAsync(guidA);
108+
await db.SaveAsync(guidB);
109+
110+
Assert.That(guidA.Id, Is.Not.EqualTo(new Guid()));
111+
Assert.That(guidB.Id, Is.Not.EqualTo(new Guid()));
112+
Assert.That(guidA.Id, Is.Not.EqualTo(guidB));
113+
114+
var dbA = await db.SingleByIdAsync<GuidAutoId>(guidA.Id);
115+
Assert.That(dbA.Name, Is.EqualTo(guidA.Name));
116+
117+
var dbB = await db.SingleByIdAsync<GuidAutoId>(guidB.Id);
118+
Assert.That(dbB.Name, Is.EqualTo(guidB.Name));
119+
}
120+
}
121+
71122
[Test]
72123
public void Uses_existing_Guid_Id_if_not_Empty()
73124
{

0 commit comments

Comments
 (0)