You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: end2end/EndToEndScaffold/Templates/PostgresTests.cs
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -484,6 +484,36 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
484
484
}
485
485
"""
486
486
},
487
+
[KnownTestType.PostgresTransaction]=newTestImpl
488
+
{
489
+
Impl=$$"""
490
+
[Test]
491
+
public async Task TestPostgresTransaction()
492
+
{
493
+
var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv));
494
+
await connection.OpenAsync();
495
+
var transaction = connection.BeginTransaction();
496
+
497
+
var sqlQueryWithTx = new QuerySql(transaction);
498
+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
499
+
500
+
// The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct)
501
+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
502
+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
503
+
504
+
await transaction.CommitAsync();
505
+
506
+
var expected = new QuerySql.GetAuthorRow
507
+
{
508
+
Id = 1111,
509
+
Name = "Bojack Horseman",
510
+
Bio = "Back in the 90s he was in a very famous TV show"
511
+
};
512
+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
513
+
Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here
var connection = new Microsoft.Data.Sqlite.SqliteConnection(Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv));
99
+
await connection.OpenAsync();
100
+
var transaction = connection.BeginTransaction();
101
+
102
+
var sqlQueryWithTx = new QuerySql(transaction);
103
+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
104
+
105
+
// The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class)
106
+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
107
+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
108
+
109
+
await transaction.CommitAsync();
110
+
111
+
var expected = new QuerySql.GetAuthorRow
112
+
{
113
+
Id = 1111,
114
+
Name = "Bojack Horseman",
115
+
Bio = "Back in the 90s he was in a very famous TV show"
116
+
};
117
+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
118
+
Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here
0 commit comments