Skip to content

Commit a2d76d5

Browse files
committed
add tests
1 parent 6d66fe4 commit a2d76d5

11 files changed

Lines changed: 242 additions & 0 deletions

end2end/EndToEndScaffold/Config.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum KnownTestType
2929
// Sqlite
3030
SqliteDataTypes,
3131
SqliteCopyFrom,
32+
SqliteTransaction,
3233

3334
// Postgres
3435
PostgresStringDataTypes,
@@ -38,6 +39,7 @@ public enum KnownTestType
3839
PostgresArrayDataTypes,
3940

4041
PostgresStringCopyFrom,
42+
PostgresTransaction,
4143
PostgresIntegerCopyFrom,
4244
PostgresFloatingPointCopyFrom,
4345
PostgresDateTimeCopyFrom,
@@ -160,6 +162,7 @@ internal static class Config
160162
KnownTestType.NargNull,
161163
KnownTestType.NargNotNull,
162164

165+
KnownTestType.PostgresTransaction,
163166
KnownTestType.PostgresStringDataTypes,
164167
KnownTestType.PostgresIntegerDataTypes,
165168
KnownTestType.PostgresFloatingPointDataTypes,
@@ -192,6 +195,7 @@ internal static class Config
192195
KnownTestType.MultipleArraysAsParams,
193196
KnownTestType.NargNull,
194197
KnownTestType.NargNotNull,
198+
KnownTestType.PostgresTransaction,
195199

196200
KnownTestType.PostgresStringDataTypes,
197201
KnownTestType.PostgresIntegerDataTypes,
@@ -225,6 +229,7 @@ internal static class Config
225229
KnownTestType.MultipleSlices,
226230
KnownTestType.NargNull,
227231
KnownTestType.NargNotNull,
232+
KnownTestType.SqliteTransaction,
228233
KnownTestType.SqliteDataTypes,
229234
KnownTestType.SqliteCopyFrom
230235
]
@@ -247,6 +252,7 @@ internal static class Config
247252
KnownTestType.MultipleSlices,
248253
KnownTestType.NargNull,
249254
KnownTestType.NargNotNull,
255+
KnownTestType.SqliteTransaction,
250256
KnownTestType.SqliteDataTypes,
251257
KnownTestType.SqliteCopyFrom
252258
]

end2end/EndToEndScaffold/Templates/PostgresTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,36 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
484484
}
485485
"""
486486
},
487+
[KnownTestType.PostgresTransaction] = new TestImpl
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
514+
}
515+
"""
516+
},
487517

488518
};
489519
}

