Skip to content

Commit 5408f9b

Browse files
committed
add test for mysql
1 parent d907217 commit 5408f9b

6 files changed

Lines changed: 136 additions & 0 deletions

File tree

end2end/EndToEndScaffold/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum KnownTestType
5050
// MySql
5151
MySqlStringDataTypes,
5252
MySqlIntegerDataTypes,
53+
MySqlTransaction,
5354
MySqlFloatingPointDataTypes,
5455
MySqlDateTimeDataTypes,
5556
MySqlBinaryDataTypes,
@@ -89,6 +90,7 @@ internal static class Config
8990

9091
KnownTestType.MySqlStringDataTypes,
9192
KnownTestType.MySqlIntegerDataTypes,
93+
KnownTestType.MySqlTransaction,
9294
KnownTestType.MySqlFloatingPointDataTypes,
9395
KnownTestType.MySqlDateTimeDataTypes,
9496
KnownTestType.MySqlBinaryDataTypes,
@@ -124,6 +126,7 @@ internal static class Config
124126

125127
KnownTestType.MySqlStringDataTypes,
126128
KnownTestType.MySqlIntegerDataTypes,
129+
KnownTestType.MySqlTransaction,
127130
KnownTestType.MySqlFloatingPointDataTypes,
128131
KnownTestType.MySqlDateTimeDataTypes,
129132
KnownTestType.MySqlBinaryDataTypes,

end2end/EndToEndScaffold/Templates/MySqlTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,39 @@ public async Task TestBinaryCopyFrom(
523523
}
524524
"""
525525
},
526+
[KnownTestType.MySqlTransaction] = new TestImpl
527+
{
528+
Impl = $$"""
529+
[Test]
530+
public async Task TestMySqlTransaction()
531+
{
532+
var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)!);
533+
await connection.OpenAsync();
534+
var transaction = connection.BeginTransaction();
535+
536+
var sqlQueryWithTx = new QuerySql(transaction);
537+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
538+
539+
// The GetAuthor method in MySqlConnectorExampleGen (non-Dapper) returns QuerySql.GetAuthorRow (non-nullable struct/record)
540+
// if it were a non-nullable struct/record, actualNull == null would always be false.
541+
// However, MySqlConnectorTester.generated.cs uses actual.Value, implying it's nullable.
542+
// Let's assume QuerySql.GetAuthor returns QuerySql.GetAuthorRow? (nullable record struct) for MySqlConnectorExampleGen.
543+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
544+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
545+
546+
await transaction.CommitAsync();
547+
548+
var expected = new QuerySql.GetAuthorRow
549+
{
550+
Id = 1111,
551+
Name = "Bojack Horseman",
552+
Bio = "Back in the 90s he was in a very famous TV show"
553+
};
554+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
555+
Assert.That(SingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}})); // Apply placeholder here
556+
}
557+
"""
558+
},
526559
[KnownTestType.MySqlEnumCopyFrom] = new TestImpl
527560
{
528561
Impl = $$"""

end2end/EndToEndTests/MySqlConnectorDapperTester.generated.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,31 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin
361361
Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint));
362362
}
363363

364+
[Test]
365+
public async Task TestMySqlTransaction()
366+
{
367+
var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)!);
368+
await connection.OpenAsync();
369+
var transaction = connection.BeginTransaction();
370+
var sqlQueryWithTx = new QuerySql(transaction);
371+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
372+
// The GetAuthor method in MySqlConnectorExampleGen (non-Dapper) returns QuerySql.GetAuthorRow (non-nullable struct/record)
373+
// if it were a non-nullable struct/record, actualNull == null would always be false.
374+
// However, MySqlConnectorTester.generated.cs uses actual.Value, implying it's nullable.
375+
// Let's assume QuerySql.GetAuthor returns QuerySql.GetAuthorRow? (nullable record struct) for MySqlConnectorExampleGen.
376+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
377+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
378+
await transaction.CommitAsync();
379+
var expected = new QuerySql.GetAuthorRow
380+
{
381+
Id = 1111,
382+
Name = "Bojack Horseman",
383+
Bio = "Back in the 90s he was in a very famous TV show"
384+
};
385+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
386+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
387+
}
388+
364389
[Test]
365390
[TestCase(3.4f, -31.555666, 11.098643, 34.4424, 423.2445, 998.9994542, 21.214312452534)]
366391
[TestCase(null, null, null, null, null, null, null)]

end2end/EndToEndTests/MySqlConnectorTester.generated.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,31 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin
361361
Assert.That(actual.Value.CBigint, Is.EqualTo(expected.CBigint));
362362
}
363363

