Skip to content

Commit a46354a

Browse files
bgraingerNickCraver
authored andcommitted
Fix MySQL tests and disposal (#774)
* Don't create the connection in Dispose: this avoids creating a SQLConnection simply to Dispose it. * Run MySQL tests against the open MySqlConnection: 'connection' is a protected variable in the TestBase class that is a SQL Server connection, not a MySQL connection. * Skip broken MySQL tests: as per issue #295, setting "AllowZeroDateTime=True" in the connection string causes an InvalidCastException in SqlMapper.
1 parent d3ab338 commit a46354a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Dapper.Tests/Providers/MySQLTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ private static MySql.Data.MySqlClient.MySqlConnection GetMySqlConnection(bool op
2626
[FactMySql]
2727
public void DapperEnumValue_Mysql()
2828
{
29-
using (var connection = GetMySqlConnection())
29+
using (var conn = GetMySqlConnection())
3030
{
31-
Common.DapperEnumValue(connection);
31+
Common.DapperEnumValue(conn);
3232
}
3333
}
3434

@@ -77,7 +77,7 @@ public void Issue295_NullableDateTime_MySql_Default()
7777
{
7878
using (var conn = GetMySqlConnection(true, false, false))
7979
{
80-
Common.TestDateTime(connection);
80+
Common.TestDateTime(conn);
8181
}
8282
}
8383

@@ -86,25 +86,25 @@ public void Issue295_NullableDateTime_MySql_ConvertZeroDatetime()
8686
{
8787
using (var conn = GetMySqlConnection(true, true, false))
8888
{
89-
Common.TestDateTime(connection);
89+
Common.TestDateTime(conn);
9090
}
9191
}
9292

93-
[FactMySql]
93+
[FactMySql(Skip = "See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported")]
9494
public void Issue295_NullableDateTime_MySql_AllowZeroDatetime()
9595
{
9696
using (var conn = GetMySqlConnection(true, false, true))
9797
{
98-
Common.TestDateTime(connection);
98+
Common.TestDateTime(conn);
9999
}
100100
}
101101

102-
[FactMySql]
102+
[FactMySql(Skip = "See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported")]
103103
public void Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime()
104104
{
105105
using (var conn = GetMySqlConnection(true, true, true))
106106
{
107-
Common.TestDateTime(connection);
107+
Common.TestDateTime(conn);
108108
}
109109
}
110110

@@ -186,4 +186,4 @@ static FactMySqlAttribute()
186186
}
187187
}
188188
}
189-
#endif
189+
#endif

Dapper.Tests/TestBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static TestBase()
7878

7979
public void Dispose()
8080
{
81-
connection?.Dispose();
81+
_connection?.Dispose();
8282
}
8383
}
8484
}

0 commit comments

Comments
 (0)