Skip to content

Commit

Permalink
Initial test setup for #461; note that this does not repro, due to ru…
Browse files Browse the repository at this point in the history
…nning on SQL-Server - needs to be changed to SQLite to repro
  • Loading branch information
mgravell committed Feb 15, 2016
1 parent 95d587f commit 1797a3c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
70 changes: 70 additions & 0 deletions Dapper.Tests/Tests.Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,76 @@ public void TestNoDefaultConstructorBinary()
}
#endif

[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
// SqlMapper.AddTypeHandler(new Issue461_DateTimeOffsetHandler());

connection.Execute(@"CREATE TABLE #Issue461 (
Id VARCHAR(50),
SomeValue VARCHAR(50),
SomeDateValue DATETIMEOFFSET
)");
var when = new DateTimeOffset(2016, 02, 15, 16, 0, 0, TimeSpan.FromHours(2));
connection.Execute(
"INSERT INTO #Issue461 (Id, SomeValue, SomeDateValue) VALUES (@Id, @SomeValue, @SomeDateValue)",
new
{
Id = "id",
SomeValue = "what up?",
SomeDateValue = when
});

var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo("id");
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeDateValue.IsEqualTo(when);

//throws about not being able to find constructor (It expects the DateTime field to be a string still)
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo("id");
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeDateValue.IsEqualTo(when);


}

//class Issue461_DateTimeOffsetHandler : SqlMapper.TypeHandler<DateTimeOffset>
//{
// public override void SetValue(IDbDataParameter parameter, DateTimeOffset value)
// {
// parameter.Value = value.ToString();
// }

// public override DateTimeOffset Parse(object value)
// {
// return DateTimeOffset.Parse(value.ToString());
// }
//}

class Issue461_ParameterlessTypeConstructor
{
public string Id { get; set; }

public string SomeValue { get; set; }
public DateTimeOffset SomeDateValue { get; set; }
}

class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(string id, string someValue, DateTimeOffset someDateValue)
{
Id = id;
SomeValue = someValue;
SomeDateValue = someDateValue;
}

public string Id { get; }

public string SomeValue { get; }
public DateTimeOffset SomeDateValue { get; }
}

public class AbstractInheritance
{
public abstract class Order
Expand Down
12 changes: 8 additions & 4 deletions Dapper.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"MASSIVE",
"ORMLITE",
"SOMA",
"SIMPLEDATA"
"SIMPLEDATA",
"SQLITE"
]
},
"frameworkAssemblies": {
Expand All @@ -61,7 +62,8 @@
"Simple.Data.SqlServer": "1.0.0-rc3",
"Soma": "1.8.0.7",
"Microsoft.SqlServer.Compact": "4.0.8876.1",
"xunit": "1.9.2"
"xunit": "1.9.2",
"System.Data.SQLite": "1.0.99"
}
},
"net45": {
Expand All @@ -79,7 +81,8 @@
"ORMLITE",
"SOMA",
"SIMPLEDATA",
"XUNIT2"
"XUNIT2",
"SQLITE"
]
},
"frameworkAssemblies": {
Expand Down Expand Up @@ -108,7 +111,8 @@
"Susanoo.Core": "1.2.4",
"Susanoo.SqlServer": "1.2.4",
"Microsoft.SqlServer.Compact": "4.0.8876.1",
"xunit": "2.1.0"
"xunit": "2.1.0",
"System.Data.SQLite": "1.0.99"
}
},
"dotnet5.4": {
Expand Down

0 comments on commit 1797a3c

Please sign in to comment.