Commit e918254e authored by Marc Gravell's avatar Marc Gravell

Test rig for Issue #295

parent 23c4c539
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.Diagnostics; using System.Diagnostics;
using Xunit; using Xunit;
using System.Data.Common;
#if EXTERNALS #if EXTERNALS
using FirebirdSql.Data.FirebirdClient; using FirebirdSql.Data.FirebirdClient;
using System.Data.Entity.Spatial; using System.Data.Entity.Spatial;
...@@ -2844,7 +2845,95 @@ public void SO30435185_InvalidTypeOwner() ...@@ -2844,7 +2845,95 @@ public void SO30435185_InvalidTypeOwner()
ex.Message.IsEqualTo("An enumerable sequence of parameters (arrays, lists, etc) is not allowed in this context"); ex.Message.IsEqualTo("An enumerable sequence of parameters (arrays, lists, etc) is not allowed in this context");
} }
} }
[Fact]
public void Issue295_NullableDateTime_SqlServer()
{
TestDateTime(connection);
}
#if MYSQL
private static MySql.Data.MySqlClient.MySqlConnection GetMySqlConnection(bool open = true,
bool convertZeroDatetime = false, bool allowZeroDatetime = false)
{
const string cs = "Server=localhost;Database=tests;Uid=test;Pwd=pass;";
var csb = new MySql.Data.MySqlClient.MySqlConnectionStringBuilder(cs);
csb.AllowZeroDateTime = allowZeroDatetime;
csb.ConvertZeroDateTime = convertZeroDatetime;
var conn = new MySql.Data.MySqlClient.MySqlConnection(csb.ConnectionString);
if (open) conn.Open();
return conn;
}
[FactMySql]
public void Issue295_NullableDateTime_MySql_Default()
{
using (var conn = GetMySqlConnection(true, false, false)) { TestDateTime(connection); }
}
[FactMySql]
public void Issue295_NullableDateTime_MySql_ConvertZeroDatetime()
{
using (var conn = GetMySqlConnection(true, true, false)) { TestDateTime(connection); }
}
[FactMySql]
public void Issue295_NullableDateTime_MySql_AllowZeroDatetime()
{
using (var conn = GetMySqlConnection(true, false, true)) { TestDateTime(connection); }
}
[FactMySql]
public void Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime()
{
using (var conn = GetMySqlConnection(true, true, true)) { TestDateTime(connection); }
}
public class FactMySqlAttribute : FactAttribute
{
public override string Skip
{
get { return unavailable ?? base.Skip; }
set { base.Skip = value; }
}
private static string unavailable;
static FactMySqlAttribute()
{
try
{
using (GetMySqlConnection(true)) { }
}
catch(Exception ex)
{
unavailable = $"MySql is unavailable: {ex.Message}";
}
}
}
#endif
private void TestDateTime(DbConnection connection)
{
DateTime? now = DateTime.UtcNow;
try { connection.Execute("DROP TABLE Persons"); } catch { }
connection.Execute(@"CREATE TABLE Persons (id int not null, dob datetime null)");
connection.Execute(@"INSERT Persons (id, dob) values (@id, @dob)",
new { id = 7, dob = (DateTime?)null });
connection.Execute(@"INSERT Persons (id, dob) values (@id, @dob)",
new { id = 42, dob = now });
var row = connection.QueryFirstOrDefault<Issue295Person>(
"SELECT id, dob, dob as dob2 FROM Persons WHERE id=@id", new { id = 7});
row.IsNotNull();
row.Id.IsEqualTo(7);
row.DoB.IsNull();
row.DoB2.IsNull();
row = connection.QueryFirstOrDefault<Issue295Person>(
"SELECT id, dob FROM Persons WHERE id=@id", new { id = 42 });
row.IsNotNull();
row.Id.IsEqualTo(42);
row.DoB.Equals(now);
row.DoB2.Equals(now);
}
class Issue295Person
{
public int Id { get; set; }
public DateTime? DoB { get; set; }
public DateTime? DoB2 { get; set; }
}
#if EXTERNALS #if EXTERNALS
[Fact(Skip="Bug in Firebird; a PR to fix it has been submitted")] [Fact(Skip="Bug in Firebird; a PR to fix it has been submitted")]
public void Issue178_Firebird() public void Issue178_Firebird()
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
}, },
"frameworks": { "frameworks": {
"net40": { "net40": {
"compilationOptions": {
"define": [ "MYSQL" ]
},
"frameworkAssemblies": { "frameworkAssemblies": {
"System.Configuration": "4.0.0.0", "System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0", "System.Data": "4.0.0.0",
...@@ -36,12 +39,13 @@ ...@@ -36,12 +39,13 @@
"ServiceStack.OrmLite": "4.0.48", "ServiceStack.OrmLite": "4.0.48",
"ServiceStack.OrmLite.SqlServer": "4.0.48", "ServiceStack.OrmLite.SqlServer": "4.0.48",
"Soma": "1.8.0.7", "Soma": "1.8.0.7",
"xunit": "1.9.2" "xunit": "1.9.2",
"MySql.Data": "6.9.8"
} }
}, },
"net45": { "net45": {
"compilationOptions": { "compilationOptions": {
"define": [ "ASYNC" ] "define": [ "ASYNC", "MYSQL" ]
}, },
"frameworkAssemblies": { "frameworkAssemblies": {
"System.Configuration": "4.0.0.0", "System.Configuration": "4.0.0.0",
...@@ -55,7 +59,8 @@ ...@@ -55,7 +59,8 @@
"ServiceStack.OrmLite": "4.0.48", "ServiceStack.OrmLite": "4.0.48",
"ServiceStack.OrmLite.SqlServer": "4.0.48", "ServiceStack.OrmLite.SqlServer": "4.0.48",
"Soma": "1.8.0.7", "Soma": "1.8.0.7",
"xunit": "2.1.0" "xunit": "2.1.0",
"MySql.Data": "6.9.8"
} }
}, },
"dotnet5.4": { "dotnet5.4": {
...@@ -75,7 +80,7 @@ ...@@ -75,7 +80,7 @@
}, },
"dnx451": { "dnx451": {
"compilationOptions": { "compilationOptions": {
"define": [ "ASYNC", "EXTERNALS", "DNX" ] "define": [ "ASYNC", "EXTERNALS", "DNX", "MYSQL" ]
}, },
"frameworkAssemblies": { "frameworkAssemblies": {
"System.Configuration": "4.0.0.0", "System.Configuration": "4.0.0.0",
...@@ -102,7 +107,8 @@ ...@@ -102,7 +107,8 @@
"FirebirdSql.Data.FirebirdClient": "4.8.1.1", "FirebirdSql.Data.FirebirdClient": "4.8.1.1",
"Dapper.EntityFramework": { "Dapper.EntityFramework": {
"target": "project" "target": "project"
} },
"MySql.Data": "6.9.8"
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment