Skip to content

Commit

Permalink
additional work on #1728
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Dec 9, 2021
1 parent 24d7f37 commit caa4eba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<ProjectReference Include="../../Dapper.SqlBuilder/Dapper.SqlBuilder.csproj" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="7.5.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="MySqlConnector" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="6.0.0" />
<PackageReference Include="Npgsql" Version="6.0.1" />
<PackageReference Include="Snowflake.Data" Version="2.0.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
Expand Down
14 changes: 7 additions & 7 deletions tests/Dapper.Tests/ParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/Dapper.Tests/Providers/PostgresqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime>(result.day));
var time = TimeOnly.FromTimeSpan(Assert.IsType<TimeSpan>(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
}
}
17 changes: 17 additions & 0 deletions tests/Dapper.Tests/Providers/SqliteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(result.day));
var time = TimeOnly.Parse(Assert.IsType<string>(result.time));

Assert.Equal(args.day, day);
Assert.Equal(args.time, time);
}
#endif

private class PersonWithDob
{
public int Id { get; set; }
Expand Down

0 comments on commit caa4eba

Please sign in to comment.