Skip to content

Commit a0d7f11

Browse files
authored
Add tolerance for DATETIME
1 parent 63c3547 commit a0d7f11

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/SqlClient.Tests/TypeProviderTest.fs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,18 @@ let ``Roundtrip ToTraceString for decimals with maximum precision``() =
148148
[<Fact>]
149149
let ``Roundtrip ToTraceString for date time ``() =
150150
let cmd = new SqlCommandProvider<"SELECT CAST(@x AS DATETIME)", ConnectionStrings.AdventureWorksNamed>()
151+
// SQL Server DATETIME has precision up to .00333 seconds
152+
let tolerance = 0.00334
151153
let now = System.DateTime.Now
152-
let result = runScalarQuery <| cmd.ToTraceString(now)
154+
let result = runScalarQuery <| cmd.ToTraceString(now)
155+
Assert.InRange(unbox<DateTime> result, now.AddSeconds(-1. * tolerance), now.AddSeconds(tolerance))
156+
157+
[<Fact>]
158+
let ``Roundtrip ToTraceString for datetime2 ``() =
159+
let cmd = new SqlCommandProvider<"SELECT CAST(@x AS DATETIME2)", ConnectionStrings.AdventureWorksNamed>()
160+
// SQL Server DATETIME2 has the same nanosecond precision as DATETIMEOFFSET so there shouldn't be any discrepance
161+
let now = System.DateTime.Now
162+
let result = runScalarQuery <| cmd.ToTraceString(now)
153163
Assert.Equal(expected = now, actual = unbox<DateTime> result)
154164

155165
[<Fact>]

0 commit comments

Comments
 (0)