From 352734a537286e502f3d5599ada4f2ff8ffc235b Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 4 Oct 2023 01:19:17 +0800 Subject: [PATCH] Update the base Gears of War to be synced with .Net RC1 --- .../EFCore.Jet.CustomBaseTests.csproj | 2 +- .../GearsOfWarModel/GearsOfWarData.cs | 18 +-- .../GearsOfWarFromSqlQueryTestBase.cs | 2 +- .../GearsOfWarQueryTestBase.cs | 135 ++++++++++++++---- 4 files changed, 117 insertions(+), 40 deletions(-) diff --git a/test/EFCore.Jet.CustomBaseTests/EFCore.Jet.CustomBaseTests.csproj b/test/EFCore.Jet.CustomBaseTests/EFCore.Jet.CustomBaseTests.csproj index d21b29b..97cd266 100644 --- a/test/EFCore.Jet.CustomBaseTests/EFCore.Jet.CustomBaseTests.csproj +++ b/test/EFCore.Jet.CustomBaseTests/EFCore.Jet.CustomBaseTests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable AnyCPU;x86 diff --git a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarData.cs b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarData.cs index 805e23d..48bf2ac 100644 --- a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarData.cs +++ b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarData.cs @@ -202,63 +202,63 @@ public class GearsOfWarData : ISetSource { Id = 1, Name = "Marcus' Lancer", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Cartridge, + AmmunitionType = AmmunitionType.Cartridge, IsAutomatic = true }, new() { Id = 2, Name = "Marcus' Gnasher", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Shell, + AmmunitionType = AmmunitionType.Shell, IsAutomatic = false }, new() { Id = 3, Name = "Dom's Hammerburst", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Cartridge, + AmmunitionType = AmmunitionType.Cartridge, IsAutomatic = false }, new() { Id = 4, Name = "Dom's Gnasher", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Shell, + AmmunitionType = AmmunitionType.Shell, IsAutomatic = false }, new() { Id = 5, Name = "Cole's Gnasher", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Shell, + AmmunitionType = AmmunitionType.Shell, IsAutomatic = false }, new() { Id = 6, Name = "Cole's Mulcher", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Cartridge, + AmmunitionType = AmmunitionType.Cartridge, IsAutomatic = true }, new() { Id = 7, Name = "Baird's Lancer", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Cartridge, + AmmunitionType = AmmunitionType.Cartridge, IsAutomatic = true }, new() { Id = 8, Name = "Baird's Gnasher", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Shell, + AmmunitionType = AmmunitionType.Shell, IsAutomatic = false }, new() { Id = 9, Name = "Paduk's Markza", - AmmunitionType = global::EFCore.Jet.CustomBaseTests.GearsOfWarModel.AmmunitionType.Cartridge, + AmmunitionType = AmmunitionType.Cartridge, IsAutomatic = false }, new() diff --git a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarFromSqlQueryTestBase.cs b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarFromSqlQueryTestBase.cs index bfb29ff..0ee868c 100644 --- a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarFromSqlQueryTestBase.cs +++ b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarFromSqlQueryTestBase.cs @@ -43,7 +43,7 @@ public abstract class GearsOfWarFromSqlQueryTestBase : IClassFixture Fixture.TestStore.NormalizeDelimitersInInterpolatedString(sql); - protected GearsOfWarModel.GearsOfWarContext CreateContext() + protected GearsOfWarContext CreateContext() => Fixture.CreateContext(); protected virtual void ClearLog() diff --git a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarQueryTestBase.cs b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarQueryTestBase.cs index 4af897c..dbeb90f 100644 --- a/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Jet.CustomBaseTests/GearsOfWarModel/GearsOfWarQueryTestBase.cs @@ -45,34 +45,6 @@ public abstract class GearsOfWarQueryTestBase : QueryTestBase new ExpectedQueryRewritingVisitor(Fixture.GetShadowPropertyMappings()) .Visit(expectedQueryExpression); - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Negate_on_binary_expression(bool async) - => AssertQuery( - async, - ss => ss.Set().Where(s => s.Id == -(s.Id + s.Id))); - - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Negate_on_column(bool async) - => AssertQuery( - async, - ss => ss.Set().Where(s => s.Id == -s.Id)); - - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Double_negate_on_column(bool async) - => AssertQuery( - async, - ss => ss.Set().Where(s => -(-s.Id) == s.Id)); - - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Negate_on_like_expression(bool async) - => AssertQuery( - async, - ss => ss.Set().Where(s => !s.Name.StartsWith("us"))); - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Entity_equality_empty(bool async) @@ -106,6 +78,13 @@ public abstract class GearsOfWarQueryTestBase : QueryTestBase AssertQuery( + async, + ss => ss.Set().Select(w => w.Name.ToString())); + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ToString_boolean_property_non_nullable(bool async) @@ -2647,7 +2626,7 @@ public abstract class GearsOfWarQueryTestBase : QueryTestBase weapons.OrderBy(w => w.Id).FirstOrDefault(); private static IEnumerable Veterans(IEnumerable gears) - => gears.Where(g => g.Nickname == "Marcus" || g.Nickname == "Dom" || g.Nickname == "Cole Train" || g.Nickname == "Baird"); + => gears.Where(g => g.Nickname is "Marcus" or "Dom" or "Cole Train" or "Baird"); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -8186,6 +8165,104 @@ public abstract class GearsOfWarQueryTestBase : QueryTestBase ss.Set().Where(s => s.Weapons.OrderBy(e => e.Name).FirstOrDefault() == null)); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ElementAt_basic_with_OrderBy(bool async) + => AssertElementAt( + async, + ss => ss.Set().OrderBy(g => g.FullName), + () => 0); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ElementAtOrDefault_basic_with_OrderBy(bool async) + => AssertElementAtOrDefault( + async, + ss => ss.Set().OrderBy(g => g.FullName), + () => 1); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ElementAtOrDefault_basic_with_OrderBy_parameter(bool async) + { + var prm = 2; + + return AssertElementAtOrDefault( + async, + ss => ss.Set().OrderBy(g => g.FullName), + () => prm); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Where_subquery_with_ElementAtOrDefault_equality_to_null_with_composite_key(bool async) + => AssertQuery( + async, + ss => ss.Set().Where(s => s.Members.OrderBy(e => e.Nickname).ElementAtOrDefault(2) == null)); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Where_subquery_with_ElementAt_using_column_as_index(bool async) + => AssertQuery( + async, + ss => ss.Set().Where(s => s.Members.OrderBy(m => m.Nickname).ElementAt(s.Id).Nickname == "Cole Train"), + ss => ss.Set().Where(s => s.Members.OrderBy(m => m.Nickname).ElementAtOrDefault(s.Id).Nickname == "Cole Train")); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Using_indexer_on_byte_array_and_string_in_projection(bool async) + => AssertQuery( + async, + ss => ss.Set().Select(x => new { x.Id, ByteArray = x.Banner[0], String = x.Name[1] }), + elementSorter: e => e.Id, + elementAsserter: (e, a) => + { + Assert.Equal(e.Id, a.Id); + Assert.Equal(e.ByteArray, a.ByteArray); + Assert.Equal(e.String, a.String); + }); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task DateTimeOffset_to_unix_time_milliseconds(bool async) + { + long unixEpochMilliseconds = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds(); + + return AssertQuery( + async, + ss => ss.Set() + .Include(g => g.Squad.Missions) + .Where(s => s.Squad.Missions + .Where(m => unixEpochMilliseconds == m.Mission.Timeline.ToUnixTimeMilliseconds()) + .FirstOrDefault() == null)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task DateTimeOffset_to_unix_time_seconds(bool async) + { + long unixEpochSeconds = DateTimeOffset.UnixEpoch.ToUnixTimeSeconds(); + + return AssertQuery( + async, + ss => ss.Set() + .Include(g => g.Squad.Missions) + .Where(s => s.Squad.Missions + .Where(m => unixEpochSeconds == m.Mission.Timeline.ToUnixTimeSeconds()) + .FirstOrDefault() == null)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Set_operator_with_navigation_in_projection_groupby_aggregate(bool async) + => AssertQuery( + async, + ss => ss.Set() + .Where(x => ss.Set().Concat(ss.Set()).Select(x => x.Nickname).Contains("Marcus")) + .Select(x => new { x.Squad.Name, x.CityOfBirth.Location }) + .GroupBy(x => new { x.Name }) + .Select(x => new { x.Key.Name, SumOfLengths = x.Sum(xx => xx.Location.Length) })); + protected GearsOfWarContext CreateContext() => Fixture.CreateContext();