end2end/EndToEndScaffold/Templates/SqliteTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,35 @@ private static void AssertSingularEquals(QuerySql.GetSqliteTypesAggRow expected,
8989
}
9090
"""
9191
},
92+
[KnownTestType.SqliteTransaction] = new TestImpl
93+
{
94+
Impl = $$"""
95+
[Test]
96+
public async Task TestSqliteTransaction()
97+
{
98+
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
119+
}
120+
"""
121+
},
92122
};
93123
}

end2end/EndToEndTests/NpgsqlDapperTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha
412412
Assert.That(actual.CText, Is.EqualTo(expected.CText));
413413
}
414414

415+
[Test]
416+
public async Task TestPostgresTransaction()
417+
{
418+
var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv));
419+
await connection.OpenAsync();
420+
var transaction = connection.BeginTransaction();
421+
var sqlQueryWithTx = new QuerySql(transaction);
422+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
423+
// The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct)
424+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
425+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
426+
await transaction.CommitAsync();
427+
var expected = new QuerySql.GetAuthorRow
428+
{
429+
Id = 1111,
430+
Name = "Bojack Horseman",
431+
Bio = "Back in the 90s he was in a very famous TV show"
432+
};
433+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
434+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
435+
}
436+
415437
[Test]
416438
[TestCase(100, true, 3, 453, -1445214231L)]
417439
[TestCase(10, null, null, null, null)]

end2end/EndToEndTests/NpgsqlTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha
412412
Assert.That(actual.Value.CText, Is.EqualTo(expected.CText));
413413
}
414414

415+
[Test]
416+
public async Task TestPostgresTransaction()
417+
{
418+
var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv));
419+
await connection.OpenAsync();
420+
var transaction = connection.BeginTransaction();
421+
var sqlQueryWithTx = new QuerySql(transaction);
422+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
423+
// The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct)
424+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
425+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
426+
await transaction.CommitAsync();
427+
var expected = new QuerySql.GetAuthorRow
428+
{
429+
Id = 1111,
430+
Name = "Bojack Horseman",
431+
Bio = "Back in the 90s he was in a very famous TV show"
432+
};
433+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
434+
Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here
435+
}
436+
415437
[Test]
416438
[TestCase(100, true, 3, 453, -1445214231L)]
417439
[TestCase(10, null, null, null, null)]

end2end/EndToEndTests/SqliteDapperTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,27 @@ private static void AssertSingularEquals(QuerySql.GetSqliteTypesAggRow expected,
357357
Assert.That(actual.CReal, Is.EqualTo(expected.CReal));
358358
Assert.That(actual.CText, Is.EqualTo(expected.CText));
359359
}
360+
361+
[Test]
362+
public async Task TestSqliteTransaction()
363+
{
364+
var connection = new Microsoft.Data.Sqlite.SqliteConnection(Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv));
365+
await connection.OpenAsync();
366+
var transaction = connection.BeginTransaction();
367+
var sqlQueryWithTx = new QuerySql(transaction);
368+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
369+
// The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class)
370+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
371+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
372+
await transaction.CommitAsync();
373+
var expected = new QuerySql.GetAuthorRow
374+
{
375+
Id = 1111,
376+
Name = "Bojack Horseman",
377+
Bio = "Back in the 90s he was in a very famous TV show"
378+
};
379+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
380+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
381+
}
360382
}
361383
}

end2end/EndToEndTests/SqliteTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,27 @@ private static void AssertSingularEquals(QuerySql.GetSqliteTypesAggRow expected,
357357
Assert.That(actual.CReal, Is.EqualTo(expected.CReal));
358358
Assert.That(actual.CText, Is.EqualTo(expected.CText));
359359
}
360+
361+
[Test]
362+
public async Task TestSqliteTransaction()
363+
{
364+
var connection = new Microsoft.Data.Sqlite.SqliteConnection(Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv));
365+
await connection.OpenAsync();
366+
var transaction = connection.BeginTransaction();
367+
var sqlQueryWithTx = new QuerySql(transaction);
368+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
369+
// The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class)
370+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
371+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
372+
await transaction.CommitAsync();
373+
var expected = new QuerySql.GetAuthorRow
374+
{
375+
Id = 1111,
376+
Name = "Bojack Horseman",
377+
Bio = "Back in the 90s he was in a very famous TV show"
378+
};
379+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
380+
Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here
381+
}
360382
}
361383
}

end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha
412412
Assert.That(actual.CText, Is.EqualTo(expected.CText));
413413
}
414414

415+
[Test]
416+
public async Task TestPostgresTransaction()
417+
{
418+
var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv));
419+
await connection.OpenAsync();
420+
var transaction = connection.BeginTransaction();
421+
var sqlQueryWithTx = new QuerySql(transaction);
422+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
423+
// The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct)
424+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
425+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
426+
await transaction.CommitAsync();
427+
var expected = new QuerySql.GetAuthorRow
428+
{
429+
Id = 1111,
430+
Name = "Bojack Horseman",
431+
Bio = "Back in the 90s he was in a very famous TV show"
432+
};
433+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
434+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
435+
}
436+
415437
[Test]
416438
[TestCase(100, true, 3, 453, -1445214231L)]
417439
[TestCase(10, null, null, null, null)]

end2end/EndToEndTestsLegacy/NpgsqlTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ public async Task TestStringCopyFrom(int batchSize, string cChar, string cVarcha
412412
Assert.That(actual.CText, Is.EqualTo(expected.CText));
413413
}
414414

415+
[Test]
416+
public async Task TestPostgresTransaction()
417+
{
418+
var connection = new Npgsql.NpgsqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.PostgresConnectionStringEnv));
419+
await connection.OpenAsync();
420+
var transaction = connection.BeginTransaction();
421+
var sqlQueryWithTx = new QuerySql(transaction);
422+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
423+
// The GetAuthor method in NpgsqlExampleGen returns QuerySql.GetAuthorRow? (nullable record struct)
424+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
425+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
426+
await transaction.CommitAsync();
427+
var expected = new QuerySql.GetAuthorRow
428+
{
429+
Id = 1111,
430+
Name = "Bojack Horseman",
431+
Bio = "Back in the 90s he was in a very famous TV show"
432+
};
433+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
434+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
435+
}
436+
415437
[Test]
416438
[TestCase(100, true, 3, 453, -1445214231L)]
417439
[TestCase(10, null, null, null, null)]

end2end/EndToEndTestsLegacy/SqliteDapperTester.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,27 @@ private static void AssertSingularEquals(QuerySql.GetSqliteTypesAggRow expected,
357357
Assert.That(actual.CReal, Is.EqualTo(expected.CReal));
358358
Assert.That(actual.CText, Is.EqualTo(expected.CText));
359359
}
360+
361+
[Test]
362+
public async Task TestSqliteTransaction()
363+
{
364+
var connection = new Microsoft.Data.Sqlite.SqliteConnection(Environment.GetEnvironmentVariable(EndToEndCommon.SqliteConnectionStringEnv));
365+
await connection.OpenAsync();
366+
var transaction = connection.BeginTransaction();
367+
var sqlQueryWithTx = new QuerySql(transaction);
368+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
369+
// The GetAuthor method in SqliteExampleGen returns QuerySql.GetAuthorRow? (nullable record struct/class)
370+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
371+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
372+
await transaction.CommitAsync();
373+
var expected = new QuerySql.GetAuthorRow
374+
{
375+
Id = 1111,
376+
Name = "Bojack Horseman",
377+
Bio = "Back in the 90s he was in a very famous TV show"
378+
};
379+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
380+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
381+
}
360382
}
361383
}

0 commit comments

Comments
 (0)