364+
[Test]
365+
public async Task TestMySqlTransaction()
366+
{
367+
var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)!);
368+
await connection.OpenAsync();
369+
var transaction = connection.BeginTransaction();
370+
var sqlQueryWithTx = new QuerySql(transaction);
371+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
372+
// The GetAuthor method in MySqlConnectorExampleGen (non-Dapper) returns QuerySql.GetAuthorRow (non-nullable struct/record)
373+
// if it were a non-nullable struct/record, actualNull == null would always be false.
374+
// However, MySqlConnectorTester.generated.cs uses actual.Value, implying it's nullable.
375+
// Let's assume QuerySql.GetAuthor returns QuerySql.GetAuthorRow? (nullable record struct) for MySqlConnectorExampleGen.
376+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
377+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
378+
await transaction.CommitAsync();
379+
var expected = new QuerySql.GetAuthorRow
380+
{
381+
Id = 1111,
382+
Name = "Bojack Horseman",
383+
Bio = "Back in the 90s he was in a very famous TV show"
384+
};
385+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
386+
Assert.That(SingularEquals(expected, actual.Value)); // Apply placeholder here
387+
}
388+
364389
[Test]
365390
[TestCase(3.4f, -31.555666, 11.098643, 34.4424, 423.2445, 998.9994542, 21.214312452534)]
366391
[TestCase(null, null, null, null, null, null, null)]

end2end/EndToEndTestsLegacy/MySqlConnectorDapperTester.generated.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,31 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin
361361
Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint));
362362
}
363363

364+
[Test]
365+
public async Task TestMySqlTransaction()
366+
{
367+
var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)!);
368+
await connection.OpenAsync();
369+
var transaction = connection.BeginTransaction();
370+
var sqlQueryWithTx = new QuerySql(transaction);
371+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
372+
// The GetAuthor method in MySqlConnectorExampleGen (non-Dapper) returns QuerySql.GetAuthorRow (non-nullable struct/record)
373+
// if it were a non-nullable struct/record, actualNull == null would always be false.
374+
// However, MySqlConnectorTester.generated.cs uses actual.Value, implying it's nullable.
375+
// Let's assume QuerySql.GetAuthor returns QuerySql.GetAuthorRow? (nullable record struct) for MySqlConnectorExampleGen.
376+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
377+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
378+
await transaction.CommitAsync();
379+
var expected = new QuerySql.GetAuthorRow
380+
{
381+
Id = 1111,
382+
Name = "Bojack Horseman",
383+
Bio = "Back in the 90s he was in a very famous TV show"
384+
};
385+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
386+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
387+
}
388+
364389
[Test]
365390
[TestCase(3.4f, -31.555666, 11.098643, 34.4424, 423.2445, 998.9994542, 21.214312452534)]
366391
[TestCase(null, null, null, null, null, null, null)]

end2end/EndToEndTestsLegacy/MySqlConnectorTester.generated.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,31 @@ public async Task TestMySqlIntegerTypes(bool? cBool, bool? cBoolean, short? cTin
361361
Assert.That(actual.CBigint, Is.EqualTo(expected.CBigint));
362362
}
363363

364+
[Test]
365+
public async Task TestMySqlTransaction()
366+
{
367+
var connection = new MySqlConnector.MySqlConnection(Environment.GetEnvironmentVariable(EndToEndCommon.MySqlConnectionStringEnv)!);
368+
await connection.OpenAsync();
369+
var transaction = connection.BeginTransaction();
370+
var sqlQueryWithTx = new QuerySql(transaction);
371+
await sqlQueryWithTx.CreateAuthor(new QuerySql.CreateAuthorArgs { Id = 1111, Name = "Bojack Horseman", Bio = "Back in the 90s he was in a very famous TV show" });
372+
// The GetAuthor method in MySqlConnectorExampleGen (non-Dapper) returns QuerySql.GetAuthorRow (non-nullable struct/record)
373+
// if it were a non-nullable struct/record, actualNull == null would always be false.
374+
// However, MySqlConnectorTester.generated.cs uses actual.Value, implying it's nullable.
375+
// Let's assume QuerySql.GetAuthor returns QuerySql.GetAuthorRow? (nullable record struct) for MySqlConnectorExampleGen.
376+
var actualNull = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
377+
Assert.That(actualNull == null, "there is author"); // This is correct for nullable types
378+
await transaction.CommitAsync();
379+
var expected = new QuerySql.GetAuthorRow
380+
{
381+
Id = 1111,
382+
Name = "Bojack Horseman",
383+
Bio = "Back in the 90s he was in a very famous TV show"
384+
};
385+
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs { Name = "Bojack Horseman" });
386+
Assert.That(SingularEquals(expected, actual)); // Apply placeholder here
387+
}
388+
364389
[Test]
365390
[TestCase(3.4f, -31.555666, 11.098643, 34.4424, 423.2445, 998.9994542, 21.214312452534)]
366391
[TestCase(null, null, null, null, null, null, null)]

0 commit comments

Comments
 (0)