From caa4ebac81c2c1429192f1e38b74b46005e3103f Mon Sep 17 00:00:00 2001 From: mgravell Date: Thu, 9 Dec 2021 12:12:49 +0000 Subject: [PATCH] additional work on #1728 --- tests/Dapper.Tests/Dapper.Tests.csproj | 4 ++-- tests/Dapper.Tests/ParameterTests.cs | 14 ++++++------- .../Dapper.Tests/Providers/PostgresqlTests.cs | 20 +++++++++++++++++++ tests/Dapper.Tests/Providers/SqliteTests.cs | 17 ++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index 8e3881ff3..c736f3995 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -16,10 +16,10 @@ - + - + diff --git a/tests/Dapper.Tests/ParameterTests.cs b/tests/Dapper.Tests/ParameterTests.cs index b7f44adb2..63980268d 100644 --- a/tests/Dapper.Tests/ParameterTests.cs +++ b/tests/Dapper.Tests/ParameterTests.cs @@ -1601,17 +1601,17 @@ public void TestDateOnlyTimeOnly() var now = DateTime.UtcNow; var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) }; - //try - //{ + try + { var (day, time) = connection.QuerySingle<(DateOnly, TimeOnly)>("select @day, @time", args); Assert.Equal(args.day, day); Assert.Equal(args.time, time); - //} - //catch (ArgumentException ex) when (ex.StackTrace.Contains("MetaType.GetMetaTypeFromValue")) - //{ - // Skip.Inconclusive("Feature not supported by provider"); - //} + } + catch (ArgumentException ex) when(ex.StackTrace.Contains("MetaType.GetMetaTypeFromValue")) + { + Skip.Inconclusive("Feature not supported by provider"); + } } #endif diff --git a/tests/Dapper.Tests/Providers/PostgresqlTests.cs b/tests/Dapper.Tests/Providers/PostgresqlTests.cs index bc90f1721..9a1b56262 100644 --- a/tests/Dapper.Tests/Providers/PostgresqlTests.cs +++ b/tests/Dapper.Tests/Providers/PostgresqlTests.cs @@ -141,5 +141,25 @@ static FactPostgresqlAttribute() } } } + +#if NET6_0_OR_GREATER + [Fact] + public void TestDateOnlyTimeOnly() + { + + var now = DateTime.UtcNow; + var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) }; + var result = connection.QuerySingle("select @day::date as day, @time::time as time", args); + + var day = DateOnly.FromDateTime(Assert.IsType(result.day)); + var time = TimeOnly.FromTimeSpan(Assert.IsType(result.time)); + + Assert.Equal(args.day, day); + Assert.Equal(Round(args.time), Round(time)); + + static TimeOnly Round(TimeOnly value) + => new TimeOnly(value.Hour, value.Minute, value.Second); + } +#endif } } diff --git a/tests/Dapper.Tests/Providers/SqliteTests.cs b/tests/Dapper.Tests/Providers/SqliteTests.cs index a5aeb086f..0473c70dd 100644 --- a/tests/Dapper.Tests/Providers/SqliteTests.cs +++ b/tests/Dapper.Tests/Providers/SqliteTests.cs @@ -160,6 +160,23 @@ public void DateTimeIsParsedWithInvariantCulture() } } +#if NET6_0_OR_GREATER + [Fact] + public void TestDateOnlyTimeOnly() + { + + var now = DateTime.UtcNow; + var args = new { day = DateOnly.FromDateTime(now), time = TimeOnly.FromDateTime(now) }; + var result = connection.QuerySingle("select @day as day, @time as time", args); + + var day = DateOnly.Parse(Assert.IsType(result.day)); + var time = TimeOnly.Parse(Assert.IsType(result.time)); + + Assert.Equal(args.day, day); + Assert.Equal(args.time, time); + } +#endif + private class PersonWithDob { public int Id { get; set; }