From a46354a2e2cee94410f92669a6d8f4bc0affcd18 Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Fri, 12 May 2017 15:18:34 -0700 Subject: [PATCH] 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. --- Dapper.Tests/Providers/MySQLTests.cs | 18 +++++++++--------- Dapper.Tests/TestBase.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Dapper.Tests/Providers/MySQLTests.cs b/Dapper.Tests/Providers/MySQLTests.cs index 306336887..edd6e589e 100644 --- a/Dapper.Tests/Providers/MySQLTests.cs +++ b/Dapper.Tests/Providers/MySQLTests.cs @@ -26,9 +26,9 @@ private static MySql.Data.MySqlClient.MySqlConnection GetMySqlConnection(bool op [FactMySql] public void DapperEnumValue_Mysql() { - using (var connection = GetMySqlConnection()) + using (var conn = GetMySqlConnection()) { - Common.DapperEnumValue(connection); + Common.DapperEnumValue(conn); } } @@ -77,7 +77,7 @@ public void Issue295_NullableDateTime_MySql_Default() { using (var conn = GetMySqlConnection(true, false, false)) { - Common.TestDateTime(connection); + Common.TestDateTime(conn); } } @@ -86,25 +86,25 @@ public void Issue295_NullableDateTime_MySql_ConvertZeroDatetime() { using (var conn = GetMySqlConnection(true, true, false)) { - Common.TestDateTime(connection); + Common.TestDateTime(conn); } } - [FactMySql] + [FactMySql(Skip = "See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported")] public void Issue295_NullableDateTime_MySql_AllowZeroDatetime() { using (var conn = GetMySqlConnection(true, false, true)) { - Common.TestDateTime(connection); + Common.TestDateTime(conn); } } - [FactMySql] + [FactMySql(Skip = "See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported")] public void Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime() { using (var conn = GetMySqlConnection(true, true, true)) { - Common.TestDateTime(connection); + Common.TestDateTime(conn); } } @@ -186,4 +186,4 @@ static FactMySqlAttribute() } } } -#endif \ No newline at end of file +#endif diff --git a/Dapper.Tests/TestBase.cs b/Dapper.Tests/TestBase.cs index 1d595377b..dccf38f23 100644 --- a/Dapper.Tests/TestBase.cs +++ b/Dapper.Tests/TestBase.cs @@ -78,7 +78,7 @@ static TestBase() public void Dispose() { - connection?.Dispose(); + _connection?.Dispose(); } } }