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

Commit cbf0e6c

Browse files
committed
Add test for ModelWithRowVersionAlias
1 parent 877ca8d commit cbf0e6c

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

tests/ServiceStack.OrmLite.Tests/RowVersionTests.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ public class ModelWithRowVersion
1717
public ulong RowVersion { get; set; }
1818
}
1919

20-
public class RowVersionTests : OrmLiteTestBase
20+
public class ModelWithRowVersionAlias
2121
{
22-
public RowVersionTests()
23-
{
24-
//Dialect = Dialect.Sqlite;
25-
}
22+
[AutoIncrement]
23+
public long Id { get; set; }
24+
25+
public string Text { get; set; }
26+
27+
[Alias("VersionAlias")]
28+
public ulong RowVersion { get; set; }
29+
}
2630

31+
public class RowVersionTests : OrmLiteTestBase
32+
{
2733
private IDbConnection db;
2834

2935
[TestFixtureSetUp]
3036
public void FixtureSetUp()
3137
{
38+
//Dialect = Dialect.SqlServer;
39+
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
3240
using (var dbConn = OpenDbConnection())
3341
{
3442
dbConn.DropAndCreateTable<ModelWithRowVersion>();
@@ -76,6 +84,35 @@ public void Can_create_table_with_RowVersion()
7684
db.Update(updatedRow);
7785
}
7886

87+
[Test]
88+
public void Can_create_table_with_RowVersion_Alias()
89+
{
90+
db.DropAndCreateTable<ModelWithRowVersionAlias>();
91+
92+
db.Insert(new ModelWithRowVersionAlias { Text = "Text" });
93+
94+
var row = db.SingleById<ModelWithRowVersionAlias>(1);
95+
96+
row.Text += " Updated";
97+
98+
db.Update(row);
99+
100+
var updatedRow = db.SingleById<ModelWithRowVersionAlias>(1);
101+
102+
Assert.That(updatedRow.Text, Is.EqualTo("Text Updated"));
103+
Assert.That(updatedRow.RowVersion, Is.GreaterThan(0));
104+
105+
row.Text += " Again";
106+
107+
//Can't update old record
108+
Assert.Throws<RowModifiedException>(() =>
109+
db.Update(row));
110+
111+
//Can update latest version
112+
updatedRow.Text += " Again";
113+
db.Update(updatedRow);
114+
}
115+
79116
[Test]
80117
public void Select_retrieves_rowversion()
81118
{

0 commit comments

Comments
 (0)