Skip to content

Commit

Permalink
Fix MySQL tests and disposal (#774)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bgrainger authored and NickCraver committed May 12, 2017
1 parent d3ab338 commit a46354a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Dapper.Tests/Providers/MySQLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public void Issue295_NullableDateTime_MySql_Default()
{
using (var conn = GetMySqlConnection(true, false, false))
{
Common.TestDateTime(connection);
Common.TestDateTime(conn);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -186,4 +186,4 @@ static FactMySqlAttribute()
}
}
}
#endif
#endif
2 changes: 1 addition & 1 deletion Dapper.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static TestBase()

public void Dispose()
{
connection?.Dispose();
_connection?.Dispose();
}
}
}

0 comments on commit a46354a

Please sign in to comment.