From d974c6ed0d424e8160357fb0284c7bc4576624d3 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Sat, 17 Aug 2024 22:25:24 +0800 Subject: [PATCH] Fix tests: Have to specify minimum DateTime rather than the default with Jet --- .../Query/GearsOfWarQueryJetTest.cs | 23 ++++++++++++++----- .../Query/TPCGearsOfWarQueryJetTest.cs | 14 ++++++++--- .../Query/TPTGearsOfWarQueryJetTest.cs | 19 +++++++++++---- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs index 8c771f0..fc4bd6d 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs @@ -2564,13 +2564,24 @@ WHERE `m`.`Timeline` <> DATEADD('n', {dtoffset}.0, NOW()) public override async Task Where_datetimeoffset_date_component(bool isAsync) { - await base.Where_datetimeoffset_date_component(isAsync); + //We have to specifically use 1 JAn 100 as that is the minimum in Jet. + //The default 0 in DateTimeOffset is normally mapped to the OLE Automation date 30 Dec 1899 + //Investigate if we can pick the scenario up automatically and have a new DateTimeOffset().Date go to the required value if we have a comparison + //await base.Where_datetimeoffset_date_component(isAsync); + await AssertQuery( + isAsync, + ss => from m in ss.Set() + where m.Timeline.Date > new DateTimeOffset(100,1,1,0,0,0,new TimeSpan()).Date + select m); - // issue #16057 - // AssertSql( - // $@"SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Rating`, `m`.`Timeline` - //FROM `Missions` AS `m` - //WHERE CONVERT(date, `m`.`Timeline`) > '0001-01-01T00:00:00.0000000-08:00'"); + AssertSql( + """ +@__Date_0='0100-01-01T00:00:00.0000000' (DbType = DateTime) + +SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` +FROM `Missions` AS `m` +WHERE DATEVALUE(`m`.`Timeline`) > CDATE(@__Date_0) +"""); } public override async Task Where_datetimeoffset_year_component(bool isAsync) diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs index 464bfca..adc080c 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs @@ -3753,15 +3753,23 @@ WHERE `m`.`Timeline` <> DATEADD('n', {dtoffset}.0, NOW()) public override async Task Where_datetimeoffset_date_component(bool async) { - await base.Where_datetimeoffset_date_component(async); + //We have to specifically use 1 JAn 100 as that is the minimum in Jet. + //The default 0 in DateTimeOffset is normally mapped to the OLE Automation date 30 Dec 1899 + //Investigate if we can pick the scenario up automatically and have a new DateTimeOffset().Date go to the required value if we have a comparison + //await base.Where_datetimeoffset_date_component(async); + await AssertQuery( + async, + ss => from m in ss.Set() + where m.Timeline.Date > new DateTimeOffset(100, 1, 1, 0, 0, 0, new TimeSpan()).Date + select m); AssertSql( """ -@__Date_0='0001-01-01T00:00:00.0000000' (DbType = DateTime) +@__Date_0='0100-01-01T00:00:00.0000000' (DbType = DateTime) SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` FROM `Missions` AS `m` -WHERE DATEVALUE(`m`.`Timeline`) > @__Date_0 +WHERE DATEVALUE(`m`.`Timeline`) > CDATE(@__Date_0) """); } diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs index fdffde6..6b11e9b 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs @@ -2954,14 +2954,23 @@ WHERE `m`.`Timeline` <> DATEADD('n', {dtoffset}.0, NOW()) public override async Task Where_datetimeoffset_date_component(bool async) { - await base.Where_datetimeoffset_date_component(async); -AssertSql( - """ -@__Date_0='0001-01-01T00:00:00.0000000' (DbType = DateTime) + //We have to specifically use 1 JAn 100 as that is the minimum in Jet. + //The default 0 in DateTimeOffset is normally mapped to the OLE Automation date 30 Dec 1899 + //Investigate if we can pick the scenario up automatically and have a new DateTimeOffset().Date go to the required value if we have a comparison + //await base.Where_datetimeoffset_date_component(async); + await AssertQuery( + async, + ss => from m in ss.Set() + where m.Timeline.Date > new DateTimeOffset(100, 1, 1, 0, 0, 0, new TimeSpan()).Date + select m); + + AssertSql( + """ +@__Date_0='0100-01-01T00:00:00.0000000' (DbType = DateTime) SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` FROM `Missions` AS `m` -WHERE DATEVALUE(`m`.`Timeline`) > @__Date_0 +WHERE DATEVALUE(`m`.`Timeline`) > CDATE(@__Date_0) """); }