diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f07d3d71..1e694832 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -692,11 +692,17 @@ jobs: - Preconditions - Changes if: (needs.Preconditions.outputs.lastCommitIsAutoCommit != 'true' || needs.Preconditions.outputs.lastCommitCreatedBeforeSeconds > 300) && needs.Changes.outputs.libred == 'true' + # The 365 leg is new: it does not gate the build until it has proven itself stable. + continue-on-error: ${{ matrix.aceVersion == '365' }} strategy: fail-fast: false matrix: + # 2016 is the out-of-support redistributable; 365 is the current Microsoft 365 Access Runtime, the engine + # the cross-checks are measured on. They differ where a test guards itself (BIGINT/DATETIME2, a + # backtick-quoted CHECK, a stored query's LvExtra), so those cases only run on the 365 leg. aceVersion: - 2016 + - 365 runs-on: windows-latest steps: - name: Checkout @@ -711,9 +717,38 @@ jobs: - name: Install Access Database Engine shell: pwsh run: | - $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' - Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName - & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + if ('${{ matrix.aceVersion }}' -eq '365') + { + # The runtime is click-to-run: the Office Deployment Tool downloads it from Microsoft's CDN, so + # the tool is fetched from there too rather than hosted. + Invoke-WebRequest 'https://officecdn.microsoft.com/pr/wsus/setup.exe' -OutFile setup.exe + Set-Content AccessRuntime.xml @' + + + + + + + + + + '@ + $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru + if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + # Since the December 2025 Office builds, ACE refuses every query that reaches another file ("Operation + # is not supported for this type of object") unless AllowQueryRemoteTables is 1. The IN externaldatabase + # cross-checks were measured with it set, as on the developer machine. -Force on an existing registry + # key would wipe its values, so the key is only created when missing. + $engines = 'HKLM:\SOFTWARE\Microsoft\Office\16.0\Access Connectivity Engine\Engines' + if (-not (Test-Path $engines)) { New-Item $engines -Force | Out-Null } + New-ItemProperty $engines -Name AllowQueryRemoteTables -PropertyType DWord -Value 1 -Force | Out-Null + } + else + { + $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' + Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName + & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + } - name: 'ACE Information' shell: pwsh run: | diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7ecc936b..64a837c4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -700,11 +700,17 @@ jobs: - Preconditions - Changes if: (needs.Preconditions.outputs.lastCommitIsAutoCommit != 'true' || needs.Preconditions.outputs.lastCommitCreatedBeforeSeconds > 300) && needs.Changes.outputs.libred == 'true' + # The 365 leg is new: it does not gate the build until it has proven itself stable. + continue-on-error: ${{ matrix.aceVersion == '365' }} strategy: fail-fast: false matrix: + # 2016 is the out-of-support redistributable; 365 is the current Microsoft 365 Access Runtime, the engine + # the cross-checks are measured on. They differ where a test guards itself (BIGINT/DATETIME2, a + # backtick-quoted CHECK, a stored query's LvExtra), so those cases only run on the 365 leg. aceVersion: - 2016 + - 365 runs-on: windows-latest steps: - name: Checkout @@ -719,9 +725,38 @@ jobs: - name: Install Access Database Engine shell: pwsh run: | - $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' - Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName - & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + if ('${{ matrix.aceVersion }}' -eq '365') + { + # The runtime is click-to-run: the Office Deployment Tool downloads it from Microsoft's CDN, so + # the tool is fetched from there too rather than hosted. + Invoke-WebRequest 'https://officecdn.microsoft.com/pr/wsus/setup.exe' -OutFile setup.exe + Set-Content AccessRuntime.xml @' + + + + + + + + + + '@ + $setup = Start-Process .\setup.exe -ArgumentList '/configure', 'AccessRuntime.xml' -Wait -PassThru + if ($setup.ExitCode -ne 0) { throw "The Office Deployment Tool exited with $($setup.ExitCode)." } + # Since the December 2025 Office builds, ACE refuses every query that reaches another file ("Operation + # is not supported for this type of object") unless AllowQueryRemoteTables is 1. The IN externaldatabase + # cross-checks were measured with it set, as on the developer machine. -Force on an existing registry + # key would wipe its values, so the key is only created when missing. + $engines = 'HKLM:\SOFTWARE\Microsoft\Office\16.0\Access Connectivity Engine\Engines' + if (-not (Test-Path $engines)) { New-Item $engines -Force | Out-Null } + New-ItemProperty $engines -Name AllowQueryRemoteTables -PropertyType DWord -Value 1 -Force | Out-Null + } + else + { + $setupFileName = 'AccessDatabaseEngine_${{ matrix.aceVersion }}_x64.exe' + Invoke-WebRequest "https://cirrusredorg.github.io/EntityFrameworkCore.Jet/$setupFileName" -OutFile $setupFileName + & ".\$setupFileName" /passive /quiet /norestart REBOOT=ReallySuppress | Out-Default + } - name: 'ACE Information' shell: pwsh run: | diff --git a/AGENTS.md b/AGENTS.md index 8f4b5e64..f45d7bf5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ It is kept in sync with `CLAUDE.md`; if you change guidance in one, check whethe EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-alpha.5` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` are the exception: they multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, since none of them depends on an EF Core package. `LibRed.EFCore` @@ -165,7 +165,8 @@ test/ LibRed.EFCore.Tests/ LibRed EF Core provider: query round-trip, database-first scaffolding [no driver; CI's Windows ACE job] LibRed.Shared/ Helpers compiled into the Core/Engine test pairs and LibRed.Ado.Tests - (TemporaryDatabase, …; AceTestDatabase into the AccessTests only) + (TemporaryDatabase, …; AceTestDatabase into the AccessTests only; + MalformedFile into LibRed.Core.Tests and LibRed.Core.Fuzz) EFCore.LibRed.FunctionalTests/ EF Core specification suite over LibRed, compatible SQL mode (Jet-dialect SQL) [cross-platform] EFCore.LibRed.Extended.FunctionalTests/ @@ -176,6 +177,9 @@ test/ split, storage, writes, DDL, catalog, and an opt-in ACE head-to-head. `-- --validate` checks the SQL corpus. See its README.md [cross-platform] + LibRed.Core.Fuzz/ SharpFuzz + libFuzzer harness over LibRed.Core: damaged databases + and blob decoders, held to the sweep's leak contract. Not in CI; + needs third-party tools. See its README.md [cross-platform] Shared/ For the EF functional suites: ModuleInitializer.cs (locks culture to en-US) and TestUtilities/ (test orderers, crash detection, conditions) @@ -405,8 +409,10 @@ flags — `jet` and `libred` — and skips the jobs that don't apply: partway through the largest shard. - **LibRed** — `LibRed.Engine.Tests` and `LibRed.Core.Tests` on Linux/Windows/macOS + ubuntu-arm/windows-arm, no ACE anywhere. -- **LibRedAccess** — the ACE cross-check suites on `windows-latest` with ACE 2016, plus `LibRed.Ado.Tests` and - `LibRed.EFCore.Tests`, which need no driver but run only there for now. +- **LibRedAccess** — the ACE cross-check suites on `windows-latest`, plus `LibRed.Ado.Tests` and + `LibRed.EFCore.Tests`, which need no driver but run only there for now. Two legs: the 2016 redistributable, and + the Microsoft 365 Access Runtime installed through the Office Deployment Tool, where the version-guarded cases + (BIGINT/DATETIME2, backtick CHECKs) actually run. The 365 leg is `continue-on-error` until it proves stable. - **LibRedFunctional** — both `EFCore.LibRed.FunctionalTests` (compatible mode) and `EFCore.LibRed.Extended.FunctionalTests` (extended mode) on the five-platform matrix, `continue-on-error`. - **NuGet** — packs for `master`, `*-servicing`, `*-wip` and release tags, attaching the packages to the run diff --git a/CLAUDE.md b/CLAUDE.md index 57b85d15..2b937041 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co EntityFrameworkCore.Jet is an EF Core provider for Microsoft Jet/ACE databases (Microsoft Access `.mdb`/`.accdb` files). The **Jet** provider runs **Windows only** and bridges EF Core to the Access database engine via either ODBC or OLE DB. Alongside it, **LibRed** (also in this repo, on `master`) is a from-scratch managed engine that reads/writes the file format directly and is **cross-platform** — see the LibRed section below. -Current version: `11.0.0-alpha.5` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 RC2 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. +Current version: `11.0.0-beta.1` (`Version.props`) targeting EF Core 11 and `net11.0`; `global.json` pins the 11.0.100 SDK with `rollForward: latestFeature`. The test projects use **xunit v3**, except `EFCore.Jet.Data.Tests` and `EFCore.Jet.IntegrationTests`, which use MSTest. **One exception to `net11.0`:** `LibRed.Core`, `LibRed.Sql`, `LibRed.Engine` and `LibRed.Ado` multi-target `$(LibRedTargetFrameworks)` = `net10.0;net11.0`, because none of them depends on an EF Core package. `LibRed.EFCore` @@ -169,7 +169,8 @@ test/ LibRed.EFCore.Tests/ LibRed EF Core provider: query round-trip, database-first scaffolding [no driver; CI's Windows ACE job] LibRed.Shared/ Helpers compiled into the Core/Engine test pairs and LibRed.Ado.Tests - (TemporaryDatabase, …; AceTestDatabase into the AccessTests only) + (TemporaryDatabase, …; AceTestDatabase into the AccessTests only; + MalformedFile into LibRed.Core.Tests and LibRed.Core.Fuzz) EFCore.LibRed.FunctionalTests/ EF Core specification suite over LibRed, compatible SQL mode (Jet-dialect SQL) [cross-platform] EFCore.LibRed.Extended.FunctionalTests/ @@ -180,6 +181,9 @@ test/ split, storage, writes, DDL, catalog, and an opt-in ACE head-to-head. `-- --validate` checks the SQL corpus. See its README.md [cross-platform] + LibRed.Core.Fuzz/ SharpFuzz + libFuzzer harness over LibRed.Core: damaged databases + and blob decoders, held to the sweep's leak contract. Not in CI; + needs third-party tools. See its README.md [cross-platform] Shared/ For the EF functional suites: ModuleInitializer.cs (locks culture to en-US) and TestUtilities/ (test orderers, crash detection, conditions) @@ -415,8 +419,10 @@ flags — `jet` and `libred` — and skips the jobs that don't apply: partway through the largest shard. - **LibRed** — `LibRed.Engine.Tests` and `LibRed.Core.Tests` on Linux/Windows/macOS + ubuntu-arm/windows-arm, no ACE anywhere. -- **LibRedAccess** — the ACE cross-check suites on `windows-latest` with ACE 2016, plus `LibRed.Ado.Tests` and - `LibRed.EFCore.Tests`, which need no driver but run only there for now. +- **LibRedAccess** — the ACE cross-check suites on `windows-latest`, plus `LibRed.Ado.Tests` and + `LibRed.EFCore.Tests`, which need no driver but run only there for now. Two legs: the 2016 redistributable, and + the Microsoft 365 Access Runtime installed through the Office Deployment Tool, where the version-guarded cases + (BIGINT/DATETIME2, backtick CHECKs) actually run. The 365 leg is `continue-on-error` until it proves stable. - **LibRedFunctional** — both `EFCore.LibRed.FunctionalTests` (compatible mode) and `EFCore.LibRed.Extended.FunctionalTests` (extended mode) on the five-platform matrix, `continue-on-error`. - **NuGet** — packs for `master`, `*-servicing`, `*-wip` and release tags, attaching the packages to the run diff --git a/Directory.Packages.props b/Directory.Packages.props index bf2ca305..fbcb09b5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,8 +1,8 @@ true - [11.0.0-rc.2.26504.105] - [11.0.0-rc.2.26504.105] + [11.0.0,11.0.999] + [11.0.0,11.0.999] @@ -25,11 +25,12 @@ - + + - - - + + + diff --git a/EFCore.Jet.sln b/EFCore.Jet.sln index 5157a78a..9b1e42f5 100644 --- a/EFCore.Jet.sln +++ b/EFCore.Jet.sln @@ -89,6 +89,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.LibRed.Extended.Func EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibRed.Core.AccessTests", "test\LibRed.Core.AccessTests\LibRed.Core.AccessTests.csproj", "{681BEAF7-FB98-4E12-81F1-055DF766AFC4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibRed.Core.Fuzz", "test\LibRed.Core.Fuzz\LibRed.Core.Fuzz.csproj", "{62DA6569-9508-471D-A4ED-72E8BF2C70B0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -387,6 +389,18 @@ Global {681BEAF7-FB98-4E12-81F1-055DF766AFC4}.Release|x64.Build.0 = Release|x64 {681BEAF7-FB98-4E12-81F1-055DF766AFC4}.Release|x86.ActiveCfg = Release|x86 {681BEAF7-FB98-4E12-81F1-055DF766AFC4}.Release|x86.Build.0 = Release|x86 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|x64.ActiveCfg = Debug|x64 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|x64.Build.0 = Debug|x64 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|x86.ActiveCfg = Debug|x86 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Debug|x86.Build.0 = Debug|x86 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|Any CPU.Build.0 = Release|Any CPU + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|x64.ActiveCfg = Release|x64 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|x64.Build.0 = Release|x64 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|x86.ActiveCfg = Release|x86 + {62DA6569-9508-471D-A4ED-72E8BF2C70B0}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Version.props b/Version.props index 57d74c37..7b97835a 100644 --- a/Version.props +++ b/Version.props @@ -16,8 +16,8 @@ correctly. --> 11.0.0 - alpha - 5 + beta + 1 + + diff --git a/src/LibRed/LibRed.Core/Pages/DataPage.cs b/src/LibRed/LibRed.Core/Pages/DataPage.cs index 9ae17236..5cc8945c 100644 --- a/src/LibRed/LibRed.Core/Pages/DataPage.cs +++ b/src/LibRed/LibRed.Core/Pages/DataPage.cs @@ -288,10 +288,14 @@ private static void ValidateSlot(PageBuffer buffer, int index, int offset, int p /// masked out of and so can exceed the page; rows are packed from the page end /// backward, so they must also never increase. RowInserter's in-place repackers re-derived this /// arithmetic without the checks, which on a corrupt directory produced an out-of-range exception from a - /// half-repacked page rather than a diagnosis. + /// half-repacked page rather than a diagnosis. The previous boundary is checked too: a directory walk has + /// already validated it, but reads it straight from the neighbouring slot. internal static void ValidateSlot( int pageNumber, int bufferLength, int index, int offset, int previousEnd, int directoryEnd) { + if (previousEnd > bufferLength) + throw new InvalidDataException( + $"Data page {pageNumber} row slot {index - 1} has offset {previousEnd}, past the page end {bufferLength}."); if (offset < directoryEnd || offset > bufferLength) throw new InvalidDataException( $"Data page {pageNumber} row slot {index} has offset {offset}, outside the row heap " + diff --git a/src/LibRed/LibRed.Core/Storage/BitmapBits.cs b/src/LibRed/LibRed.Core/Storage/BitmapBits.cs index f37ce293..ad0664cd 100644 --- a/src/LibRed/LibRed.Core/Storage/BitmapBits.cs +++ b/src/LibRed/LibRed.Core/Storage/BitmapBits.cs @@ -70,6 +70,10 @@ public static void AppendPages( for (int bit = NextSetBit(bitmap, 0); bit >= 0; bit = NextSetBit(bitmap, bit + 1)) { long page = (long)basePage + bit; + // Keeping every bit keeps pages past the file's end, never a page no file can have: a negative one + // would be taken for a bit index below the bitmap's first byte. + if (page is < 0 or > int.MaxValue) + throw new InvalidDataException($"{what} names page {page}, which no file can hold."); if (rejectBeyond is { } pageCount && (page <= 1 || page >= pageCount)) throw new InvalidDataException( $"{what} names page {page}, outside the file's 2..{pageCount - 1} range."); diff --git a/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs b/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs index 138edd2b..5eff702f 100644 --- a/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs +++ b/src/LibRed/LibRed.Core/Storage/CalculatedValue.cs @@ -150,6 +150,9 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v $"Calculated column '{column.Name}' contains an invalid expression: its descriptor lacks the flag that " + "lets the expression be evaluated."); + // The width first: a slot too short to be an envelope is damage, and its first four bytes are no status. + ReadOnlySpan payload = Payload(envelope, column); + // A failed expression is cached as its VBA error number with no payload, so it is NOT a Null even // though it has a Null's empty payload -- and reading it as one is a silent wrong answer, on a value // neither engine re-derives. ACE will not hand back such a row at all. @@ -158,7 +161,6 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v $"Calculated column '{column.Name}' holds a cached error, not a value: " + $"{VbaErrorText(error)}. Its expression is '{column.CalculatedExpression ?? "(unknown)"}'."); - ReadOnlySpan payload = Payload(envelope, column); JetDataType type = StoredType(column, payload.Length); // A zero-length payload is a Null result -- EXCEPT for text, where it is the empty string. The two @@ -172,10 +174,9 @@ private static byte[] EncodePayload(ColumnDef column, JetDataType type, object v } /// The envelope's leading status: 0 when the expression produced a value, otherwise the VBA - /// runtime error number it raised. A short envelope reads as 0 — a truncated slot is the width check's - /// business, not this one's. + /// runtime error number it raised. Read only after has checked the width. private static uint Status(ReadOnlySpan envelope) => - envelope.Length >= StatusSize ? BinaryPrimitives.ReadUInt32LittleEndian(envelope[..StatusSize]) : 0; + BinaryPrimitives.ReadUInt32LittleEndian(envelope[..StatusSize]); /// Names the VBA errors a calculated expression can actually raise, so the message says what /// went wrong rather than quoting a number. Measured: CDbl(Null) caches 94 and CDbl('hello') diff --git a/src/LibRed/LibRed.Core/Storage/IndexTree.cs b/src/LibRed/LibRed.Core/Storage/IndexTree.cs index 96ffb12a..bc34a7c9 100644 --- a/src/LibRed/LibRed.Core/Storage/IndexTree.cs +++ b/src/LibRed/LibRed.Core/Storage/IndexTree.cs @@ -177,8 +177,10 @@ public void RemoveEntry(IndexDef index, object?[] values, RowId rowId) int idx = LowerBound(entries, key); while (idx < entries.Count && CompareBytes(entries[idx].Key, key) == 0 && entries[idx].Trailer != pointer) idx++; + // The key is built from the row's own stored values, so a missing entry is an index that disagrees with its + // table: damage, which ACE refuses too ("The search key was not found in any record.", measured). if (idx == entries.Count || entries[idx].Trailer != pointer || CompareBytes(entries[idx].Key, key) != 0) - throw new InvalidOperationException( + throw new InvalidDataException( $"Index '{index.Name}': entry for row {rowId.Page}:{rowId.Row} was not found on leaf {leafPage}."); entries.RemoveAt(idx); diff --git a/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs b/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs index 820a5318..b11998aa 100644 --- a/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs +++ b/src/LibRed/LibRed.Core/Storage/JetLocaleTailoring.cs @@ -155,8 +155,9 @@ private bool TryLongest(ReadOnlySpan text, int start, out TailoredWeight w { for (int length = Math.Min(MaxLength, text.Length - start); length >= 1; length--) { - // A lowercase letter followed by an uppercase one breaks a contraction, which then falls to a shorter - // match: "cS" is c and S, "dzS" is dz and S, "dZs" is d and zs (verified vs ACE in every digraph order). + // A contraction matches only in lowercase, uppercase or title case; any other mix falls to a shorter + // match: "cS" is c and S, "dzS" is dz and S, "dZs" is d and zs, "DZs" is DZ and s (verified vs ACE in + // every case mix of every contraction). if (BreaksCase(text.Slice(start, length))) continue; if (TryGet(text.Slice(start, length), out weight)) @@ -172,7 +173,8 @@ private bool TryLongest(ReadOnlySpan text, int start, out TailoredWeight w static bool BreaksCase(ReadOnlySpan candidate) { for (int i = 0; i + 1 < candidate.Length; i++) - if (char.IsLower(candidate[i]) && char.IsUpper(candidate[i + 1])) + if ((char.IsLower(candidate[i]) && char.IsUpper(candidate[i + 1])) || + (i > 0 && char.IsUpper(candidate[i]) && char.IsLower(candidate[i + 1]))) return true; return false; } diff --git a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs index 8a353989..8dc6ed2b 100644 --- a/src/LibRed/LibRed.Core/Storage/PageAllocator.cs +++ b/src/LibRed/LibRed.Core/Storage/PageAllocator.cs @@ -446,41 +446,49 @@ public void ReturnReleasedPages() { SortedSet pages = [.. _channel.PagesReleasedAtClose]; if (pages.Count == 0 && !_channel.HasPublishedWrites && _reservationBits == 0 && _groups.Count == 0) return; - (_, MapRecord released) = ReadGlobalMaps(); - // Every bit kept, none bounded by the file: a released page past its end was never materialized, and is - // skipped below. - pages.UnionWith(UsageMap.PagesInRecord(_channel, released.Record, rejectBeyond: null, "The global released-pages map")); - if (pages.Count == 0 && _reservationBits == 0 && _groups.Count == 0) return; - bool ownTransaction = !_channel.InTransaction; - if (ownTransaction) _channel.BeginTransaction(); - try - { - // Sized before the merge: a conversion allocates its bitmap pages from the free map as it stands, - // without the pages being released. - if (pages.Count != 0) SizeReleasedMap(pages); - ReturnGroups(); - - // A released page past the end of the file was never materialized; the free map already records - // every page past the end as free. - foreach (int page in pages) - if (page < _channel.PageCount) Free(page); - for (int bit = 0; bit < 32; bit++) - if ((_reservationBits & (1u << bit)) != 0) Free(_reservationStart + bit); - _reservationBits = 0; - _owners.Clear(); - _bitmapSlot = 0; - - (_, released) = ReadGlobalMaps(); - ClearReleasedMap(released); - _channel.ClearPagesReleasedAtClose(); - if (ownTransaction) _channel.CommitTransaction(flush: false); - } - catch + // In the file's exclusive scope, as a writing statement runs: the global maps are read, rewritten and + // committed with no other connection committing between. Outside it, a statement on another connection + // could commit page 1 after this transaction first wrote it, and the commit would fail as a write conflict. + _channel.WriteExclusive(() => { - if (ownTransaction) _channel.RollbackTransaction(); - throw; - } + (_, MapRecord released) = ReadGlobalMaps(); + // Every bit kept, none bounded by the file: a released page past its end was never materialized, and is + // skipped below. + pages.UnionWith(UsageMap.PagesInRecord(_channel, released.Record, rejectBeyond: null, "The global released-pages map")); + if (pages.Count == 0 && _reservationBits == 0 && _groups.Count == 0) return false; + + bool ownTransaction = !_channel.InTransaction; + if (ownTransaction) _channel.BeginTransaction(); + try + { + // Sized before the merge: a conversion allocates its bitmap pages from the free map as it stands, + // without the pages being released. + if (pages.Count != 0) SizeReleasedMap(pages); + ReturnGroups(); + + // A released page past the end of the file was never materialized; the free map already records + // every page past the end as free. + foreach (int page in pages) + if (page < _channel.PageCount) Free(page); + for (int bit = 0; bit < 32; bit++) + if ((_reservationBits & (1u << bit)) != 0) Free(_reservationStart + bit); + _reservationBits = 0; + _owners.Clear(); + _bitmapSlot = 0; + + (_, released) = ReadGlobalMaps(); + ClearReleasedMap(released); + _channel.ClearPagesReleasedAtClose(); + if (ownTransaction) _channel.CommitTransaction(flush: false); + } + catch + { + if (ownTransaction) _channel.RollbackTransaction(); + throw; + } + return true; + }); } /// @@ -512,7 +520,9 @@ private void SizeReleasedMap(SortedSet pages) int start = UsageMap.StartPage(released.Record, format); int lowest = pages.Min, highest = pages.Max; int Covering(int from) => headerSize + UsageMap.InlineBitmapBytes(format, highest - from + 1); - if (lowest >= start && highest < start + (released.Slot.Length - headerSize) * 8) return; + // A map starting below page 0 is left as it was, and the pages are freed all the same: ACE's close does + // (measured, start -2,147,483,648). + if (start < 0 || lowest >= start && highest < start + (released.Slot.Length - headerSize) * 8) return; var holder = new DataPage(); holder.Read(new PageBuffer(released.Page, released.PageNumber), format); @@ -868,6 +878,11 @@ private static void ValidateReusablePage(int page, string source, MapRecord free /// against two ACE handles. private void EnsurePhysicalAllocation(int page) { + // A page past the largest file is in no database: ACE refuses to allocate it and leaves the file as it was + // (measured), where growing towards it would buffer pages up to the 2 GiB limit before WritePage refused one. + if (page > _channel.PageCount && page >= _channel.MaxPageCount) + throw new InvalidDataException( + $"The global free map selected page {page}, past the largest file of {_channel.MaxPageCount} pages."); while (_channel.PageCount < page) Append(); if (page < _channel.PageCount) return; int allocated = Append(); diff --git a/src/LibRed/LibRed.Core/Storage/RowCodec.cs b/src/LibRed/LibRed.Core/Storage/RowCodec.cs index 3215811e..9044b87a 100644 --- a/src/LibRed/LibRed.Core/Storage/RowCodec.cs +++ b/src/LibRed/LibRed.Core/Storage/RowCodec.cs @@ -76,9 +76,9 @@ public sealed class RowCodec(IReadOnlyList columns, JetFormatBase for /// The zero bytes to leave between the variable data and its offset table (spec §5), from /// the variable chunks this row is written with, by variable index; null for none. /// The buffer an UPDATE builds its rows in, one per statement and table, page-sized and - /// zeroed at the start: is copied in, the row is built over it, and the row is left in - /// it — so a byte the row does not write and its old record did not reach holds the last updated record that - /// did (verified vs ACE, UpdateRowBufferProbeTest). Null for none. + /// zeroed at the start: is copied in and the row is built over it, and the caller leaves + /// the row in it once the row is known to fit — so a byte the row does not write and its old record did not reach + /// holds the last updated record that did (verified vs ACE, UpdateRowBufferProbeTest). Null for none. internal byte[] Encode(object?[] values, IReadOnlyDictionary? preservedCalculated, object?[]? logicalValues = null, Layout prior = default, Func, int>? slackOf = null, byte[]? buffer = null) @@ -112,10 +112,8 @@ internal byte[] Encode(object?[] values, IReadOnlyDictionary? prese varChunks[column.VariableIndex] = v is null ? [] : JetTypeCodec.Encode(column, v, _format); } - byte[] row = AssembleRow(_format, _maxColumnId, fixedRegion, varChunks, _columns, values, prior.NullBitmap, + return AssembleRow(_format, _maxColumnId, fixedRegion, varChunks, _columns, values, prior.NullBitmap, slackOf?.Invoke(varChunks) ?? 0, buffer); - if (buffer is not null) row.CopyTo(buffer, 0); - return row; } /// The fixed region of a row being written over : diff --git a/src/LibRed/LibRed.Core/Storage/RowInserter.cs b/src/LibRed/LibRed.Core/Storage/RowInserter.cs index aa8ff8db..3963a66d 100644 --- a/src/LibRed/LibRed.Core/Storage/RowInserter.cs +++ b/src/LibRed/LibRed.Core/Storage/RowInserter.cs @@ -204,6 +204,10 @@ private void UpdateCore(RowId id, object?[] values, IReadOnlySet changedCol // unreadable row an INSERT was stopped from producing. EnsureRecordFits(format, record); + // The row is left in the statement's buffer for the next one built over it — only once it is known to fit, + // since one grown past the page does not fit the buffer either. + if (buffer is not null) record.CopyTo(buffer, 0); + if (DataPage.ReadSlot(srcPage.Span, format, id.Row).Flags.HasFlag(RowSlotFlags.Overflow)) { // This slot is a forward record pointer to the real (relocated) row; rewrite it on its target page @@ -1221,9 +1225,17 @@ private TableDefinition ReadDefinition() /// private bool[]? AssignAutoNumbers(JetFormatBase format, object?[] values, ReadOnlySpan tdef) { + // The counter is four bytes. A fixed column of another width carrying the AutoNumber flag — a damaged + // descriptor — cannot hold it: ACE draws the id all the same and then refuses the row, explicit value or not + // (measured on Integer, Currency and Date/Time columns; Single and Long, four bytes, take theirs). A random + // AutoNumber draws no id, so it is left as it was. + static bool CannotHoldTheCounter(ColumnDef column) => + column.IsFixedLength && column.Type != JetDataType.Boolean && column.Length != sizeof(int) + && !column.IsRandomAutoNumber; + bool needed = false; foreach (ColumnDef column in _table.Columns) - if (column.IsAutoNumber && values[column.Index] is null or DBNull) { needed = true; break; } + if (column.IsAutoNumber && (values[column.Index] is null or DBNull || CannotHoldTheCounter(column))) { needed = true; break; } if (!needed) return null; int highWater = TableDefinition.ReadLastAutoNumber(tdef, format); @@ -1237,7 +1249,8 @@ private TableDefinition ReadDefinition() bool[] generated = new bool[values.Length]; foreach (ColumnDef column in _table.Columns) - if (column.IsAutoNumber && column.Type != JetDataType.Complex && values[column.Index] is null or DBNull) + if (column.IsAutoNumber && column.Type != JetDataType.Complex + && (values[column.Index] is null or DBNull || CannotHoldTheCounter(column))) { if (column.IsRandomAutoNumber) // "Random" AutoNumber (DefaultValue = GenUniqueID()): a random Int32, independent of the @@ -1249,9 +1262,13 @@ private TableDefinition ReadDefinition() // Seed-Increment, so the first assigned id is the Seed. The addition is deliberately // unchecked: past int.MaxValue the counter wraps to int.MinValue and keeps going, which // is exactly what ACE does (no overflow error exists — see AceAutoNumberOverflowProbeTest). - values[column.Index] = highWater = unchecked(highWater + column.Increment); - generated[column.Index] = true; + highWater = unchecked(highWater + column.Increment); _channel.KeepThroughRollback(_table.DefinitionPage, format.TdefLastAutoNumberOffset, highWater); + if (CannotHoldTheCounter(column)) + throw new InvalidOperationException( + $"The field '{column.Name}' is too small to accept the amount of data you attempted to add."); + values[column.Index] = highWater; + generated[column.Index] = true; } } return generated; @@ -1331,7 +1348,17 @@ private void UpdateTdefCounters(JetFormatBase format, byte[] tdef, object?[] val // a UI-authored Random AutoNumber reads last-value 0). Advancing it would be meaningless (random ids // don't form a monotone sequence) and diverge from Access's on-disk state. if (column.IsRandomAutoNumber) continue; - int assigned = Convert.ToInt32(value, CultureInfo.InvariantCulture); + // The counter is a value's first four bytes. On a Text, OLE or Single column that carries the AutoNumber + // flag — a damaged descriptor — ACE takes them from the UTF-16 text, zero-padded, from the binary value, + // or from the float (measured: "Street" sets 0x14 to 0x00740053, "A" to 65, bytes 01 02 03 04 05 06 to + // 0x04030201, 0.25 to 0x3E800000). + int assigned = value switch + { + string text => (text.Length > 0 ? text[0] : 0) | (text.Length > 1 ? text[1] << 16 : 0), + float single => BitConverter.SingleToInt32Bits(single), + byte[] bytes => bytes.Take(4).Select((b, i) => b << (8 * i)).Aggregate(0, (counter, b) => counter | b), + _ => Convert.ToInt32(value, CultureInfo.InvariantCulture), + }; int highWater = TableDefinition.ReadLastAutoNumber(tdef, format); // An id this insert *generated* always becomes the new high-water: it came from 0x14 + increment, // so it is by construction the next value in the sequence. That includes the wrap past diff --git a/src/LibRed/LibRed.Core/Storage/Table.cs b/src/LibRed/LibRed.Core/Storage/Table.cs index 4b6420d4..dc63680d 100644 --- a/src/LibRed/LibRed.Core/Storage/Table.cs +++ b/src/LibRed/LibRed.Core/Storage/Table.cs @@ -258,7 +258,11 @@ public void Delete(RowId id) Write(() => { object?[] values = GetRow(id, StoredColumns) ?? throw new InvalidOperationException($"Row '{id}' does not exist."); - foreach (ComplexColumn complex in _catalog.LoadComplexColumns(Definition.DefinitionPage)) + // Only a table with a complex column has values elsewhere to remove, so only it asks MSysComplexColumns: + // on a file whose registry is damaged, ACE deletes from any other table as usual (measured). + IEnumerable complexColumns = Definition.Columns.Any(c => c.Type == JetDataType.Complex) + ? _catalog.LoadComplexColumns(Definition.DefinitionPage) : []; + foreach (ComplexColumn complex in complexColumns) { if (values[complex.OwnerTable.RequireColumn(complex.ColumnName).Index] is not { } raw) continue; int recordId = Convert.ToInt32(raw, System.Globalization.CultureInfo.InvariantCulture); diff --git a/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs b/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs index f6469a52..a653ce1a 100644 --- a/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs +++ b/src/LibRed/LibRed.EFCore/Storage/Internal/LibRedRelationalConnection.cs @@ -1,3 +1,7 @@ +using System.Data; +using EntityFrameworkCore.Jet.Infrastructure; +using EntityFrameworkCore.LibRed.Infrastructure; +using EntityFrameworkCore.LibRed.Infrastructure.Internal; using LibRed.Data; namespace EntityFrameworkCore.LibRed.Storage.Internal; @@ -11,5 +15,16 @@ public class LibRedRelationalConnection(RelationalConnectionDependencies depende : RelationalConnection(dependencies), ILibRedRelationalConnection { protected override DbConnection CreateDbConnection() - => new LibRedConnection { ConnectionString = ConnectionString }; + { + var connection = new LibRedConnection { ConnectionString = ConnectionString }; + if (Dependencies.ContextOptions.FindExtension()?.SqlMode == LibRedSqlMode.Compatible) + { + connection.StateChange += (_, e) => + { + if (e.CurrentState == ConnectionState.Open) + JetDualTable.DetectedName = connection.HasDualTable ? LibRedConnection.DualTableName : ""; + }; + } + return connection; + } } \ No newline at end of file diff --git a/src/LibRed/LibRed.Engine/Execution/StatementExecutor.cs b/src/LibRed/LibRed.Engine/Execution/StatementExecutor.cs index f38e65ea..6b8ed92c 100644 --- a/src/LibRed/LibRed.Engine/Execution/StatementExecutor.cs +++ b/src/LibRed/LibRed.Engine/Execution/StatementExecutor.cs @@ -845,13 +845,16 @@ private int RenameColumn(string table, string field, string newName) } /// - /// RENAME INDEX — renames an index; the name lives in the TDEF's index block. If the index backs a foreign - /// key, check its coupling to the relationship name (szRelationship). Access cannot do this through - /// SQL or DAO/ADOX, so there is no ACE oracle for the operation itself — verify via the converged - /// end state (an index created as the new name should match one created then renamed). + /// RENAME INDEX — renames an index; the name lives in the TDEF's logical index block. ACE has no SQL for it, + /// but DAO renames one through Index.Name, and LibRed matches that (see SchemaEditor.RenameIndex). /// - private int RenameIndex(string table, string index, string newName) => throw new NotSupportedException( - $"ALTER TABLE `{table}` RENAME INDEX `{index}` TO `{newName}` is parsed and routed but the TDEF rewrite is not implemented yet."); + private int RenameIndex(string table, string index, string newName) + { + if (!_database.RenameIndex(table, index, newName)) + throw new InvalidOperationException( + $"ALTER TABLE '{table}' RENAME INDEX '{index}' TO '{newName}': the index was not found."); + return 0; + } private int DropConstraint(string table, string name) { diff --git a/src/LibRed/README.md b/src/LibRed/README.md index b314b675..fb50018e 100644 --- a/src/LibRed/README.md +++ b/src/LibRed/README.md @@ -194,13 +194,14 @@ Treat the number as of its date — an EF Core version bump moves it. read back onto the column, and applied when an insert omits the column — **and Access honors them too**. Table-level `CHECK` constraints are persisted to the `LvProp` `CheckConstraints` property (verbatim expression text) and read back onto `TableDefinition.CheckConstraints` — **and Access enforces them**. - From files Access wrote, a relationship's 1:1 flag (`grbit` `0x01`) is read and reported as ONE/MANY by - `INFORMATION_SCHEMA`, and a column's `ValidationRule`/`ValidationText` are read off the same property blob, + A relationship's 1:1 flag (`grbit` `0x01`) is read and reported as ONE/MANY by `INFORMATION_SCHEMA`, and + written through the Core API (`RelationshipSpec.IsOneToOne`) as DAO's `dbRelationUnique` writes it — SQL has no + syntax for it. A column's `ValidationRule`/`ValidationText` are read off the `LvProp` property blob, reported by `INFORMATION_SCHEMA` and kept through a rewrite. - **SQL** — ANTLR front end (parser → binder via `ISchemaProvider` → planner → executor). Statements: `CREATE TABLE`, `CREATE [UNIQUE] INDEX … [WITH {PRIMARY|DISALLOW NULL|IGNORE NULL}]`, `CREATE VIEW`, `CREATE PROCEDURE`, `ALTER TABLE` (ADD/DROP COLUMN, ADD PK/FK/UNIQUE/CHECK, ALTER COLUMN incl. the - byte-faithful in-place type change and `SET`/`DROP DEFAULT`, DROP CONSTRAINT, `RENAME TO`/`RENAME COLUMN`), + byte-faithful in-place type change and `SET`/`DROP DEFAULT`, DROP CONSTRAINT, `RENAME TO`/`RENAME COLUMN`/`RENAME INDEX`), `DROP {TABLE|INDEX|VIEW|PROCEDURE}`, `INSERT` (with AutoNumber) — from `VALUES`, from a multi-row table value constructor, or from a query (`INSERT INTO … SELECT`, the append query) — `SELECT … INTO` (the make-table query), `UPDATE`, `DELETE`, @@ -324,8 +325,6 @@ Format-level detail on each on-disk gap lives in `docs/format/`. - **`ON UPDATE SET NULL`** — pathway threaded but throws; its Jet storage bytes are unverified because the ACE OLE DB provider rejects the DDL (needs a UI/DAO-created sample to probe). -- **1:1 relationships** (`dbRelationUnique` = `0x01`) — never written; a 1:1 migration would render as 1:many - in Access (the unique index still enforces uniqueness). - **`ValidationRule`/`ValidationText` are not enforced** — UI-authored validation, distinct from a SQL `CHECK`: a row violating an Access-authored rule is accepted where ACE would refuse it. - **A column-level `CHECK`** (`Col LONG CHECK (Col > 0)`) is parsed and silently dropped — neither stored nor @@ -340,7 +339,6 @@ Format-level detail on each on-disk gap lives in `docs/format/`. - **Stored pass-through queries** — read back as a *named* refusal rather than executing. - **A crosstab's columns when describing** (`CommandBehavior.SchemaOnly`) — only the row headings and fixed headings, since the rest come from the data. -- **`ALTER TABLE … RENAME INDEX`** — parsed and routed, but throws: the TDEF rewrite is not implemented. - **Function surface** — the evaluator's whitelist isn't proven identical to ACE's JES, and `Format`'s named date/currency formats are locale-dependent by design (not byte-identical cross-locale). - **Single-writer concurrency** — LibRed is a **single-writer engine that merely tolerates extra open diff --git a/src/LibRed/docs/format/page-02a-tdef.md b/src/LibRed/docs/format/page-02a-tdef.md index d885be4e..a5b30916 100644 --- a/src/LibRed/docs/format/page-02a-tdef.md +++ b/src/LibRed/docs/format/page-02a-tdef.md @@ -94,6 +94,22 @@ > it pins `0x14` at `int.MaxValue` forever, so every later insert reissues `int.MinValue` and the table is > wedged — for ACE too, since the damage is the on-disk `0x14`. LibRed therefore applies its monotone guard > (the deliberate KB 884185 immunity) **only to caller-supplied explicit ids**; see `RowInserter`. +> +> **The counter is the first four bytes of the value (verified vs ACE).** A Text column whose descriptor carries +> the AutoNumber flag `0x04` (a damaged file) still opens, reads and takes INSERTs and DELETEs; an UPDATE of the +> column is refused as not updateable. An explicit text value sets `0x14` to the value's first four bytes as UTF-16LE, +> zero-padded: `'Street'` → `0x00740053`, `'500'` → `0x00300035`, `'A'` → `65`. A generated id goes the other way — +> with the flag byte `0x06` the id's four bytes are stored as two characters (`0x00740054` → `'Tt'`); with `0xEE` +> (`0x40` set as well) ACE stores `'\x01\0'` and resets `0x14` to `1`. LibRed matches the explicit case only. +> On an OLE column flagged the same way the counter likewise takes a binary value's first four bytes: `01 02 03 04 +> 05 06` → `0x04030201`. With the table's own AutoNumber (`Categories.CategoryID`) beside it, an `INSERT` that +> leaves that column out is refused *"You must enter a value in the 'Categories.CategoryID' field"*, its id +> burned, and a one-byte binary value left `0x14` at the explicit `CategoryID` rather than taking the byte. +> On a fixed column the width decides: a 4-byte `Single` takes its own bits (`0.25` → `0x3E800000`), while an +> `Integer`, `Currency` or `Date/Time` column refuses the row, explicit value and all, with *"The field is too +> small to accept the amount of data you attempted to add."* and `0x14` advanced by one — the id is drawn and +> burned. DAO refuses to create the flag on a GUID column at all (`dbAutoIncrField` on `dbGUID`: *"Invalid +> argument"*). > **Reader/writer count guardrails.** LibRed validates the documented 255-column and 32-real-index > limits before allocating count-sized structures, rejects negative logical/real index counts, and checks @@ -252,6 +268,14 @@ the documented 255-column, 32-index, and 64-character-name limits. > the first page's `0x04` next pointer is zeroed and it follows the single-page rule below (8 bytes zeroed > past the new end, the rest left); a definition growing onto a second page keeps its first page and takes a > fresh continuation. LibRed's `TableDefinition.WriteChain` does all of this. +> +> **Renaming an index (verified vs ACE).** The index's name entry is replaced, and its logical block moves with +> it to where the new name sorts (§3.3, name order); the info block's bytes are unchanged, `index_num` +> included. ACE writes the renamed definition **twice**, the same bytes both times. A single-page definition is +> rewritten in place, so the second write changes nothing; a multi-page one's continuations take the lowest +> free pages and then, since the first copy's pages are held until the statement ends, pages past them — from +> free pages `56, 55` at the end of a 60-page file, `first → 56 → 55` and then `first → 61 → 60`, the first +> copy left on its released pages. ### 3.3 Body layout (in order, after the header) @@ -282,6 +306,15 @@ the documented 255-column, 32-index, and 64-character-name limits. > FOREIGN KEY` is refused when the table already has an index of that name — *"Table 'FkC' already has an index > named 'Taken'."* > +> A stored column name that holds a control character (U+0003, verified) still reads: the table opens and +> `SELECT *` names the column as stored. Only the DDL refuses it, so a column renamed away from that name (DAO's +> `Field.Name`) cannot be given it back — *"'…' is not a valid name."* +> +> Two columns stored under one name (verified, one name entry damaged into another's) still read. A lookup by +> that name resolves to the first of them: `SELECT` of the name reads the first column's value, `SELECT *` lists +> both as `Table.name`, and `CREATE INDEX` over the name indexes the first. `ADD COLUMN` of the name is refused, +> *"Field '…' already exists in table '…'."* +> > LibRed enforces all of this on caller-supplied names via `JetName.Validate`, since writing the format > directly bypasses ACE's DDL parser. Internal hidden names (the `.rN` incoming-relationship index names, §3.6) > legitimately start with `.` and are **not** validated. diff --git a/src/LibRed/docs/format/page-02b-columns.md b/src/LibRed/docs/format/page-02b-columns.md index 2a6e11ef..9f3af419 100644 --- a/src/LibRed/docs/format/page-02b-columns.md +++ b/src/LibRed/docs/format/page-02b-columns.md @@ -6,7 +6,7 @@ | Offset | Size | Meaning | | --- | --- | --- | -| `0x00` | 1 | Data type (see §6) | +| `0x00` | 1 | Data type (see §6). A code no type has does not refuse the table outright (verified): with `0x0D` or `0x0E` the table opens and counts, and only a read of that column fails — OLE DB's conversion errors, or *"Data type mismatch in criteria expression"* in a `WHERE`; with `0x15` everything that loads the table is *"Unrecognized database format"*. On `MSysRelationships.szColumn` (`0x0D`) every table still lists and reads and unrelated DDL runs, but the foreign-key list fails *"Cannot perform this operation"*; LibRed refuses reading the relationships the same way | | `0x01` | 2 | Minimum engine build for the column, the low half of a 32-bit value (`0x03` is the high half) — `0x0659` as ACE and Jet 4.0 write it; each refuses the table when it exceeds its own build, 4518 and 9801 ([page-02a §3.1](page-02a-tdef.md) note) | | `0x03` | 2 | The high half of the minimum-build field at `0x01`, which is 32 bits: non-zero here puts the build past ACE's, and ACE refuses the table — *"This object requires a newer version of the Microsoft Access database engine"* (verified). Write zero | | `0x05` | 2 | Column id | @@ -41,14 +41,21 @@ normally, but a compact drops the column, every column after it and every row of > computed and stored, on an insert and on an update of a column it reads, while a Text or Memo one refuses both > (*"Error evaluating CHECK constraint."*). An update that touches none of its inputs, and a delete, go through > either way. A column with `0x40` and no expression at all fails before that, the table refusing to open -> (*"Property not found"*), and a compact drops it. `0x80` alone does nothing: the column is an ordinary one, and +> (*"Property not found"*), and a compact drops it — fixed-length or variable, everything that loads that table +> fails so, its column schema included, while the table list and the other tables still read. On a **catalog** +> table it depends which: `0x40` on any `MSysObjects` column, fixed or variable, and the database itself will not +> open (*"Invalid database object reference."*); on `MSysRelationships` the foreign-key list fails *"Property not +> found"* as a user table's reads do; on `MSysQueries` the database opens and lists no views at all. `0x80` alone +> does nothing: the column is an ordinary one, and > the bit goes at the next TDEF rewrite. A broken expression does not clear `0x80` — after `DROP COLUMN` of a > column it reads, the flags stay `0xC0` and the error comes from the expression itself. Extended bit `0x02` is > ignored and kept, through a rewrite and a compact alike. > > LibRed reads `0x40` as calculated and writes `0xC0`, as ACE does, and over `0x40` alone reads, writes, updates > and deletes as ACE does (`ColumnDef.EvaluatesExpression`). An update or delete never reads a calculated -> result, which is also what lets it rewrite a row whose result is a cached error. +> result, which is also what lets it rewrite a row whose result is a cached error. A calculated column with no +> `Expression` property refuses its table's definition, and one in `MSysObjects` refuses the catalog, both as +> `InvalidDataException`; a damaged `MSysQueries` refuses too, where ACE lists no views. > > **Extended flags beyond `0x01`/`0xC0` belong to the complex columns (verified where set).** `0x10` is set on > exactly the six attachment value columns — `FileData`, `FileFlags`, `FileName`, `FileTimeStamp`, `FileType`, @@ -355,6 +362,16 @@ column's rank among the variable columns ordered by ascending id. > read the dropped column's value). Why the gap is left, and what it means for writing a row rather than > reading one, are [§3.1](page-02a-tdef.md#31-header) and [§5](page-01-data-and-rows.md) respectively. +> **Two live columns naming one slot.** ACE does not check that variable indexes are distinct (verified on +> Northwind's `Customers` with `City`'s index set to `CompanyName`'s, 0): the table opens and reads, and `City` +> reads the company name, cut to `City`'s declared 15 characters in a `SELECT`. A write of `City` with that +> value is refused as too large for the field, an update of another column succeeds, and an insert writes both +> columns through the one slot, the later value winning. An index on `City` still holds each row under its +> real city, so a write that has to move or remove that entry fails as the index section's missing-entry case +> ([§10.4a](page-03-04-index-btree.md#104a-entry-removal--a-leaf-is-rewritten-not-repacked)). LibRed opens +> and reads the table and refuses the same writes, but returns `City` whole (19 characters); whether ACE's cut +> is the engine's or the OLE DB column binding's is not established. + #### Declared width limits Two limits bind a declaration, both enforced by ACE when it **opens the file**, so writing past either diff --git a/src/LibRed/docs/format/page-02d-constraints.md b/src/LibRed/docs/format/page-02d-constraints.md index ca55ed85..5116c463 100644 --- a/src/LibRed/docs/format/page-02d-constraints.md +++ b/src/LibRed/docs/format/page-02d-constraints.md @@ -253,7 +253,8 @@ physical (data-block) index, prefer a real index's name over a foreign-key relat > and a relationship's child index — whichever of a pair came first, and inside one `CREATE TABLE` as well. A > flag or a column apart keeps them apart: plain beside unique, `IGNORE NULL` or `DISALLOW NULL`, ascending beside > descending, a relationship beside a `UNIQUE` or the primary key over its column, a column list beside a prefix -> of it. Dropping one of the names — `DROP INDEX`, or `DROP CONSTRAINT` for a relationship — takes only its +> of it. A **one-to-one** relationship's child index is unique (`0x81`), so it is the `UNIQUE` index over its +> columns that it shares, and it still keeps apart from the primary key (`0x89`) over them (verified vs DAO). Dropping one of the names — `DROP INDEX`, or `DROP CONSTRAINT` for a relationship — takes only its > logical block and name; the data block, its statistics and its B-tree stay with the name that is left > (verified). In a `CREATE TABLE` the constraint declared later is the one that shares: it takes no usage-map > row and no root, so the rows and roots go to the others in declaration order as if it were not there diff --git a/src/LibRed/docs/format/page-03-04-index-btree.md b/src/LibRed/docs/format/page-03-04-index-btree.md index 3d0197e3..513c460c 100644 --- a/src/LibRed/docs/format/page-03-04-index-btree.md +++ b/src/LibRed/docs/format/page-03-04-index-btree.md @@ -691,10 +691,11 @@ to `n` bytes, as page-01 stores it. LibRed builds the row and every key from one `ll`+`ll`. **Only Hungarian doubles** — a doubled digraph is written by doubling its first letter, so `ggy` is `gy`+`gy` (`56 03 56 03`) and `ssz` is `sz`+`sz`, while Czech `cch` is plainly `c`+`ch` (`4D 58 03`) and Spanish `cch` is `c`+`ch`. Doubling has to be tested *before* the plain longest match, - or `ggy` degrades to `g`+`gy`. **Case breaks a contraction** where a lowercase letter is followed by an - uppercase one inside it, and the match falls to a shorter one: `cS`, `sZ`, `gY`, `cH`, `lL`, `lJ` and `dŽ` - are two letters each, Hungarian `dzS` is `dz`+`S` and `dZs` is `d`+`zs` — while `Cs`, `CS`, `Ch`, `Lj` and - `Dž` contract, and so does a doubled `cCs` (verified in every digraph order). A contraction can carry a secondary of its own: Croatian `dž` is + or `ggy` degrades to `g`+`gy`. **A contraction matches only in lowercase, uppercase or title case**; any + other case mix falls to a shorter match: `cS`, `sZ`, `gY`, `cH`, `lL`, `lJ` and `dŽ` are two letters each, + Hungarian `dzS` is `dz`+`S`, `dZs` is `d`+`zs` and `DZs` is `DZ`+`s` — while `Cs`, `CS`, `Ch`, `Lj`, `Dž`, + `Dzs` and `DZS` contract, and so does a doubled `cCs`; a doubled `dDZs` is `dz`+`dz`+`s` (verified in every + case mix of every contraction). A contraction can carry a secondary of its own: Croatian `dž` is `50 04` with secondary `04`, Danish `aa` is `å`'s primary with secondary `03`. - **Expansion** — one character, several primaries. German Phone Book: `ä` = `7F 4A 51 01 00`, primaries `a`+`e` (General has `a` + umlaut secondary); likewise `ö`→`o`+`e`, `ü`→`u`+`e`. Same primitive as @@ -970,6 +971,13 @@ packing: where the prefix is longer than the key, there are no key bytes left to Both engines then agree byte for byte: LibRed touches no page ACE does not (verified). +> **An entry the row says is there, and is not.** The entry to remove is found by the key the row's stored +> values encode to. When the index holds the row under another key — the file's index and table disagree — +> ACE refuses the `UPDATE` that would move the entry, and the `DELETE` that would remove it, with *"The search +> key was not found in any record."* and changes nothing (verified, on a `Customers` row whose `City` reads +> another column's slot, §3 of [page-02b](page-02b-columns.md)). LibRed refuses both with +> `InvalidDataException` and rolls the statement back. + ### 10.4d A leaf the removal empties leaves the tree An underfull leaf is left alone (§10.4a), but a leaf whose **last** entry is removed is taken out of the tree diff --git a/src/LibRed/docs/format/page-05-usage-maps.md b/src/LibRed/docs/format/page-05-usage-maps.md index 1c31bad4..97ae795e 100644 --- a/src/LibRed/docs/format/page-05-usage-maps.md +++ b/src/LibRed/docs/format/page-05-usage-maps.md @@ -234,6 +234,40 @@ the opening user's commit slot at close, and every later open fails with *"Unrec A far larger page number is refused on the first open — from page 524,289 exactly, as measured on `0x1C`. Only the page is checked on open — any row byte passes — but a `0x18` naming a record that is not a usage map (page 0, a TDEF page, an ordinary data page) fails at the first allocation and damages the database. +Aimed at a long-value row instead — row 0 of a 4,076-byte value, whose bytes read as an inline map starting at +page 352,321,631 — the database opens and reads, and every statement needing a page fails *"Cannot open database +''"* with the file left as it was: no page added, the long value untouched. An `INSERT` that had drawn its +AutoNumber keeps it burned (verified). LibRed refuses to grow the file to any page past the 2 GiB limit, which +refuses this one at the same point. + +**ACE does not look at the page the free map gives it (verified).** A `0x18` naming a table's own owned-pages +map makes that table's pages free, and so does the page's bit set in the real free map; either way ACE allocates +the page and writes over it. That held for a user table's page, a system table's, a page of the table the +statement itself reads and writes, and one the connection had just scanned — a `CREATE TABLE` writes its +definition there, an `INSERT` needing a long-value page writes one, and the rows on it are lost to a scan while +`COUNT(*)` still answers from the TDEF's row count. + +Only some statements fail, and only on some tables' pages: + +- **`CREATE TABLE`** fails when it took a page of `MSysObjects` or `MSysACEs` — the two tables it inserts rows + into — with the write-conflict error ("…you and another user are attempting to change the same data at the + same time"). The page and the file are left intact. Taking a page of `MSysQueries` or `MSysRelationships`, + which it writes nothing to, succeeds. +- **An `INSERT` writing a long value** fails with *"Unrecognized database format"* when the page it took is the + `MSysObjects` page holding its own table's row, or the one holding the database's and containers' rows (with + `MSysDb`). It fails after drawing the AutoNumber and before writing the row, leaves the page as it was, and + the file does not open again. Reading the table or its columns, or inserting a short row into it, on the same + connection first changes nothing. The same `INSERT` taking another `MSysObjects` page succeeds and writes its + long value over the catalog rows there, as does one taking a page of `MSysACEs` or `MSysRelationships`; so does + an `INSERT` that needs only data pages, onto any catalog page, its own table's row's included. Which of the + first page's rows the long-value write goes back to is not established. + +So ACE has no check that keeps a live page out of allocation; a statement fails when it goes back to the table +whose page it took. LibRed allocates the same way. Where its statement goes back to such a page through a read +that checks the page — `CREATE TABLE` inserting its catalog row on the `MSysObjects` page it has just made a +definition — it refuses with `InvalidDataException` and rolls back, leaving the file intact as ACE does. Which +page each engine takes, and what each goes back to, differ, so the two do not fail on the same cases: the +`INSERT` that takes an `MSysObjects` page succeeds in LibRed and leaves the catalog damaged. **Freed pages are released at close, through the released-pages map.** Most pages freed during a session are not reusable on the same connection: later allocations in that session grow the file instead, and the free map on @@ -279,6 +313,10 @@ An inline record that already covers them stays as it is. Otherwise, in order of end and the vacated bytes are not cleared, so the long record's bitmap stays on the page below the new one. +An inline record whose start page is below 0 is not sized at all: with start page -2,147,483,648 and no bits set, +releasing three pages and closing leaves the record as it was and merges the pages into the free map exactly as +on the undamaged file (verified). + A map already in reference form gains a bitmap page, allocated the same way, for each range holding a released page that it has none for — a released table-definition page among the free pages is taken like any other, its type becoming `0x0105`. The merge then clears every bitmap page, each keeping its 4-byte header. diff --git a/src/LibRed/docs/format/system-catalog.md b/src/LibRed/docs/format/system-catalog.md index f905ffdd..79f29dfa 100644 --- a/src/LibRed/docs/format/system-catalog.md +++ b/src/LibRed/docs/format/system-catalog.md @@ -51,6 +51,13 @@ The last column lists what a row of that kind *can* carry, not what every one does: a query or relationship written by ACE or LibRed leaves `LvProp` null (below), where Access fills it. + > **A table's row with a null `Id`, `Name` or `Flags`** (measured, by clearing the column's null-bitmap bit). + > The database still opens. A null **`Flags`** is no flags: the table reads as usual, and `MSysQueries`, its + > system bit gone, is listed as a `TABLE`. A null **`Id`** leaves the table listed but unreadable — *"Unrecognized + > database format"* — and on `MSysQueries` leaves no views at all. A null **`Name`** fails the table list + > (`E_FAIL`). LibRed reads a null `Flags` as `0` and refuses a table whose row has no `Id` or `Name` as + > `InvalidDataException`. + > **A name is unique within its container, and only there.** That is the rule the unique `(ParentId, Name)` > index states, and the one ACE applies (verified, case-insensitively): a new table (`CREATE TABLE`, > `SELECT … INTO`, a rename) or query (`CREATE VIEW` / `CREATE PROCEDURE`) is refused when a table, query or @@ -837,6 +844,13 @@ single-column FK stores `ccolumn = 1`, `icolumn = 0`, `grbit = 0`; a relationship cascading both update and delete stores `grbit = 0x1100`; Access's relationship dialog writes each bit above as its option says. + > **A relationship row with a null column** (measured, by clearing one column's null-bitmap bit in one row). The + > database opens, every table reads and DDL runs. The foreign-key list leaves out the relationship whose row has + > a null `szObject` or `szReferencedObject`, and lists it all the same with a null `szRelationship`, `szColumn`, + > `icolumn` or `grbit`. LibRed reads the relationships the same way. A column of another type than its own — a + > damaged type byte — fails the foreign-key list instead, *"Cannot perform this operation"*, and LibRed refuses + > the relationships as `InvalidDataException` ([page-02b §3.4](page-02b-columns.md)). + > **`grbit` records the relationship; ACE does not act on its cascade bits.** The update and delete actions > ACE applies are the ones in the relationship's index-info blocks (§3.6, `0x15`/`0x16`): with the two made > to disagree, a parent delete that `grbit` calls cascading but the blocks do not is refused, and one the @@ -848,7 +862,13 @@ > are unique. On an **enforced** relationship the child's backing index is created **unique** with it, and > non-unique without it even when the child column is the table's primary key. What ACE then enforces is > that index's unique flag (page-02d §3.5, `0x2E`), not this bit: made to disagree, ACE follows the flag - > (verified vs ACE). The bit is what Access and DAO report as the relationship's type. + > (verified vs ACE). The bit is what Access and DAO report as the relationship's type. A one-to-one differs + > from the same one-to-many in those two places only — `0x01` on every row of the key, and `0x81` for `0x80` on + > the child index — and DAO's one-to-many is byte-identical to SQL's `FOREIGN KEY` (verified). DAO refuses a + > one-to-one over child rows that already share a key (*"…would create duplicate values in the index, primary + > key, or relationship…"*); rows whose key is null do not collide. The refusal comes after the relationship's + > `MSysObjects` object and its `MSysACEs` rows are written, so their rollback leaves those two tables' + > counting behind (page-02a §3.1) and nothing else (verified, whole-file diff). > **Writing a relationship.** An **enforced** relationship is `MSysRelationships` rows, an `MSysObjects` > row of its own (`Type` = 8, under the relationship container, with the `MSysACEs` rows that container @@ -906,6 +926,14 @@ > renamed**, which cannot collide with itself: ACE allows renaming a table to its own name, and allows a > case-only change (both verified). The self-rename case is not hypothetical — EF models "move a table to > another schema" as a rename, and on a schema-less engine that degrades to `RENAME TO` the *same* name. + > + > **Renaming an index (verified, through DAO's `Index.Name` — ACE has no SQL for it).** Only the table's + > definition changes; this table names no index. A primary key renames even while a relationship references + > it, the parent's incoming block untouched. Two renames are refused, leaving the file as it was: the index a + > relationship created on its child table (named after the relationship) — *"Cannot delete this index or table. + > It is either the current index or is used in a relationship."* — and a name another index of the table has — + > *"Index already exists."* A case-only change is the same index, and renames. The definition rewrite is in + > [page-02a](page-02a-tdef.md) §3.2. - **MSysNameMap** is Access's **Name AutoCorrect** map: for each object Access tracks, the names it and the objects it depends on had when the map was last written. Five columns, no indexes: `GUID` (GUID), `Id` @@ -977,7 +1005,9 @@ Four layers — the user table, then three kinds of ordinary hidden/system table 2. **`MSysComplexColumns`** maps each complex column to its backing table: `(ColumnName, ComplexID, ComplexTypeObjectID, ConceptualTableID, FlatTableID)`. E.g. `Attachments | 3 | 39 | 79 | 150` = the `Attachments` column of table `79`, element type **39** - (`MSysComplexType_Attachment`), backed by flat table **150** = `f__Attachments`. + (`MSysComplexType_Attachment`), backed by flat table **150** = `f__Attachments`. A write to a table + with no `Complex` column does not depend on it: with `ConceptualTableID`'s type byte damaged from Long to + Byte, ACE inserts, updates and deletes rows of such a table as usual (verified). 3. **`MSysComplexType_*`** — nine schema templates, one per element subtype, matching the DAO `dbComplex*` codes: `UnsignedByte, Short, Long, IEEESingle, IEEEDouble, GUID, Decimal, Text, Attachment`. `MSysComplexType_Attachment` = `FileData:Ole, FileFlags:Int32, FileName:Text, FileTimeStamp:DateTime, diff --git a/test/EFCore.Jet.Data.Tests/RenameFanOutProbeTest.cs b/test/EFCore.Jet.Data.Tests/RenameFanOutProbeTest.cs index 259896f9..4c964194 100644 --- a/test/EFCore.Jet.Data.Tests/RenameFanOutProbeTest.cs +++ b/test/EFCore.Jet.Data.Tests/RenameFanOutProbeTest.cs @@ -211,6 +211,59 @@ CREATE TABLE DocChild (Id INT NOT NULL CONSTRAINT PK_DocChild PRIMARY KEY, DocId Assert.IsFalse(ViewResolves("vwDoc"), "The view still resolves — ACE rewrote the stored query."); } + /// + /// The index-rename counterpart, through the intercepted DAO path. Measured against ACE + /// (RenameIndexDaoProbeTest): a plain index and a primary key rename — the key in place even while a + /// relationship references it — but the index a relationship created on its child table is refused, as is + /// a name another index of the table has. + /// + [TestMethod] + public void Probe_what_an_index_rename_does() + { + string plain = TryRenameIndex("Parent", "IX_Parent_Name", "IX_Parent_Name_Renamed"); + string key = TryRenameIndex("Parent", "PK_Parent", "PK_Parent_Renamed"); + string relationship = TryRenameIndex("Child", "FK_Child_Parent", "FK_Child_Parent_Renamed"); + string taken = TryRenameIndex("Child", "PK_Child", "FK_Child_Parent"); + + ReOpenConnection(); + + Report($"rename plain index : {plain}"); + Report($"rename referenced key : {key}"); + Report($"rename FK's own index : {relationship}"); + Report($"rename onto taken name : {taken}"); + ReportIndexes(); + ReportRelations(); + + Assert.AreEqual("ALLOWED (no error)", plain); + Assert.IsTrue(IndexExists("Parent", "IX_Parent_Name_Renamed"), "The plain index was not renamed."); + Assert.IsFalse(IndexExists("Parent", "IX_Parent_Name"), "The old index name still resolves."); + + Assert.AreEqual("ALLOWED (no error)", key); + Assert.IsTrue(IndexExists("Parent", "PK_Parent_Renamed"), "The primary key was not renamed."); + Assert.AreEqual("True", RelationValue("FK_Child_Parent", "IS_ENFORCED"), ignoreCase: true, + "The relationship lost its enforcement when its referenced key was renamed."); + + Assert.IsTrue(relationship.StartsWith("REJECTED"), $"ACE renamed a relationship's own index: {relationship}"); + Assert.IsTrue(IndexExists("Child", "FK_Child_Parent"), "The relationship's index lost its name."); + + Assert.IsTrue(taken.StartsWith("REJECTED"), $"ACE renamed an index onto a name another index has: {taken}"); + Assert.IsTrue(IndexExists("Child", "PK_Child"), "The primary key lost its name."); + } + + private string TryRenameIndex(string table, string from, string to) + { + try + { + using var command = _connection.CreateCommand($"ALTER TABLE `{table}` RENAME INDEX `{from}` TO `{to}`"); + command.ExecuteNonQuery(); + return "ALLOWED (no error)"; + } + catch (Exception e) + { + return $"REJECTED — {e.GetType().Name}: {e.GetBaseException().Message.ReplaceLineEndings(" ")}"; + } + } + /// A single field of the named relationship's column mapping, or null if it is gone. private string RelationColumnValue(string relationName, string columnName) { diff --git a/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs index 94ca63bd..57a085f0 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/AdHocQueryFiltersQueryJetTest.cs @@ -509,20 +509,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..9a7ede1d --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionJetTest.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionJetTest( + ComplexTableSplittingJetFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs new file mode 100644 index 00000000..94788daa --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateJetTest.cs @@ -0,0 +1,158 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateJetTest(NavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [n] +SET [n].[String] = @p +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..c617fdbf --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionJetTest(NavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..b2b1a5db --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionJetTest(OwnedNavigationsJetFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs new file mode 100644 index 00000000..55ea789e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionJetTest.cs @@ -0,0 +1,152 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionJetTest( + OwnedTableSplittingJetFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..83156949 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryJetFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..f3fd8f84 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryJetTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryJetTest(TPCInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [u].[ParentComplexType] +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..b6524226 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,175 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryJetTest(TPCInheritanceQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..bcc605cd --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryJetFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..b616a6f3 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryJetTest.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryJetTest(TPHInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..0f5b3d4a --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,125 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryJetTest( + TPHInheritanceQueryJetFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs new file mode 100644 index 00000000..2a028733 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryJetFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs new file mode 100644 index 00000000..57d513b7 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryJetTest.cs @@ -0,0 +1,145 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryJetTest(TPTInheritanceJsonQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs new file mode 100644 index 00000000..ebb2fe47 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryJetTest.cs @@ -0,0 +1,148 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryJetTest( + TPTInheritanceQueryJetFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs new file mode 100644 index 00000000..92b9a42e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Query/Translations/JsonTranslationsJetTest.cs @@ -0,0 +1,70 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Query.Translations; + +public class JsonTranslationsJetTest : JsonTranslationsRelationalTestBase< + JsonTranslationsJetTest.JsonTranslationsQueryJetFixture> +{ + public JsonTranslationsJetTest(JsonTranslationsQueryJetFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryJetFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs b/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs new file mode 100644 index 00000000..bb566d41 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/RuntimeMigrationJetTest.cs @@ -0,0 +1,20 @@ +using EntityFrameworkCore.Jet.Design.Internal; +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Reflection; + +namespace EntityFrameworkCore.Jet.FunctionalTests; + +public class RuntimeMigrationJetTest(RuntimeMigrationJetTest.RuntimeMigrationJetFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(JetDesignTimeServices).Assembly; + + public class RuntimeMigrationJetFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs b/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs new file mode 100644 index 00000000..0b9a1e9a --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/JetTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types; + +public abstract class JetTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => JetTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs new file mode 100644 index 00000000..56873c3e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetBoolTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetBoolTypeTest(JetBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(1 AS bit) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : JetTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs new file mode 100644 index 00000000..863ddbbe --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetByteArrayTypeTest.cs @@ -0,0 +1,220 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetByteArrayTypeTest(JetByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 8000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : JetTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs new file mode 100644 index 00000000..fac28920 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetGuidTypeTest.cs @@ -0,0 +1,227 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetGuidTypeTest(JetGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '8f7331d6-cde9-44fb-8611-81fff686f280' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : JetTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs new file mode 100644 index 00000000..e21ef4da --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Miscellaneous/JetStringTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Miscellaneous; + +public class JetStringTypeTest(JetStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = N'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 4000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : JetTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs new file mode 100644 index 00000000..c6669c59 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetByteTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetByteTypeTest(JetByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(0 AS tinyint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : JetTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs new file mode 100644 index 00000000..0a889371 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetDecimalTypeTest(JetDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : JetTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs new file mode 100644 index 00000000..63530063 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetDoubleTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetDoubleTypeTest(JetDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5E0 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : JetTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs new file mode 100644 index 00000000..1d58b760 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetFloatTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetFloatTypeTest(JetFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(30.5 AS real) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : JetTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs new file mode 100644 index 00000000..b91e050c --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetIntTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetIntTypeTest(JetIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : JetTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs new file mode 100644 index 00000000..cdf0ab18 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetLongTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetLongTypeTest(JetLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-9223372036854775808 AS bigint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : JetTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs new file mode 100644 index 00000000..07bc9f7e --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Numeric/JetShortTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Numeric; + +public class JetShortTypeTest(JetShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-32768 AS smallint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : JetTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs new file mode 100644 index 00000000..a20b0e83 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateOnlyTypeTest(JetDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='05/03/2022' (DbType = Date) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : JetTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs new file mode 100644 index 00000000..dbdd8eb8 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTime2TypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTime2TypeTest(JetDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : JetTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..cb95f948 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeOffsetTypeTest.cs @@ -0,0 +1,241 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTimeOffsetTypeTest( + JetDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000+02:00' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T12:30:45.0000000+03:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : JetTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs new file mode 100644 index 00000000..b15753ba --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetDateTimeTypeTest.cs @@ -0,0 +1,229 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetDateTimeTypeTest(JetDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : JetTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs new file mode 100644 index 00000000..f6a1869c --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetTimeOnlyTypeTest(JetTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00' (DbType = Time) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : JetTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs new file mode 100644 index 00000000..9cd8be76 --- /dev/null +++ b/test/EFCore.Jet.FunctionalTests/Types/Temporal/JetTimeSpanTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.Jet.FunctionalTests.Types.Temporal; + +public class JetTimeSpanTypeTest(JetTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : JetTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs new file mode 100644 index 00000000..6d71acb6 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Context.cs @@ -0,0 +1,27 @@ +using System.Data.Common; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + public class Context : DbContext + { + public Context(DbConnection connection) : + base(TestBase.GetContextOptions(connection)) + { + TestBase.TryCreateTables(this); + } + + public DbSet Table { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity
( + b => + { + b.Property(x => x.Text).HasColumnType("longchar"); + b.Property(x => x.Binary).HasColumnType("longbinary"); + b.ComplexProperty(x => x.Document, d => d.ToJson()); + }); + } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs new file mode 100644 index 00000000..5e52518a --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/JetTest.cs @@ -0,0 +1,19 @@ +using System.Data.Common; +using System.Data.Odbc; +using EntityFrameworkCore.Jet.Data; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + [TestClass] + public class Model80_LongValuesOverOdbc : Test + { + // ODBC explicitly: the bug is the Access ODBC driver's, so the test must not follow the default provider. + protected override DbConnection GetConnection(string storeName) + { + var connection = new JetConnection(Helpers.CreateJetDatabase(storeName), OdbcFactory.Instance); + connection.Open(); + return connection; + } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs new file mode 100644 index 00000000..6aba3250 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Table.cs @@ -0,0 +1,15 @@ +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + public class Table + { + public int Id { get; set; } + public string Text { get; set; } + public byte[] Binary { get; set; } + public Document Document { get; set; } + } + + public class Document + { + public string Body { get; set; } + } +} diff --git a/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs new file mode 100644 index 00000000..428a89a9 --- /dev/null +++ b/test/EFCore.Jet.IntegrationTests/Model80_LongValuesOverOdbc/Test.cs @@ -0,0 +1,85 @@ +using System.Data.Common; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EntityFrameworkCore.Jet.IntegrationTests.Model80_LongValuesOverOdbc +{ + // The Access ODBC driver refuses a string parameter longer than 255 characters, and a binary one longer than + // 510 bytes, with HY104 "Invalid precision value" unless it is bound as a long type (GitHub issue #306). + public abstract class Test + { + // One database per test method: MSTest runs them in parallel. + protected abstract DbConnection GetConnection(string storeName); + + [TestMethod] + public void Model80_LongValuesOverOdbc_Insert() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Insert.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add( + new Table + { + Text = new string('a', 256), + Binary = Enumerable.Range(0, 511).Select(i => (byte)i).ToArray(), + Document = new Document { Body = new string('b', 300) } + }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + Assert.AreEqual(new string('a', 256), row.Text); + CollectionAssert.AreEqual(Enumerable.Range(0, 511).Select(i => (byte)i).ToArray(), row.Binary); + Assert.AreEqual(new string('b', 300), row.Document.Body); + } + } + + [TestMethod] + public void Model80_LongValuesOverOdbc_Update() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Update.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add(new Table { Text = "short", Binary = [1, 2, 3], Document = new Document { Body = "short" } }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + row.Text = new string('a', 300); + row.Binary = new byte[8001]; + row.Document = new Document { Body = new string('b', 300) }; + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var row = context.Table.Single(); + Assert.AreEqual(new string('a', 300), row.Text); + Assert.AreEqual(8001, row.Binary.Length); + Assert.AreEqual(new string('b', 300), row.Document.Body); + } + } + + [TestMethod] + public void Model80_LongValuesOverOdbc_Where() + { + using var connection = GetConnection("Model80_LongValuesOverOdbc_Where.accdb"); + using (var context = new Context(connection)) + { + context.Table.Add(new Table { Text = new string('a', 300), Document = new Document { Body = "x" } }); + context.Table.Add(new Table { Text = "short", Document = new Document { Body = "y" } }); + context.SaveChanges(); + } + + using (var context = new Context(connection)) + { + var value = new string('a', 300); + Assert.AreEqual(1, context.Table.Count(x => x.Text == value)); + } + } + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs index c6169e1e..38eb490b 100644 --- a/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs @@ -511,20 +511,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..178ca109 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,102 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionLibRedTest( + ComplexTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs new file mode 100644 index 00000000..75c3ab7b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs @@ -0,0 +1,156 @@ +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 255) + +UPDATE `RootEntity` AS `r` +INNER JOIN `AssociateType` AS `a` ON `r`.`RequiredAssociateId` = `a`.`Id` +INNER JOIN `NestedAssociateType` AS `n` ON `a`.`RequiredNestedAssociateId` = `n`.`Id` +SET `n`.`String` = @p +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..fca96458 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..d0d3ccde --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionLibRedTest(OwnedNavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..eb7c7174 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,152 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionLibRedTest( + OwnedTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..a856cb33 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..b10da1aa --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,181 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedTest(TPCInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`ParentComplexType` +FROM ( + SELECT `d`.`ParentComplexType` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`ParentComplexType` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`ParentComplexType` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`ParentComplexType` + FROM `Tea` AS `t` +) AS `u` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..4b6dfe40 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,175 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryLibRedTest(TPCInheritanceQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ComplexTypeCollection`, `c`.`Int`, `c`.`UniqueInt`, `c`.`NestedInt`, `c`.`NestedComplexType_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +WHERE `c`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`Id`, `u`.`SortIndex`, `u`.`CaffeineGrams`, `u`.`CokeCO2`, `u`.`Ints`, `u`.`SugarGrams`, `u`.`LiltCO2`, `u`.`SugarGrams1`, `u`.`CaffeineGrams1`, `u`.`HasMilk`, `u`.`ComplexTypeCollection`, `u`.`ParentComplexType_Int`, `u`.`ParentComplexType_UniqueInt`, `u`.`ParentComplexType_Nested_NestedInt`, `u`.`ParentComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int`, `u`.`ChildComplexType_UniqueInt`, `u`.`ChildComplexType_Nested_NestedInt`, `u`.`ChildComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int1`, `u`.`ChildComplexType_UniqueInt1`, `u`.`ChildComplexType_Nested_NestedInt1`, `u`.`ChildComplexType_Nested_UniqueInt1`, `u`.`Discriminator` +FROM ( + SELECT `d`.`Id`, `d`.`SortIndex`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Drink' AS `Discriminator` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`ComplexTypeCollection`, `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Coke' AS `Discriminator` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`Id`, `l`.`SortIndex`, `l`.`ComplexTypeCollection`, `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, `l`.`LiltCO2`, `l`.`SugarGrams` AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Lilt' AS `Discriminator` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`Id`, `t`.`SortIndex`, `t`.`ComplexTypeCollection`, `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, `t`.`CaffeineGrams` AS `CaffeineGrams1`, `t`.`HasMilk`, `t`.`ChildComplexType_Int` AS `ChildComplexType_Int1`, `t`.`ChildComplexType_UniqueInt` AS `ChildComplexType_UniqueInt1`, `t`.`ChildComplexType_Nested_NestedInt` AS `ChildComplexType_Nested_NestedInt1`, `t`.`ChildComplexType_Nested_UniqueInt` AS `ChildComplexType_Nested_UniqueInt1`, 'Tea' AS `Discriminator` + FROM `Tea` AS `t` +) AS `u` +WHERE `u`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ComplexTypeCollection`, `c`.`Int`, `c`.`UniqueInt`, `c`.`NestedInt`, `c`.`NestedComplexType_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +WHERE `c`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `u`.`Id`, `u`.`SortIndex`, `u`.`CaffeineGrams`, `u`.`CokeCO2`, `u`.`Ints`, `u`.`SugarGrams`, `u`.`LiltCO2`, `u`.`SugarGrams1`, `u`.`CaffeineGrams1`, `u`.`HasMilk`, `u`.`ComplexTypeCollection`, `u`.`ParentComplexType_Int`, `u`.`ParentComplexType_UniqueInt`, `u`.`ParentComplexType_Nested_NestedInt`, `u`.`ParentComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int`, `u`.`ChildComplexType_UniqueInt`, `u`.`ChildComplexType_Nested_NestedInt`, `u`.`ChildComplexType_Nested_UniqueInt`, `u`.`ChildComplexType_Int1`, `u`.`ChildComplexType_UniqueInt1`, `u`.`ChildComplexType_Nested_NestedInt1`, `u`.`ChildComplexType_Nested_UniqueInt1`, `u`.`Discriminator` +FROM ( + SELECT `d`.`Id`, `d`.`SortIndex`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Drink' AS `Discriminator` + FROM `Drinks` AS `d` + UNION ALL + SELECT `c`.`Id`, `c`.`SortIndex`, `c`.`ComplexTypeCollection`, `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Coke' AS `Discriminator` + FROM `Coke` AS `c` + UNION ALL + SELECT `l`.`Id`, `l`.`SortIndex`, `l`.`ComplexTypeCollection`, `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, `l`.`LiltCO2`, `l`.`SugarGrams` AS `SugarGrams1`, NULL AS `CaffeineGrams1`, NULL AS `HasMilk`, NULL AS `ChildComplexType_Int1`, NULL AS `ChildComplexType_UniqueInt1`, NULL AS `ChildComplexType_Nested_NestedInt1`, NULL AS `ChildComplexType_Nested_UniqueInt1`, 'Lilt' AS `Discriminator` + FROM `Lilt` AS `l` + UNION ALL + SELECT `t`.`Id`, `t`.`SortIndex`, `t`.`ComplexTypeCollection`, `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt`, NULL AS `CaffeineGrams`, NULL AS `CokeCO2`, NULL AS `Ints`, NULL AS `SugarGrams`, NULL AS `ChildComplexType_Int`, NULL AS `ChildComplexType_UniqueInt`, NULL AS `ChildComplexType_Nested_NestedInt`, NULL AS `ChildComplexType_Nested_UniqueInt`, NULL AS `LiltCO2`, NULL AS `SugarGrams1`, `t`.`CaffeineGrams` AS `CaffeineGrams1`, `t`.`HasMilk`, `t`.`ChildComplexType_Int` AS `ChildComplexType_Int1`, `t`.`ChildComplexType_UniqueInt` AS `ChildComplexType_UniqueInt1`, `t`.`ChildComplexType_Nested_NestedInt` AS `ChildComplexType_Nested_NestedInt1`, `t`.`ChildComplexType_Nested_UniqueInt` AS `ChildComplexType_Nested_UniqueInt1`, 'Tea' AS `Discriminator` + FROM `Tea` AS `t` +) AS `u` +WHERE `u`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +UNION ALL +SELECT `c`.`Int` AS `ParentComplexType_Int`, `c`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +UNION ALL +SELECT `l`.`Int` AS `ParentComplexType_Int`, `l`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Lilt` AS `l` +UNION ALL +SELECT `t`.`Int` AS `ParentComplexType_Int`, `t`.`UniqueInt` AS `ParentComplexType_UniqueInt`, `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Tea` AS `t` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +UNION ALL +SELECT `c`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `c`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Coke` AS `c` +UNION ALL +SELECT `l`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `l`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Lilt` AS `l` +UNION ALL +SELECT `t`.`NestedInt` AS `ParentComplexType_Nested_NestedInt`, `t`.`NestedComplexType_UniqueInt` AS `ParentComplexType_Nested_UniqueInt` +FROM `Tea` AS `t` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..e6509b0b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..d067147e --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,122 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedTest(TPHInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..3efa7383 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,125 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryLibRedTest( + TPHInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 AND `d`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`LiltCO2`, `d`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt`, `d`.`Tea_ChildComplexType_Int`, `d`.`Tea_ChildComplexType_UniqueInt`, `d`.`Tea_ChildComplexType_Nested_NestedInt`, `d`.`Tea_ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 AND `d`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`Discriminator`, `d`.`SortIndex`, `d`.`CaffeineGrams`, `d`.`CokeCO2`, `d`.`Ints`, `d`.`SugarGrams`, `d`.`LiltCO2`, `d`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt`, `d`.`Tea_ChildComplexType_Int`, `d`.`Tea_ChildComplexType_UniqueInt`, `d`.`Tea_ChildComplexType_Nested_NestedInt`, `d`.`Tea_ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType_Int`, `d`.`ChildComplexType_UniqueInt`, `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`ChildComplexType_Nested_NestedInt`, `d`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +WHERE `d`.`Discriminator` = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..2c2f057b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..b019b594 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,145 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedTest(TPTInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..4017b3ab --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,148 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryLibRedTest( + TPTInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +WHERE `c`.`ChildComplexType_Int` = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `l`.`LiltCO2`, `l`.`SugarGrams`, `t`.`CaffeineGrams`, `t`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, `t`.`ChildComplexType_Int`, `t`.`ChildComplexType_UniqueInt`, `t`.`ChildComplexType_Nested_NestedInt`, `t`.`ChildComplexType_Nested_UniqueInt`, CASE + WHEN `t`.`Id` IS NOT NULL THEN 'Tea' + WHEN `l`.`Id` IS NOT NULL THEN 'Lilt' + WHEN `c`.`Id` IS NOT NULL THEN 'Coke' +END AS `Discriminator` +FROM `Drinks` AS `d` +LEFT JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +LEFT JOIN `Lilt` AS `l` ON `d`.`Id` = `l`.`Id` +LEFT JOIN `Tea` AS `t` ON `d`.`Id` = `t`.`Id` +WHERE `d`.`ParentComplexType_Int` = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +WHERE `c`.`ChildComplexType_Nested_NestedInt` = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`Id`, `d`.`SortIndex`, `c`.`CaffeineGrams`, `c`.`CokeCO2`, `c`.`Ints`, `c`.`SugarGrams`, `l`.`LiltCO2`, `l`.`SugarGrams`, `t`.`CaffeineGrams`, `t`.`HasMilk`, `d`.`ComplexTypeCollection`, `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt`, `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt`, `t`.`ChildComplexType_Int`, `t`.`ChildComplexType_UniqueInt`, `t`.`ChildComplexType_Nested_NestedInt`, `t`.`ChildComplexType_Nested_UniqueInt`, CASE + WHEN `t`.`Id` IS NOT NULL THEN 'Tea' + WHEN `l`.`Id` IS NOT NULL THEN 'Lilt' + WHEN `c`.`Id` IS NOT NULL THEN 'Coke' +END AS `Discriminator` +FROM `Drinks` AS `d` +LEFT JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +LEFT JOIN `Lilt` AS `l` ON `d`.`Id` = `l`.`Id` +LEFT JOIN `Tea` AS `t` ON `d`.`Id` = `t`.`Id` +WHERE `d`.`ParentComplexType_Nested_NestedInt` = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Int`, `c`.`ChildComplexType_UniqueInt`, `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Int`, `d`.`ParentComplexType_UniqueInt`, `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT `c`.`ChildComplexType_Nested_NestedInt`, `c`.`ChildComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +INNER JOIN `Coke` AS `c` ON `d`.`Id` = `c`.`Id` +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT `d`.`ParentComplexType_Nested_NestedInt`, `d`.`ParentComplexType_Nested_UniqueInt` +FROM `Drinks` AS `d` +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs new file mode 100644 index 00000000..647c6fe1 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs @@ -0,0 +1,70 @@ +using System.Threading.Tasks; +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Query.Translations; + +public class JsonTranslationsLibRedTest : JsonTranslationsRelationalTestBase< + JsonTranslationsLibRedTest.JsonTranslationsQueryLibRedFixture> +{ + public JsonTranslationsLibRedTest(JsonTranslationsQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryLibRedFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs new file mode 100644 index 00000000..0586fffe --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/RuntimeMigrationLibRedTest.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using EntityFrameworkCore.LibRed.Design.Internal; +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests; + +public class RuntimeMigrationLibRedTest(RuntimeMigrationLibRedTest.RuntimeMigrationLibRedFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(LibRedDesignTimeServices).Assembly; + + public class RuntimeMigrationLibRedFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs new file mode 100644 index 00000000..ffab697b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/LibRedTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.LibRed.Extended.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types; + +public abstract class LibRedTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs new file mode 100644 index 00000000..29455462 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedBoolTypeTest(LibRedBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : LibRedTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs new file mode 100644 index 00000000..b9237875 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs @@ -0,0 +1,216 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedByteArrayTypeTest(LibRedByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 510) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 510) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : LibRedTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs new file mode 100644 index 00000000..d0c2d883 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs @@ -0,0 +1,223 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedGuidTypeTest(LibRedGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = {8f7331d6-cde9-44fb-8611-81fff686f280} +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : LibRedTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs new file mode 100644 index 00000000..588eeb5d --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Miscellaneous; + +public class LibRedStringTypeTest(LibRedStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 255) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 255) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : LibRedTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs new file mode 100644 index 00000000..40424d85 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs @@ -0,0 +1,234 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedByteTypeTest(LibRedByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CBYTE(0) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : LibRedTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs new file mode 100644 index 00000000..7abc7262 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedDecimalTypeTest(LibRedDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : LibRedTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs new file mode 100644 index 00000000..f4c98503 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedDoubleTypeTest(LibRedDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : LibRedTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs new file mode 100644 index 00000000..173ade0c --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedFloatTypeTest(LibRedFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : LibRedTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs new file mode 100644 index 00000000..c594fc78 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedIntTypeTest(LibRedIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : LibRedTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs new file mode 100644 index 00000000..b13160d7 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedLongTypeTest(LibRedLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = -9223372036854775808 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : LibRedTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs new file mode 100644 index 00000000..b0428aae --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs @@ -0,0 +1,229 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Numeric; + +public class LibRedShortTypeTest(LibRedShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CINT(-32768) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : LibRedTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs new file mode 100644 index 00000000..e77c3bc0 --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateOnlyTypeTest(LibRedDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T00:00:00.0000000' (DbType = Date) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = Date) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : LibRedTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs new file mode 100644 index 00000000..ee9de9af --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTime2TypeTest(LibRedDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05 12:30:45# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : LibRedTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..7625ae0e --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs @@ -0,0 +1,237 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeOffsetTypeTest( + LibRedDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T10:30:45.0000000Z' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = CDATE('2020-01-05 10:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T09:30:45.0000000Z' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : LibRedTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs new file mode 100644 index 00000000..7174b88c --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs @@ -0,0 +1,225 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeTypeTest(LibRedDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = #2020-01-05 12:30:45# +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : LibRedTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs new file mode 100644 index 00000000..0770a58a --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedTimeOnlyTypeTest(LibRedTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = TIMEVALUE('12:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : LibRedTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs new file mode 100644 index 00000000..1631bb2b --- /dev/null +++ b/test/EFCore.LibRed.Extended.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs @@ -0,0 +1,235 @@ +using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using Xunit; + +namespace EntityFrameworkCore.LibRed.Extended.FunctionalTests.Types.Temporal; + +public class LibRedTimeSpanTypeTest(LibRedTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP 2 `t`.`Id`, `t`.`ArrayValue`, `t`.`OtherValue`, `t`.`Value` +FROM `TypeEntity` AS `t` +WHERE `t`.`Value` = TIMEVALUE('12:30:45') +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +UPDATE `TypeEntity` SET `Value` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +UPDATE `JsonTypeEntity` SET `JsonContainer` = @p0 +WHERE `Id` = @p1; +SELECT @@ROWCOUNT; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : LibRedTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs index 782c2345..eb0b1dc4 100644 --- a/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs +++ b/test/EFCore.LibRed.FunctionalTests/Query/AdHocQueryFiltersQueryLibRedTest.cs @@ -509,20 +509,6 @@ public override async Task Named_query_filters_combined() AssertSql(); } - public override async Task Query_filter_with_EF_Constant_throws() - { - await base.Query_filter_with_EF_Constant_throws(); - - AssertSql(); - } - - public override async Task Query_filter_with_EF_Parameter_throws() - { - await base.Query_filter_with_EF_Parameter_throws(); - - AssertSql(); - } - public override async Task GroupBy_aggregate_over_required_navigation_with_query_filter(bool async) { await base.GroupBy_aggregate_over_required_navigation_with_query_filter(async); diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..02d7cf57 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.ComplexTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.ComplexTableSplitting; + +public class ComplexTableSplittingPrimitiveCollectionLibRedTest( + ComplexTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : ComplexTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs new file mode 100644 index 00000000..40fb22ff --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsBulkUpdateLibRedTest.cs @@ -0,0 +1,158 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System; +using System.Data.Common; +using System.Threading.Tasks; +using Xunit; +using Xunit.Sdk; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsBulkUpdateLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsBulkUpdateRelationalTestBase(fixture, testOutputHelper) +{ + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + // FK constraint failures + public override Task Delete_entity_with_associations() + => Assert.ThrowsAsync(base.Delete_entity_with_associations); + + public override Task Delete_required_associate() + => Assert.ThrowsAsync(base.Delete_required_associate); + + // SQL generation produces invalid object name for these scenarios + public override Task Delete_optional_associate() + => Assert.ThrowsAsync(base.Delete_optional_associate); + + public override Task Update_property_inside_associate() + => Assert.ThrowsAsync(base.Update_property_inside_associate); + + public override Task Update_property_inside_associate_with_special_chars() + => Assert.ThrowsAsync(base.Update_property_inside_associate_with_special_chars); + + public override Task Update_property_on_projected_associate() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate); + + public override Task Update_property_on_projected_associate_with_OrderBy_Skip() + => Assert.ThrowsAsync(base.Update_property_on_projected_associate_with_OrderBy_Skip); + + public override Task Update_multiple_properties_inside_same_associate() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_same_associate); + + public override Task Update_primitive_collection_to_constant() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_constant); + + public override Task Update_primitive_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_parameter); + + // Translation not yet supported for navigation-mapped associations + public override Task Update_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_parameter); + + public override Task Update_associate_to_inline() + => Assert.ThrowsAsync(base.Update_associate_to_inline); + + public override Task Update_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_inline_with_lambda); + + public override Task Update_associate_to_another_associate() + => Assert.ThrowsAsync(base.Update_associate_to_another_associate); + + public override Task Update_associate_to_null() + => Assert.ThrowsAsync(base.Update_associate_to_null); + + public override Task Update_associate_to_null_with_lambda() + => Assert.ThrowsAsync(base.Update_associate_to_null_with_lambda); + + public override Task Update_associate_to_null_parameter() + => Assert.ThrowsAsync(base.Update_associate_to_null_parameter); + + public override Task Update_nested_associate_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_associate_to_parameter); + + public override Task Update_nested_associate_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_associate_to_inline_with_lambda); + + public override Task Update_nested_associate_to_another_nested_associate() + => Assert.ThrowsAsync(base.Update_nested_associate_to_another_nested_associate); + + public override Task Update_nested_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_nested_collection_to_parameter); + + public override Task Update_nested_collection_to_inline_with_lambda() + => Assert.ThrowsAsync(base.Update_nested_collection_to_inline_with_lambda); + + public override Task Update_nested_collection_to_another_nested_collection() + => Assert.ThrowsAsync(base.Update_nested_collection_to_another_nested_collection); + + public override Task Update_collection_to_parameter() + => Assert.ThrowsAsync(base.Update_collection_to_parameter); + + public override Task Update_collection_referencing_the_original_collection() + => Assert.ThrowsAsync(base.Update_collection_referencing_the_original_collection); + + public override Task Update_primitive_collection_to_another_collection() + => Assert.ThrowsAsync(base.Update_primitive_collection_to_another_collection); + + public override Task Update_inside_structural_collection() + => Assert.ThrowsAsync(base.Update_inside_structural_collection); + + public override Task Update_multiple_properties_inside_associates_and_on_entity_type() + => Assert.ThrowsAsync(base.Update_multiple_properties_inside_associates_and_on_entity_type); + + public override Task Update_multiple_projected_associates_via_anonymous_type() + => Assert.ThrowsAsync(base.Update_multiple_projected_associates_via_anonymous_type); + + public override async Task Update_property_inside_nested_associate() + { + await base.Update_property_inside_nested_associate(); + + AssertExecuteUpdateSql( + """ +@p='foo_updated' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [n] +SET [n].[String] = @p +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +"""); + } + + public override async Task Update_associate_with_null_required_property() + { + await base.Update_associate_with_null_required_property(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_required_nested_associate_to_null() + { + await base.Update_required_nested_associate_to_null(); + + AssertExecuteUpdateSql(); + } + + public override async Task Update_inside_primitive_collection() + { + await base.Update_inside_primitive_collection(); + + AssertExecuteUpdateSql( + """ +@p='99' + +SET NOCOUNT OFF; +UPDATE [a0] +SET [a0].[Ints] = JSON_MODIFY([a0].[Ints], '$[1]', @p) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [AssociateType] AS [a0] ON [r].[RequiredAssociateId] = [a0].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) >= 2 +"""); + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..681069c7 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/Navigations/NavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.Navigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.Navigations; + +public class NavigationsPrimitiveCollectionLibRedTest(NavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : NavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([a].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE CAST(JSON_VALUE([a].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n] ON [a0].[OptionalNestedAssociateId] = [n].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[RequiredNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a].[OptionalNestedAssociateId] = [n1].[Id] +INNER JOIN [NestedAssociateType] AS [n2] ON [a].[RequiredNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r].[OptionalAssociateId], [r].[RequiredAssociateId], [s].[Id], [s].[CollectionRootId], [s].[Int], [s].[Ints], [s].[Name], [s].[OptionalNestedAssociateId], [s].[RequiredNestedAssociateId], [s].[String], [s].[Id0], [s].[CollectionAssociateId], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[CollectionAssociateId0], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[CollectionAssociateId1], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [a0].[Id], [a0].[CollectionRootId], [a0].[Int], [a0].[Ints], [a0].[Name], [a0].[OptionalNestedAssociateId], [a0].[RequiredNestedAssociateId], [a0].[String], [n6].[Id], [n6].[CollectionAssociateId], [n6].[Int], [n6].[Ints], [n6].[Name], [n6].[String], [n0].[Id], [n0].[CollectionAssociateId], [n0].[Int], [n0].[Ints], [n0].[Name], [n0].[String], [n1].[Id], [n1].[CollectionAssociateId], [n1].[Int], [n1].[Ints], [n1].[Name], [n1].[String], [a].[Id], [a].[CollectionRootId], [a].[Int], [a].[Ints], [a].[Name], [a].[OptionalNestedAssociateId], [a].[RequiredNestedAssociateId], [a].[String], [n7].[Id], [n7].[CollectionAssociateId], [n7].[Int], [n7].[Ints], [n7].[Name], [n7].[String], [n2].[Id], [n2].[CollectionAssociateId], [n2].[Int], [n2].[Ints], [n2].[Name], [n2].[String], [n].[Id], [n].[CollectionAssociateId], [n].[Int], [n].[Ints], [n].[Name], [n].[String] +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +INNER JOIN [NestedAssociateType] AS [n] ON [a].[RequiredNestedAssociateId] = [n].[Id] +LEFT JOIN [AssociateType] AS [a0] ON [r].[OptionalAssociateId] = [a0].[Id] +LEFT JOIN [NestedAssociateType] AS [n0] ON [a0].[OptionalNestedAssociateId] = [n0].[Id] +LEFT JOIN [NestedAssociateType] AS [n1] ON [a0].[RequiredNestedAssociateId] = [n1].[Id] +LEFT JOIN [NestedAssociateType] AS [n2] ON [a].[OptionalNestedAssociateId] = [n2].[Id] +LEFT JOIN ( + SELECT [a1].[Id], [a1].[CollectionRootId], [a1].[Int], [a1].[Ints], [a1].[Name], [a1].[OptionalNestedAssociateId], [a1].[RequiredNestedAssociateId], [a1].[String], [n5].[Id] AS [Id0], [n5].[CollectionAssociateId], [n5].[Int] AS [Int0], [n5].[Ints] AS [Ints0], [n5].[Name] AS [Name0], [n5].[String] AS [String0], [n3].[Id] AS [Id1], [n3].[CollectionAssociateId] AS [CollectionAssociateId0], [n3].[Int] AS [Int1], [n3].[Ints] AS [Ints1], [n3].[Name] AS [Name1], [n3].[String] AS [String1], [n4].[Id] AS [Id2], [n4].[CollectionAssociateId] AS [CollectionAssociateId1], [n4].[Int] AS [Int2], [n4].[Ints] AS [Ints2], [n4].[Name] AS [Name2], [n4].[String] AS [String2] + FROM [AssociateType] AS [a1] + LEFT JOIN [NestedAssociateType] AS [n3] ON [a1].[OptionalNestedAssociateId] = [n3].[Id] + INNER JOIN [NestedAssociateType] AS [n4] ON [a1].[RequiredNestedAssociateId] = [n4].[Id] + LEFT JOIN [NestedAssociateType] AS [n5] ON [a1].[Id] = [n5].[CollectionAssociateId] +) AS [s] ON [r].[Id] = [s].[CollectionRootId] +LEFT JOIN [NestedAssociateType] AS [n6] ON [a0].[Id] = [n6].[CollectionAssociateId] +LEFT JOIN [NestedAssociateType] AS [n7] ON [a].[Id] = [n7].[CollectionAssociateId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([n].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [s].[Id], [s].[Id0], [n6].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +INNER JOIN [AssociateType] AS [a] ON [r].[RequiredAssociateId] = [a].[Id] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([a].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..3f2c5201 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedNavigations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.OwnedNavigations; + +public class OwnedNavigationsPrimitiveCollectionLibRedTest(OwnedNavigationsLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : OwnedNavigationsPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r0].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r0].[Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [i].[value] + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i] +) +ORDER BY [r].[Id], [r0].[RootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[Id1], [s].[Int1], [s].[Ints1], [s].[Name1], [s].[String1], [s].[Id2], [s].[Int2], [s].[Ints2], [s].[Name2], [s].[String2], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [o2].[AssociateTypeRootEntityId], [o2].[Id], [o2].[Int], [o2].[Ints], [o2].[Name], [o2].[String], [o0].[Id], [o0].[Int], [o0].[Ints], [o0].[Name], [o0].[String], [o1].[Id], [o1].[Int], [o1].[Ints], [o1].[Name], [o1].[String], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r7].[AssociateTypeRootEntityId], [r7].[Id], [r7].[Int], [r7].[Ints], [r7].[Name], [r7].[String], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String] +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +LEFT JOIN [RequiredRelated_RequiredNested] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated] AS [o] ON [r].[Id] = [o].[RootEntityId] +LEFT JOIN [OptionalRelated_OptionalNested] AS [o0] ON [o].[RootEntityId] = [o0].[AssociateTypeRootEntityId] +LEFT JOIN [OptionalRelated_RequiredNested] AS [o1] ON [o].[RootEntityId] = [o1].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_OptionalNested] AS [r2] ON [r0].[RootEntityId] = [r2].[AssociateTypeRootEntityId] +LEFT JOIN ( + SELECT [r3].[RootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r4].[AssociateTypeRootEntityId], [r4].[AssociateTypeId], [r5].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId0], [r5].[AssociateTypeId] AS [AssociateTypeId0], [r6].[AssociateTypeRootEntityId] AS [AssociateTypeRootEntityId1], [r6].[AssociateTypeId] AS [AssociateTypeId1], [r6].[Id] AS [Id0], [r6].[Int] AS [Int0], [r6].[Ints] AS [Ints0], [r6].[Name] AS [Name0], [r6].[String] AS [String0], [r4].[Id] AS [Id1], [r4].[Int] AS [Int1], [r4].[Ints] AS [Ints1], [r4].[Name] AS [Name1], [r4].[String] AS [String1], [r5].[Id] AS [Id2], [r5].[Int] AS [Int2], [r5].[Ints] AS [Ints2], [r5].[Name] AS [Name2], [r5].[String] AS [String2] + FROM [RelatedCollection] AS [r3] + LEFT JOIN [RelatedCollection_OptionalNested] AS [r4] ON [r3].[RootEntityId] = [r4].[AssociateTypeRootEntityId] AND [r3].[Id] = [r4].[AssociateTypeId] + LEFT JOIN [RelatedCollection_RequiredNested] AS [r5] ON [r3].[RootEntityId] = [r5].[AssociateTypeRootEntityId] AND [r3].[Id] = [r5].[AssociateTypeId] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r6] ON [r3].[RootEntityId] = [r6].[AssociateTypeRootEntityId] AND [r3].[Id] = [r6].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o2] ON [o].[RootEntityId] = [o2].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r7] ON [r0].[RootEntityId] = [r7].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r1].[Ints]) AS [i]) = 3 +ORDER BY [r].[Id], [r0].[RootEntityId], [r1].[AssociateTypeRootEntityId], [o].[RootEntityId], [o0].[AssociateTypeRootEntityId], [o1].[AssociateTypeRootEntityId], [r2].[AssociateTypeRootEntityId], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[AssociateTypeRootEntityId0], [s].[AssociateTypeId0], [s].[AssociateTypeRootEntityId1], [s].[AssociateTypeId1], [s].[Id0], [o2].[AssociateTypeRootEntityId], [o2].[Id], [r7].[AssociateTypeRootEntityId], [r7].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([i0].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i0]) +FROM [RootEntity] AS [r] +LEFT JOIN [RequiredRelated] AS [r0] ON [r].[Id] = [r0].[RootEntityId] +WHERE ( + SELECT ISNULL(SUM([i].[value]), 0) + FROM OPENJSON([r0].[Ints]) WITH ([value] int '$') AS [i]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs new file mode 100644 index 00000000..7636c3a1 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingPrimitiveCollectionLibRedTest.cs @@ -0,0 +1,152 @@ +using Microsoft.EntityFrameworkCore.Query.Associations.OwnedTableSplitting; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Associations.OwnedTableSplitting; + +public class OwnedTableSplittingPrimitiveCollectionLibRedTest( + OwnedTableSplittingLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : OwnedTableSplittingPrimitiveCollectionRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Count() + { + await base.Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Index() + { + await base.Index(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r2].[AssociateTypeRootEntityId], [r2].[Id], [r2].[Int], [r2].[Ints], [r2].[Name], [r2].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r0].[RootEntityId], [r0].[Id], [r0].[Int], [r0].[Ints], [r0].[Name], [r0].[String], [r1].[AssociateTypeRootEntityId], [r1].[AssociateTypeId], [r1].[Id] AS [Id0], [r1].[Int] AS [Int0], [r1].[Ints] AS [Ints0], [r1].[Name] AS [Name0], [r1].[String] AS [String0], [r0].[OptionalNestedAssociate_Id], [r0].[OptionalNestedAssociate_Int], [r0].[OptionalNestedAssociate_Ints], [r0].[OptionalNestedAssociate_Name], [r0].[OptionalNestedAssociate_String], [r0].[RequiredNestedAssociate_Id], [r0].[RequiredNestedAssociate_Int], [r0].[RequiredNestedAssociate_Ints], [r0].[RequiredNestedAssociate_Name], [r0].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r0] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r1] ON [r0].[RootEntityId] = [r1].[AssociateTypeRootEntityId] AND [r0].[Id] = [r1].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r2] ON [r].[Id] = [r2].[AssociateTypeRootEntityId] +WHERE CAST(JSON_VALUE([r].[RequiredAssociate_Ints], '$[0]') AS int) = 1 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r2].[AssociateTypeRootEntityId], [r2].[Id] +"""); + } + + public override async Task Contains() + { + await base.Contains(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 3 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Any_predicate() + { + await base.Any_predicate(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE 2 IN ( + SELECT [r0].[value] + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0] +) +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Nested_Count() + { + await base.Nested_Count(); + + AssertSql( + """ +SELECT [r].[Id], [r].[Name], [s].[RootEntityId], [s].[Id], [s].[Int], [s].[Ints], [s].[Name], [s].[String], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [s].[Int0], [s].[Ints0], [s].[Name0], [s].[String0], [s].[OptionalNestedAssociate_Id], [s].[OptionalNestedAssociate_Int], [s].[OptionalNestedAssociate_Ints], [s].[OptionalNestedAssociate_Name], [s].[OptionalNestedAssociate_String], [s].[RequiredNestedAssociate_Id], [s].[RequiredNestedAssociate_Int], [s].[RequiredNestedAssociate_Ints], [s].[RequiredNestedAssociate_Name], [s].[RequiredNestedAssociate_String], [r].[OptionalAssociate_Id], [r].[OptionalAssociate_Int], [r].[OptionalAssociate_Ints], [r].[OptionalAssociate_Name], [r].[OptionalAssociate_String], [o].[AssociateTypeRootEntityId], [o].[Id], [o].[Int], [o].[Ints], [o].[Name], [o].[String], [r].[OptionalAssociate_OptionalNestedAssociate_Id], [r].[OptionalAssociate_OptionalNestedAssociate_Int], [r].[OptionalAssociate_OptionalNestedAssociate_Ints], [r].[OptionalAssociate_OptionalNestedAssociate_Name], [r].[OptionalAssociate_OptionalNestedAssociate_String], [r].[OptionalAssociate_RequiredNestedAssociate_Id], [r].[OptionalAssociate_RequiredNestedAssociate_Int], [r].[OptionalAssociate_RequiredNestedAssociate_Ints], [r].[OptionalAssociate_RequiredNestedAssociate_Name], [r].[OptionalAssociate_RequiredNestedAssociate_String], [r].[RequiredAssociate_Id], [r].[RequiredAssociate_Int], [r].[RequiredAssociate_Ints], [r].[RequiredAssociate_Name], [r].[RequiredAssociate_String], [r3].[AssociateTypeRootEntityId], [r3].[Id], [r3].[Int], [r3].[Ints], [r3].[Name], [r3].[String], [r].[RequiredAssociate_OptionalNestedAssociate_Id], [r].[RequiredAssociate_OptionalNestedAssociate_Int], [r].[RequiredAssociate_OptionalNestedAssociate_Ints], [r].[RequiredAssociate_OptionalNestedAssociate_Name], [r].[RequiredAssociate_OptionalNestedAssociate_String], [r].[RequiredAssociate_RequiredNestedAssociate_Id], [r].[RequiredAssociate_RequiredNestedAssociate_Int], [r].[RequiredAssociate_RequiredNestedAssociate_Ints], [r].[RequiredAssociate_RequiredNestedAssociate_Name], [r].[RequiredAssociate_RequiredNestedAssociate_String] +FROM [RootEntity] AS [r] +LEFT JOIN ( + SELECT [r1].[RootEntityId], [r1].[Id], [r1].[Int], [r1].[Ints], [r1].[Name], [r1].[String], [r2].[AssociateTypeRootEntityId], [r2].[AssociateTypeId], [r2].[Id] AS [Id0], [r2].[Int] AS [Int0], [r2].[Ints] AS [Ints0], [r2].[Name] AS [Name0], [r2].[String] AS [String0], [r1].[OptionalNestedAssociate_Id], [r1].[OptionalNestedAssociate_Int], [r1].[OptionalNestedAssociate_Ints], [r1].[OptionalNestedAssociate_Name], [r1].[OptionalNestedAssociate_String], [r1].[RequiredNestedAssociate_Id], [r1].[RequiredNestedAssociate_Int], [r1].[RequiredNestedAssociate_Ints], [r1].[RequiredNestedAssociate_Name], [r1].[RequiredNestedAssociate_String] + FROM [RelatedCollection] AS [r1] + LEFT JOIN [RelatedCollection_NestedCollection] AS [r2] ON [r1].[RootEntityId] = [r2].[AssociateTypeRootEntityId] AND [r1].[Id] = [r2].[AssociateTypeId] +) AS [s] ON [r].[Id] = [s].[RootEntityId] +LEFT JOIN [OptionalRelated_NestedCollection] AS [o] ON CASE + WHEN [r].[OptionalAssociate_Id] IS NOT NULL AND [r].[OptionalAssociate_Int] IS NOT NULL AND [r].[OptionalAssociate_Ints] IS NOT NULL AND [r].[OptionalAssociate_Name] IS NOT NULL AND [r].[OptionalAssociate_String] IS NOT NULL THEN [r].[Id] +END = [o].[AssociateTypeRootEntityId] +LEFT JOIN [RequiredRelated_NestedCollection] AS [r3] ON [r].[Id] = [r3].[AssociateTypeRootEntityId] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([r].[RequiredAssociate_RequiredNestedAssociate_Ints]) AS [r0]) = 3 +ORDER BY [r].[Id], [s].[RootEntityId], [s].[Id], [s].[AssociateTypeRootEntityId], [s].[AssociateTypeId], [s].[Id0], [o].[AssociateTypeRootEntityId], [o].[Id], [r3].[AssociateTypeRootEntityId], [r3].[Id] +"""); + } + + public override async Task Select_Sum() + { + await base.Select_Sum(); + + AssertSql( + """ +SELECT ( + SELECT ISNULL(SUM([r1].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r1]) +FROM [RootEntity] AS [r] +WHERE ( + SELECT ISNULL(SUM([r0].[value]), 0) + FROM OPENJSON([r].[RequiredAssociate_Ints]) WITH ([value] int '$') AS [r0]) >= 6 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..1fe2e80e --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedFixture : TPCInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..36042a6c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,181 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceJsonQueryLibRedTest(TPCInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[ChildComplexType] +FROM [Coke] AS [c] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE CAST(JSON_VALUE([u].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [u].[ParentComplexType] +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([u].[ParentComplexType], '$.Nested') +FROM ( + SELECT [d].[ParentComplexType] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[ParentComplexType] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[ParentComplexType] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[ParentComplexType] + FROM [Tea] AS [t] +) AS [u] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType], [u].[ChildComplexType], [u].[ChildComplexType1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[ParentComplexType], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[ParentComplexType], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType] AS [ChildComplexType1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..7426d645 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPCInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,175 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPCInheritanceTableSplittingQueryLibRedTest(TPCInheritanceQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPCInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[Id], [c].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ComplexTypeCollection], [c].[Int], [c].[UniqueInt], [c].[NestedInt], [c].[NestedComplexType_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE [u].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +UNION ALL +SELECT [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Coke] AS [c] +UNION ALL +SELECT [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Lilt] AS [l] +UNION ALL +SELECT [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt] +FROM [Tea] AS [t] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [u].[Id], [u].[SortIndex], [u].[CaffeineGrams], [u].[CokeCO2], [u].[Ints], [u].[SugarGrams], [u].[LiltCO2], [u].[SugarGrams1], [u].[CaffeineGrams1], [u].[HasMilk], [u].[ComplexTypeCollection], [u].[ParentComplexType_Int], [u].[ParentComplexType_UniqueInt], [u].[ParentComplexType_Nested_NestedInt], [u].[ParentComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int], [u].[ChildComplexType_UniqueInt], [u].[ChildComplexType_Nested_NestedInt], [u].[ChildComplexType_Nested_UniqueInt], [u].[ChildComplexType_Int1], [u].[ChildComplexType_UniqueInt1], [u].[ChildComplexType_Nested_NestedInt1], [u].[ChildComplexType_Nested_UniqueInt1], [u].[Discriminator] +FROM ( + SELECT [d].[Id], [d].[SortIndex], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Drink' AS [Discriminator] + FROM [Drinks] AS [d] + UNION ALL + SELECT [c].[Id], [c].[SortIndex], [c].[ComplexTypeCollection], [c].[Int] AS [ParentComplexType_Int], [c].[UniqueInt] AS [ParentComplexType_UniqueInt], [c].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [c].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Coke' AS [Discriminator] + FROM [Coke] AS [c] + UNION ALL + SELECT [l].[Id], [l].[SortIndex], [l].[ComplexTypeCollection], [l].[Int] AS [ParentComplexType_Int], [l].[UniqueInt] AS [ParentComplexType_UniqueInt], [l].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [l].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], [l].[LiltCO2], [l].[SugarGrams] AS [SugarGrams1], NULL AS [CaffeineGrams1], NULL AS [HasMilk], NULL AS [ChildComplexType_Int1], NULL AS [ChildComplexType_UniqueInt1], NULL AS [ChildComplexType_Nested_NestedInt1], NULL AS [ChildComplexType_Nested_UniqueInt1], N'Lilt' AS [Discriminator] + FROM [Lilt] AS [l] + UNION ALL + SELECT [t].[Id], [t].[SortIndex], [t].[ComplexTypeCollection], [t].[Int] AS [ParentComplexType_Int], [t].[UniqueInt] AS [ParentComplexType_UniqueInt], [t].[NestedInt] AS [ParentComplexType_Nested_NestedInt], [t].[NestedComplexType_UniqueInt] AS [ParentComplexType_Nested_UniqueInt], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [Ints], NULL AS [SugarGrams], NULL AS [ChildComplexType_Int], NULL AS [ChildComplexType_UniqueInt], NULL AS [ChildComplexType_Nested_NestedInt], NULL AS [ChildComplexType_Nested_UniqueInt], NULL AS [LiltCO2], NULL AS [SugarGrams1], [t].[CaffeineGrams] AS [CaffeineGrams1], [t].[HasMilk], [t].[ChildComplexType_Int] AS [ChildComplexType_Int1], [t].[ChildComplexType_UniqueInt] AS [ChildComplexType_UniqueInt1], [t].[ChildComplexType_Nested_NestedInt] AS [ChildComplexType_Nested_NestedInt1], [t].[ChildComplexType_Nested_UniqueInt] AS [ChildComplexType_Nested_UniqueInt1], N'Tea' AS [Discriminator] + FROM [Tea] AS [t] +) AS [u] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([u].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..053b64e9 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedFixture : TPHInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..2fd48f9f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceJsonQueryLibRedTest(TPHInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPHInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND CAST(JSON_VALUE([d].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [d].[ChildComplexType], [d].[ChildComplexType] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..6d002a9c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPHInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,125 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPHInheritanceTableSplittingQueryLibRedTest( + TPHInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPHInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 AND [d].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE [d].[Discriminator] = 1 +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[Discriminator], [d].[SortIndex], [d].[CaffeineGrams], [d].[CokeCO2], [d].[Ints], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [d].[ChildComplexType_Int], [d].[ChildComplexType_UniqueInt], [d].[ChildComplexType_Nested_NestedInt], [d].[ChildComplexType_Nested_UniqueInt], [d].[Tea_ChildComplexType_Int], [d].[Tea_ChildComplexType_UniqueInt], [d].[Tea_ChildComplexType_Nested_NestedInt], [d].[Tea_ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c] + WHERE [c].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs new file mode 100644 index 00000000..ee7185bf --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedFixture.cs @@ -0,0 +1,11 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedFixture : TPTInheritanceJsonQueryRelationalFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs new file mode 100644 index 00000000..6f27ec8f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceJsonQueryLibRedTest.cs @@ -0,0 +1,145 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceJsonQueryLibRedTest(TPTInheritanceJsonQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : TPTInheritanceJsonQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Int') AS int) = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Int') AS int) = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE CAST(JSON_VALUE([c].[ChildComplexType], '$.Nested.NestedInt') AS int) = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE CAST(JSON_VALUE([d].[ParentComplexType], '$.Nested.NestedInt') AS int) = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([c].[ChildComplexType], '$.Nested') +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT JSON_QUERY([d].[ParentComplexType], '$.Nested') +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType], [c].[ChildComplexType], [t].[ChildComplexType], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs new file mode 100644 index 00000000..7da3e5c9 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Inheritance/TPTInheritanceTableSplittingQueryLibRedTest.cs @@ -0,0 +1,148 @@ +using Microsoft.EntityFrameworkCore.Query.Inheritance; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Inheritance; + +public class TPTInheritanceTableSplittingQueryLibRedTest( + TPTInheritanceQueryLibRedFixture fixture, + ITestOutputHelper testOutputHelper) + : TPTInheritanceTableSplittingQueryRelationalTestBase(fixture, testOutputHelper) +{ + public override async Task Filter_on_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Int] = 10 +"""); + } + + public override async Task Filter_on_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Int] = 8 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_derived_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_derived_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +WHERE [c].[ChildComplexType_Nested_NestedInt] = 58 +"""); + } + + public override async Task Filter_on_nested_complex_type_property_on_base_type(bool async) + { + await base.Filter_on_nested_complex_type_property_on_base_type(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE [d].[ParentComplexType_Nested_NestedInt] = 50 +"""); + } + + public override async Task Project_complex_type_on_derived_type(bool async) + { + await base.Project_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_complex_type_on_base_type(bool async) + { + await base.Project_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Project_nested_complex_type_on_derived_type(bool async) + { + await base.Project_nested_complex_type_on_derived_type(async); + + AssertSql( + """ +SELECT [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +INNER JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +"""); + } + + public override async Task Project_nested_complex_type_on_base_type(bool async) + { + await base.Project_nested_complex_type_on_base_type(async); + + AssertSql( + """ +SELECT [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt] +FROM [Drinks] AS [d] +"""); + } + + public override async Task Subquery_over_complex_collection(bool async) + { + await base.Subquery_over_complex_collection(async); + + AssertSql( + """ +SELECT [d].[Id], [d].[SortIndex], [c].[CaffeineGrams], [c].[CokeCO2], [c].[Ints], [c].[SugarGrams], [l].[LiltCO2], [l].[SugarGrams], [t].[CaffeineGrams], [t].[HasMilk], [d].[ComplexTypeCollection], [d].[ParentComplexType_Int], [d].[ParentComplexType_UniqueInt], [d].[ParentComplexType_Nested_NestedInt], [d].[ParentComplexType_Nested_UniqueInt], [c].[ChildComplexType_Int], [c].[ChildComplexType_UniqueInt], [c].[ChildComplexType_Nested_NestedInt], [c].[ChildComplexType_Nested_UniqueInt], [t].[ChildComplexType_Int], [t].[ChildComplexType_UniqueInt], [t].[ChildComplexType_Nested_NestedInt], [t].[ChildComplexType_Nested_UniqueInt], CASE + WHEN [t].[Id] IS NOT NULL THEN N'Tea' + WHEN [l].[Id] IS NOT NULL THEN N'Lilt' + WHEN [c].[Id] IS NOT NULL THEN N'Coke' +END AS [Discriminator] +FROM [Drinks] AS [d] +LEFT JOIN [Coke] AS [c] ON [d].[Id] = [c].[Id] +LEFT JOIN [Lilt] AS [l] ON [d].[Id] = [l].[Id] +LEFT JOIN [Tea] AS [t] ON [d].[Id] = [t].[Id] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([d].[ComplexTypeCollection], '$') WITH ([Int] int '$.Int') AS [c0] + WHERE [c0].[Int] > 59) = 2 +"""); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs new file mode 100644 index 00000000..70b6d612 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Query/Translations/JsonTranslationsLibRedTest.cs @@ -0,0 +1,70 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.Query.Translations; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Query.Translations; + +public class JsonTranslationsLibRedTest : JsonTranslationsRelationalTestBase< + JsonTranslationsLibRedTest.JsonTranslationsQueryLibRedFixture> +{ + public JsonTranslationsLibRedTest(JsonTranslationsQueryLibRedFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task JsonPathExists_on_scalar_string_column() + { + await base.JsonPathExists_on_scalar_string_column(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_complex_property() + { + await base.JsonPathExists_on_complex_property(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1 +"""); + } + + public override async Task JsonPathExists_on_owned_entity() + { + await base.JsonPathExists_on_owned_entity(); + + AssertSql( + """ +SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType] +FROM [JsonEntities] AS [j] +WHERE JSON_PATH_EXISTS([j].[JsonOwnedType], N'$.OptionalInt') = 1 +"""); + } + + public class JsonTranslationsQueryLibRedFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + protected override string RemoveJsonProperty(string column, string property) + => $"JSON_MODIFY({column}, '$.{property}', NULL)"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); +} diff --git a/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs b/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs new file mode 100644 index 00000000..1ccd87fd --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/RuntimeMigrationLibRedTest.cs @@ -0,0 +1,20 @@ +using EntityFrameworkCore.LibRed.Design.Internal; +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using System.Reflection; + +namespace EntityFrameworkCore.LibRed.FunctionalTests; + +public class RuntimeMigrationLibRedTest(RuntimeMigrationLibRedTest.RuntimeMigrationLibRedFixture fixture) + : RuntimeMigrationTestBase(fixture) +{ + protected override Assembly ProviderAssembly + => typeof(LibRedDesignTimeServices).Assembly; + + public class RuntimeMigrationLibRedFixture : RuntimeMigrationFixtureBase + { + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs b/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs new file mode 100644 index 00000000..1a2f824a --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/LibRedTypeFixture.cs @@ -0,0 +1,14 @@ +using EntityFrameworkCore.LibRed.FunctionalTests.TestUtilities; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types; + +public abstract class LibRedTypeFixture : RelationalTypeFixtureBase +{ + protected override ITestStoreFactory TestStoreFactory + => LibRedTestStoreFactory.Instance; + + public virtual bool UsingJsonType + => false; +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs new file mode 100644 index 00000000..b9c922a4 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedBoolTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedBoolTypeTest(LibRedBoolTypeTest.BoolTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(1 AS bit) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='True' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bit '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='False' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bit) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='True' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bit) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":false,"Value":false}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='False' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(0 AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bit)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class BoolTypeFixture : LibRedTypeFixture + { + public override bool Value { get; } = true; + public override bool OtherValue { get; } = false; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs new file mode 100644 index 00000000..b2406f70 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedByteArrayTypeTest.cs @@ -0,0 +1,220 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedByteArrayTypeTest(LibRedByteArrayTypeTest.ByteArrayTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 0x010203 +"""); + } + + // byte[].Equals() does reference equality, so the base test doesn't work for byte arrays + public override Task Primitive_collection_in_query() + => Task.CompletedTask; + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='0x04050607' (Size = 8000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with varbinary even on SQL Server 2025, as that type isn't supported + // (#36627). + // We also can't just wrap JSON_VALUE() with CAST(... AS varbinary(max)), as that would apply a SQL Server binary format + // conversion, and not base64. So we use OPENJSON which does perform base64 conversion. + AssertSql( + """ +@Fixture_Value='0x010203' (Size = 8000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +OUTER APPLY OPENJSON([j].[JsonContainer]) WITH ([Value] varbinary(max) '$.Value') AS [v] +WHERE [v].[Value] = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"BAUGBw==","Value":"BAUGBw=="}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='BAUGBw==' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'BAUGBw==') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteArrayTypeFixture : LibRedTypeFixture + { + public override byte[] Value { get; } = [1, 2, 3]; + public override byte[] OtherValue { get; } = [4, 5, 6, 7]; + + public override Func Comparer { get; } = (a, b) => a.SequenceEqual(b); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs new file mode 100644 index 00000000..d6b2ec93 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedGuidTypeTest.cs @@ -0,0 +1,227 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedGuidTypeTest(LibRedGuidTypeTest.GuidTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '8f7331d6-cde9-44fb-8611-81fff686f280' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] uniqueidentifier '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='ae192c36-9004-49b2-b785-8be10d169627' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + // Note that the JSON_VALUE RETURNING clause is never used with uniqueidentifier even on SQL Server 2025, as that type isn't + // supported (#36627). + AssertSql( + """ +@Fixture_Value='8f7331d6-cde9-44fb-8611-81fff686f280' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS uniqueidentifier) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"ae192c36-9004-49b2-b785-8be10d169627","Value":"ae192c36-9004-49b2-b785-8be10d169627"}' (Nullable = false) (Size = 100) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='ae192c36-9004-49b2-b785-8be10d169627' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'ae192c36-9004-49b2-b785-8be10d169627') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class GuidTypeFixture : LibRedTypeFixture + { + public override Guid Value { get; } = new("8f7331d6-cde9-44fb-8611-81fff686f280"); + public override Guid OtherValue { get; } = new("ae192c36-9004-49b2-b785-8be10d169627"); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs new file mode 100644 index 00000000..ac522cdb --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Miscellaneous/LibRedStringTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Miscellaneous; + +public class LibRedStringTypeTest(LibRedStringTypeTest.StringTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = N'foo' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='foo' (Size = 4000) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] nvarchar(max) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='bar' (Size = 4000) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING nvarchar(max)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='foo' (Size = 4000) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value') = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"bar","Value":"bar"}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='bar' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'bar') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class StringTypeFixture : LibRedTypeFixture + { + public override string Value { get; } = "foo"; + public override string OtherValue { get; } = "bar"; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs new file mode 100644 index 00000000..b5b10381 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedByteTypeTest.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedByteTypeTest(LibRedByteTypeTest.ByteTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(0 AS tinyint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='0' (Size = 1) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] tinyint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='255' (Size = 1) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING tinyint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='0' (Size = 1) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS tinyint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":255,"Value":255}' (Nullable = false) (Size = 30) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='255' (Size = 1) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(255 AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS tinyint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ByteTypeFixture : LibRedTypeFixture + { + public override byte Value { get; } = byte.MinValue; + public override byte OtherValue { get; } = byte.MaxValue; + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs new file mode 100644 index 00000000..de486a8f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDecimalTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedDecimalTypeTest(LibRedDecimalTypeTest.DecimalTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] decimal(18,2) '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' (Precision = 18) (Scale = 2) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING decimal(18,2)) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' (Precision = 18) (Scale = 2) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS decimal(18,2)) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' (Precision = 18) (Scale = 2) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS decimal(18,2))) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DecimalTypeFixture : LibRedTypeFixture + { + public override decimal Value { get; } = 30.5m; + public override decimal OtherValue { get; } = 30m; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs new file mode 100644 index 00000000..7e1925ef --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedDoubleTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedDoubleTypeTest(LibRedDoubleTypeTest.DoubleTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = 30.5E0 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] float '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING float) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS float) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 30.0E0) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS float)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DoubleTypeFixture : LibRedTypeFixture + { + public override double Value { get; } = 30.5d; + public override double OtherValue { get; } = 30d; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs new file mode 100644 index 00000000..ecea4266 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedFloatTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedFloatTypeTest(LibRedFloatTypeTest.FloatTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(30.5 AS real) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='30.5' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] real '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='30' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING real) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='30.5' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS real) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":30,"Value":30}' (Nullable = false) (Size = 28) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='30' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(30 AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS real)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class FloatTypeFixture : LibRedTypeFixture + { + public override float Value { get; } = 30.5f; + public override float OtherValue { get; } = 30f; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs new file mode 100644 index 00000000..c6f8d23f --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedIntTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedIntTypeTest(LibRedIntTypeTest.IntTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = -2147483648 +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-2147483648' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] int '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2147483647' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING int) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-2147483648' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS int) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":2147483647,"Value":2147483647}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='2147483647' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', 2147483647) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS int)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class IntTypeFixture : LibRedTypeFixture + { + public override int Value { get; } = int.MinValue; + public override int OtherValue { get; } = int.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs new file mode 100644 index 00000000..495c4ebb --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedLongTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedLongTypeTest(LibRedLongTypeTest.LongTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-9223372036854775808 AS bigint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-9223372036854775808' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] bigint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='9223372036854775807' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING bigint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-9223372036854775808' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS bigint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":9223372036854775807,"Value":9223372036854775807}' (Nullable = false) (Size = 62) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='9223372036854775807' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(9223372036854775807 AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS bigint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class LongTypeFixture : LibRedTypeFixture + { + public override long Value { get; } = long.MinValue; + public override long OtherValue { get; } = long.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs new file mode 100644 index 00000000..a9861aad --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Numeric/LibRedShortTypeTest.cs @@ -0,0 +1,233 @@ +using Microsoft.EntityFrameworkCore.Types; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Numeric; + +public class LibRedShortTypeTest(LibRedShortTypeTest.ShortTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = CAST(-32768 AS smallint) +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='-32768' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] smallint '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='32767' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING smallint) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='-32768' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS smallint) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":32767,"Value":32767}' (Nullable = false) (Size = 34) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@Fixture_OtherValue='32767' + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(32767 AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', CAST(JSON_VALUE([j].[JsonContainer], '$.OtherValue') AS smallint)) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', [j].[OtherValue]) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class ShortTypeFixture : LibRedTypeFixture + { + public override short Value { get; } = short.MinValue; + public override short OtherValue { get; } = short.MaxValue; + } +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs new file mode 100644 index 00000000..d71b7a1a --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateOnlyTypeTest(LibRedDateOnlyTypeTest.DateTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] date '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='05/03/2022' (DbType = Date) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING date) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='01/05/2020' (DbType = Date) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS date) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03","Value":"2022-05-03"}' (Nullable = false) (Size = 48) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTypeFixture : LibRedTypeFixture + { + public override DateOnly Value { get; } = new(2020, 1, 5); + public override DateOnly OtherValue { get; } = new(2022, 5, 3); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs new file mode 100644 index 00000000..48a4cb7c --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTime2TypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTime2TypeTest(LibRedDateTime2TypeTest.DateTime2TypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime2 '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetime2) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime2) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTime2TypeFixture : LibRedTypeFixture + { + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs new file mode 100644 index 00000000..210f8a4b --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeOffsetTypeTest.cs @@ -0,0 +1,241 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeOffsetTypeTest( + LibRedDateTimeOffsetTypeTest.DateTimeOffsetTypeFixture fixture, + ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.0000000+02:00' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetimeoffset '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2020-01-05T12:30:45.0000000+03:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING datetimeoffset) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000+02:00' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetimeoffset) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2020-01-05T12:30:45+03:00","Value":"2020-01-05T12:30:45+03:00"}' (Nullable = false) (Size = 78) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2020-01-05T12:30:45+03:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2020-01-05T12:30:45+03:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeOffsetTypeFixture : LibRedTypeFixture + { + public override DateTimeOffset Value { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(2)); + public override DateTimeOffset OtherValue { get; } = new(2020, 1, 5, 12, 30, 45, TimeSpan.FromHours(3)); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs new file mode 100644 index 00000000..608c9eed --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedDateTimeTypeTest.cs @@ -0,0 +1,229 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedDateTimeTypeTest(LibRedDateTimeTypeTest.DateTimeTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '2020-01-05T12:30:45.000' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] datetime '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='2022-05-03T00:00:00.0000000' (DbType = DateTime) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + AssertSql( + """ +@Fixture_Value='2020-01-05T12:30:45.0000000' (DbType = DateTime) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS datetime) = @Fixture_Value +"""); + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"2022-05-03T00:00:00","Value":"2022-05-03T00:00:00"}' (Nullable = false) (Size = 66) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='2022-05-03T00:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'2022-05-03T00:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class DateTimeTypeFixture : LibRedTypeFixture + { + // The default mapping for .NET DateTime is datetime2; this tests the non-default (and discouraged) datetime type. + public override string StoreType + => "datetime"; + + public override DateTime Value { get; } = new(2020, 1, 5, 12, 30, 45, DateTimeKind.Unspecified); + public override DateTime OtherValue { get; } = new(2022, 5, 3, 0, 0, 0, DateTimeKind.Unspecified); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs new file mode 100644 index 00000000..150c7a54 --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeOnlyTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedTimeOnlyTypeTest(LibRedTimeOnlyTypeTest.TimeOnlyTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30' (DbType = Time) + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00' (DbType = Time) + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30' (DbType = Time) + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00.0000000","Value":"14:00:00.0000000"}' (Nullable = false) (Size = 60) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00.0000000' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00.0000000') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeOnlyTypeFixture : LibRedTypeFixture + { + public override TimeOnly Value { get; } = new(12, 30, 45); + public override TimeOnly OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs new file mode 100644 index 00000000..e5b670bd --- /dev/null +++ b/test/EFCore.LibRed.FunctionalTests/Types/Temporal/LibRedTimeSpanTypeTest.cs @@ -0,0 +1,239 @@ +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.EntityFrameworkCore.Types; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace EntityFrameworkCore.LibRed.FunctionalTests.Types.Temporal; + +public class LibRedTimeSpanTypeTest(LibRedTimeSpanTypeTest.TimeSpanTypeFixture fixture, ITestOutputHelper testOutputHelper) + : RelationalTypeTestBase(fixture, testOutputHelper) +{ + public override async Task Equality_in_query_with_parameter() + { + await base.Equality_in_query_with_parameter(); + + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = @Fixture_Value +"""); + } + + public override async Task Equality_in_query_with_constant() + { + await base.Equality_in_query_with_constant(); + + AssertSql( + """ +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE [t].[Value] = '12:30:45' +"""); + } + + public override async Task Primitive_collection_in_query() + { + await base.Primitive_collection_in_query(); + + AssertSql( + """ +@value='12:30:45' + +SELECT TOP(2) [t].[Id], [t].[ArrayValue], [t].[OtherValue], [t].[Value] +FROM [TypeEntity] AS [t] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([t].[ArrayValue]) WITH ([value] time '$') AS [a] + WHERE [a].[value] = @value) = 2 +"""); + } + + public override async Task SaveChanges() + { + await base.SaveChanges(); + + AssertSql( + """ +@p1='1' +@p0='14:00:00' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [TypeEntity] SET [Value] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + #region JSON + + public override async Task Query_property_within_json() + { + await base.Query_property_within_json(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE JSON_VALUE([j].[JsonContainer], '$.Value' RETURNING time) = @Fixture_Value +"""); + } + else + { + AssertSql( + """ +@Fixture_Value='12:30:45' + +SELECT TOP(2) [j].[Id], [j].[OtherValue], [j].[Value], [j].[JsonContainer] +FROM [JsonTypeEntity] AS [j] +WHERE CAST(JSON_VALUE([j].[JsonContainer], '$.Value') AS time) = @Fixture_Value +"""); + } + } + + public override async Task SaveChanges_within_json() + { + await base.SaveChanges_within_json(); + + AssertSql( + """ +@p0='{"OtherValue":"14:00:00","Value":"14:00:00"}' (Nullable = false) (Size = 44) +@p1='1' + +SET IMPLICIT_TRANSACTIONS OFF; +SET NOCOUNT ON; +UPDATE [JsonTypeEntity] SET [JsonContainer] = @p0 +OUTPUT 1 +WHERE [Id] = @p1; +"""); + } + + public override async Task ExecuteUpdate_within_json_to_parameter() + { + await base.ExecuteUpdate_within_json_to_parameter(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +@complex_type_Fixture_OtherValue='14:00:00' (Size = 4000) + +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', @complex_type_Fixture_OtherValue) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_constant() + { + await base.ExecuteUpdate_within_json_to_constant(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', N'14:00:00') +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + public override async Task ExecuteUpdate_within_json_to_another_json_property() + { + await base.ExecuteUpdate_within_json_to_another_json_property(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue' RETURNING nvarchar(max))) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE([j].[JsonContainer], '$.OtherValue')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + // TODO: Currently failing on Helix only, see #36746 + public override async Task ExecuteUpdate_within_json_to_nonjson_column() + { + await base.ExecuteUpdate_within_json_to_nonjson_column(); + + if (Fixture.UsingJsonType) + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [JsonContainer].modify('$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + else + { + AssertSql( + """ +SET NOCOUNT OFF; +UPDATE [j] +SET [j].[JsonContainer] = JSON_MODIFY([j].[JsonContainer], '$.Value', JSON_VALUE(JSON_OBJECT('v': [j].[OtherValue]), '$.v')) +FROM [JsonTypeEntity] AS [j] +"""); + } + } + + #endregion JSON + + public class TimeSpanTypeFixture : LibRedTypeFixture + { + public override TimeSpan Value { get; } = new(12, 30, 45); + public override TimeSpan OtherValue { get; } = new(14, 0, 0); + } + + [Fact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); +} diff --git a/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs b/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs index a356142a..512a1ec8 100644 --- a/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs +++ b/test/LibRed.Core.AccessTests/CollationQueryProbeTests.cs @@ -36,9 +36,15 @@ public void A_column_stamped_croatian_in_a_general_database_compares_as_general( AssertComparesIn(ace, GeneralOrder, below: ["ča", "ca"], literal: "general", minMax: "ca / lm"); } + // The 2016 redistributable takes an access violation in ACECORE on the literal 'lja' < 'lm' here, which kills the + // test process and every test after it; it answered on .NET 11 RC 2 and crashes since RC 3. DATETIME2 support is + // how this suite tells that engine from the Microsoft 365 runtime, which runs the query. [Fact] public void A_general_column_in_a_database_stamped_croatian_compares_as_croatian() { + Assert.SkipUnless(AceTestDatabase.SupportsColumnType(TestDatabases.NorthwindAccdb, "DATETIME2"), + "The ACE 2016 redistributable crashes (access violation in ACECORE) comparing a Croatian digraph literal " + + "in a database stamped Croatian."); Dictionary ace = Probe(stampHeader: true, stampColumn: false); AssertComparesIn(ace, CroatianOrder, below: ["ca"], literal: "croatian", minMax: "ca / lja"); } diff --git a/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs b/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs index 6b72a6e0..819e0978 100644 --- a/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs +++ b/test/LibRed.Core.AccessTests/CreatedDatabaseCollationAccessTests.cs @@ -72,8 +72,9 @@ public class CreatedDatabaseCollationAccessTests(ITestOutputHelper output) "ñ", "č", "ž", "lj", "dž", "ch", "ll", "ı", "İ", "å", "ø", "ß", "เก", "ไทย", "Ω", "б", "א", "一", "漢字", "人々", "カタカナ", "がくせい", "한국", "韓國", @"C:\", - // A digraph in each mix of case — whether a lowercase letter then an uppercase one still contracts. - "cs", "Cs", "cS", "CS", "sz", "Sz", "sZ", "dzs", "Dzs", "dZs", "dzS", "ccs", "cCs", "gy", "gY", "ny", "nY", + // A digraph in each mix of case — only lowercase, uppercase and title case contract. + "cs", "Cs", "cS", "CS", "sz", "Sz", "sZ", "dzs", "Dzs", "dZs", "dzS", "DzS", "DZs", "DZsa", "DZS", "dDZs", + "ccs", "cCs", "gy", "gY", "ny", "nY", "zs", "zS", "ch", "Ch", "cH", "CH", "lj", "Lj", "lJ", "nj", "nJ", "dž", "dŽ", "ll", "lL", "aa", "Aa", "aA", "~sq_cSzallitoLista", ]; diff --git a/test/LibRed.Core.AccessTests/OneToOneRelationshipDaoProbeTest.cs b/test/LibRed.Core.AccessTests/OneToOneRelationshipDaoProbeTest.cs new file mode 100644 index 00000000..6f6d0aec --- /dev/null +++ b/test/LibRed.Core.AccessTests/OneToOneRelationshipDaoProbeTest.cs @@ -0,0 +1,213 @@ +using System.Data.OleDb; +using Xunit; + +namespace LibRed.Core.Tests; + +/// +/// Probe: what a one-to-one relationship (DAO dbRelationUnique, grbit 0x01) is on disk, and +/// whether LibRed's schema changes keep one intact. Reports; asserts nothing. ACE's SQL cannot create one, so each +/// case relates a child three ways on copies of one start file — SQL FOREIGN KEY, DAO with attributes 0 and +/// DAO with dbRelationUnique — and diffs them; then drops, renames the table of, and renames the column of the +/// one-to-one through ACE on one copy and LibRed on another, and diffs those. +/// +/// Every file is kept under %TEMP%\libred-one-to-one-probe for a byte diff. +[Collection(AceCollection.Name)] +public class OneToOneRelationshipDaoProbeTest(ITestOutputHelper output) +{ + private const int OneToOne = 1; + private static readonly string KeepDirectory = Path.Combine(Path.GetTempPath(), "libred-one-to-one-probe"); + + [Theory(Explicit = true)] + [InlineData("ChildPlain", "ParentId", "Parent", "Id")] // no index on the child column + [InlineData("ChildUnique", "ParentId", "Parent", "Id")] // EF's shape: a unique index over it already + [InlineData("ChildPk", "Id", "Parent", "Id")] // the child column is the child's primary key + [InlineData("ChildTwo", "A,B", "Parent2", "A,B")] // two columns + [InlineData("ChildDup", "ParentId", "Parent", "Id")] // two child rows share a key already + [InlineData("ChildNulls", "ParentId", "Parent", "Id")] // two child rows with a null key + public void Dao_creates_a_one_to_one(string child, string columns, string parent, string referenced) + { + Assert.SkipWhen(AceTestDatabase.CreateDaoEngine() is null, "DAO is not registered in this process."); + Directory.CreateDirectory(KeepDirectory); + string[] childColumns = columns.Split(','), parentColumns = referenced.Split(','); + string relation = $"FK_{child}"; + + string start = Keep(CreateStart(), $"{child}-start"); + string sql = Keep(start, $"{child}-sql"), many = Keep(start, $"{child}-dao-many"), one = Keep(start, $"{child}-dao-one"); + + output.WriteLine($"SQL FOREIGN KEY: {Outcome(() => Exec(sql, + $"ALTER TABLE {child} ADD CONSTRAINT {relation} FOREIGN KEY ({columns}) REFERENCES {parent} ({referenced})"))}"); + output.WriteLine($"DAO attributes 0: {Outcome(() => DaoRelate(many, relation, parent, child, parentColumns, childColumns, 0))}"); + string oneOutcome = Outcome(() => DaoRelate(one, relation, parent, child, parentColumns, childColumns, OneToOne)); + output.WriteLine($"DAO dbRelationUnique: {oneOutcome}"); + + output.WriteLine($"-- SQL vs DAO attributes 0:\n{DropTableParityAccessTests.Difference(sql, many)}"); + output.WriteLine($"-- DAO attributes 0 vs dbRelationUnique:\n{DropTableParityAccessTests.Difference(many, one)}"); + foreach ((string label, string path) in (ReadOnlySpan<(string, string)>)[("sql", sql), ("dao-many", many), ("dao-one", one)]) + output.WriteLine($"{label}: {Describe(path, child)}"); + if (oneOutcome != "accepted") return; + + Follow(one, $"{child}-drop", + ace => Exec(ace, $"ALTER TABLE {child} DROP CONSTRAINT {relation}"), + db => db.DropConstraint(child, relation), child); + Follow(one, $"{child}-rename-table", + ace => DaoDatabase(ace, database => database.TableDefs[child].Name = child + "X"), + db => db.RenameTable(child, child + "X"), child + "X"); + Follow(one, $"{child}-rename-column", + ace => DaoDatabase(ace, database => database.TableDefs[child].Fields[childColumns[0]].Name = childColumns[0] + "X"), + db => db.RenameColumn(child, childColumns[0], childColumns[0] + "X"), child); + } + + // The same change through ACE on one copy of the one-to-one and through LibRed on another. + private void Follow(string source, string label, Action throughAce, Func throughLibRed, string child) + { + string ace = Keep(source, $"{label}-ace"), libred = Keep(source, $"{label}-libred"); + string aceOutcome = Outcome(() => throughAce(ace)); + string libredOutcome = Outcome(() => + { + using var db = JetDatabase.Open(libred, readOnly: false); + if (!throughLibRed(db)) throw new InvalidOperationException("LibRed returned false"); + }); + output.WriteLine($"== {label}: ACE {aceOutcome}; LibRed {libredOutcome}"); + output.WriteLine($"ACE: {Describe(ace, child)}"); + output.WriteLine($"LibRed: {Describe(libred, child)}"); + output.WriteLine($"-- ACE vs LibRed:\n{DropTableParityAccessTests.Difference(ace, libred)}"); + } + + private static string CreateStart() + { + string start = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "one-to-one-start-"); + using (OleDbConnection connection = AceTestDatabase.Open(start)) + foreach (string sql in (string[]) + [ + "CREATE TABLE Parent (Id LONG, CONSTRAINT PK_Parent PRIMARY KEY (Id))", + "CREATE TABLE Parent2 (A LONG, B LONG, CONSTRAINT PK_Parent2 PRIMARY KEY (A, B))", + "CREATE TABLE ChildPlain (Id LONG, ParentId LONG, CONSTRAINT PK_ChildPlain PRIMARY KEY (Id))", + "CREATE TABLE ChildUnique (Id LONG, ParentId LONG, CONSTRAINT PK_ChildUnique PRIMARY KEY (Id))", + "CREATE UNIQUE INDEX IX_ChildUnique_ParentId ON ChildUnique (ParentId)", + "CREATE TABLE ChildPk (Id LONG, CONSTRAINT PK_ChildPk PRIMARY KEY (Id))", + "CREATE TABLE ChildTwo (Id LONG, A LONG, B LONG, CONSTRAINT PK_ChildTwo PRIMARY KEY (Id))", + "CREATE TABLE ChildDup (Id LONG, ParentId LONG, CONSTRAINT PK_ChildDup PRIMARY KEY (Id))", + "CREATE TABLE ChildNulls (Id LONG, ParentId LONG, CONSTRAINT PK_ChildNulls PRIMARY KEY (Id))", + "INSERT INTO Parent VALUES (1)", + "INSERT INTO Parent VALUES (2)", + "INSERT INTO Parent2 VALUES (1, 1)", + "INSERT INTO ChildPlain VALUES (1, 1)", + "INSERT INTO ChildUnique VALUES (1, 1)", + "INSERT INTO ChildPk VALUES (1)", + "INSERT INTO ChildTwo VALUES (1, 1, 1)", + "INSERT INTO ChildDup VALUES (1, 1)", + "INSERT INTO ChildDup VALUES (2, 1)", + "INSERT INTO ChildNulls VALUES (1, NULL)", + "INSERT INTO ChildNulls VALUES (2, NULL)", + ]) + { + using OleDbCommand command = connection.CreateCommand(); + command.CommandText = sql; + command.ExecuteNonQuery(); + } + OleDbConnection.ReleaseObjectPool(); + return start; + } + + private static string Keep(string source, string name) + { + string path = Path.Combine(KeepDirectory, name + ".accdb"); + File.Copy(source, path, overwrite: true); + return path; + } + + private static void Exec(string path, string sql) + { + using (OleDbConnection connection = AceTestDatabase.Open(path)) + using (OleDbCommand command = connection.CreateCommand()) + { + command.CommandText = sql; + command.ExecuteNonQuery(); + } + OleDbConnection.ReleaseObjectPool(); + } + + // DAO: CreateRelation(name, primary table, foreign table, attributes); Field.Name = primary field, + // Field.ForeignName = foreign field. + private static void DaoRelate(string path, string name, string parent, string child, string[] parentColumns, + string[] childColumns, int attributes) => + DaoDatabase(path, database => + { + dynamic relation = database.CreateRelation(name, parent, child, attributes); + for (int i = 0; i < parentColumns.Length; i++) + { + dynamic field = relation.CreateField(parentColumns[i]); + field.ForeignName = childColumns[i]; + relation.Fields.Append(field); + } + database.Relations.Append(relation); + }); + + private static void DaoDatabase(string path, Action run) + { + dynamic engine = AceTestDatabase.CreateDaoEngine()!; + dynamic database = engine.OpenDatabase(path); + try { run(database); } + finally + { + database.Close(); + AceTestDatabase.ReleaseAbandonedComObjects(); + } + } + + // The child's indexes as DAO and LibRed see them, and the probed relationship's attributes as DAO and LibRed read them. + private static string Describe(string path, string child) + { + var dao = new List(); + string daoOutcome = Outcome(() => + { + dynamic engine = AceTestDatabase.CreateDaoEngine()!; + dynamic database = engine.OpenDatabase(path, false, true); + try + { + dynamic indexes = database.TableDefs[child].Indexes; + for (int i = 0; i < indexes.Count; i++) + { + dynamic ix = indexes[i]; + dao.Add($"{ix.Name}{(ix.Primary ? " [PK]" : "")}{(ix.Foreign ? " [FK]" : "")}{(ix.Unique ? " [U]" : "")}"); + } + dynamic relations = database.Relations; + for (int i = 0; i < relations.Count; i++) + if (((string)relations[i].Name).StartsWith("FK_Child", StringComparison.Ordinal)) + dao.Add($"rel {relations[i].Name} attributes 0x{(int)relations[i].Attributes:X}"); + } + finally + { + database.Close(); + AceTestDatabase.ReleaseAbandonedComObjects(); + } + }); + + string libred = ""; + string libredOutcome = Outcome(() => + { + using var db = JetDatabase.Open(path, readOnly: true); + var table = db.Catalog.FindTable(child) ?? throw new InvalidOperationException($"LibRed cannot find {child}."); + libred = string.Join(", ", table.Indexes.Select(i => $"{i.Name} #{i.RealIndexOrdinal} 0x{(int)i.Flags:X4}")) + " | " + + string.Join(", ", db.Catalog.Relationships.Where(r => r.Name.StartsWith("FK_Child", StringComparison.Ordinal)) + .Select(r => $"{r.Name} one={r.IsOneToOne}")); + }); + return $"DAO [{(daoOutcome == "accepted" ? string.Join(", ", dao) : daoOutcome)}] " + + $"LibRed [{(libredOutcome == "accepted" ? libred : libredOutcome)}]"; + } + + private static string Outcome(Action run) + { + try + { + run(); + return "accepted"; + } + catch (Exception e) when (e is System.Runtime.InteropServices.COMException or InvalidOperationException + or OleDbException or Microsoft.CSharp.RuntimeBinder.RuntimeBinderException + or NotSupportedException or NotImplementedException) + { + return $"{e.GetType().Name}: {e.GetBaseException().Message}"; + } + } +} diff --git a/test/LibRed.Core.AccessTests/OneToOneRelationshipParityAccessTests.cs b/test/LibRed.Core.AccessTests/OneToOneRelationshipParityAccessTests.cs new file mode 100644 index 00000000..1a82a15d --- /dev/null +++ b/test/LibRed.Core.AccessTests/OneToOneRelationshipParityAccessTests.cs @@ -0,0 +1,143 @@ +using System.Data.OleDb; +using LibRed.Catalog; +using Xunit; + +namespace LibRed.Core.Tests; + +/// +/// Adding a one-to-one relationship through ACE and through LibRed, on copies of the same ACE-built file, must leave +/// the same file. ACE's SQL cannot declare one, so its side is DAO's CreateRelation with +/// dbRelationUnique: grbit 0x01 on every MSysRelationships row, and the child's backing +/// index unique — sharing the block of a unique index over the same columns, but not the primary key's. +/// +[Collection(AceCollection.Name)] +public class OneToOneRelationshipParityAccessTests(ITestOutputHelper output) : TempDatabaseTest +{ + private const int OneToOne = 1, DontEnforce = 2; + + [Theory] + [InlineData("ChildPlain", "ParentId", "Parent", "Id", true)] // no index on the child column + [InlineData("ChildUnique", "ParentId", "Parent", "Id", true)] // a unique index over it already, which it shares + [InlineData("ChildPk", "Id", "Parent", "Id", true)] // the child's primary key, which it does not share + [InlineData("ChildTwo", "A,B", "Parent2", "A,B", true)] // two columns: 0x01 on both rows + [InlineData("ChildNulls", "ParentId", "Parent", "Id", true)] // two null keys do not collide + [InlineData("ChildPlain", "ParentId", "Parent", "Id", false)] // unenforced: the rows alone, grbit 0x03 + public void Libred_adds_a_one_to_one_byte_for_byte_with_ace( + string child, string columns, string parent, string referenced, bool enforced) + { + string start = CreateStart(); + + string ace = TemporaryDatabase.CopyPath(start, "one-ace-"); + Assert.Equal("related", DaoRelate(ace, child, columns, parent, referenced, enforced ? OneToOne : OneToOne | DontEnforce)); + + string libred = TemporaryDatabase.CopyPath(start, "one-lib-"); + using (var db = JetDatabase.Open(libred, readOnly: false)) + db.AddForeignKey(child, Spec(child, columns, parent, referenced, enforced)); + + string difference = DropTableParityAccessTests.Difference(ace, libred); + output.WriteLine(difference); + Assert.Equal("", difference); + + using var reopened = JetDatabase.Open(libred, readOnly: true); + Assert.True(reopened.Catalog.Relationships.Single(r => r.Name == $"FK_{child}").IsOneToOne); + } + + // Child rows sharing a key cannot take the unique index: ACE refuses the relationship, having written its + // MSysObjects object first, so the rollback leaves MSysObjects' and MSysACEs' counting behind; so does LibRed. + [Fact] + public void Libred_refuses_a_one_to_one_over_duplicate_keys_as_ace_does() + { + string start = CreateStart(); + + string ace = TemporaryDatabase.CopyPath(start, "one-ace-"); + Assert.Contains("duplicate values", DaoRelate(ace, "ChildDup", "ParentId", "Parent", "Id", OneToOne)); + + string libred = TemporaryDatabase.CopyPath(start, "one-lib-"); + using (var db = JetDatabase.Open(libred, readOnly: false)) + Assert.Throws(() => + db.AddForeignKey("ChildDup", Spec("ChildDup", "ParentId", "Parent", "Id", enforced: true))); + + string difference = DropTableParityAccessTests.Difference(ace, libred); + output.WriteLine(difference); + Assert.Equal("", difference); + + using var reopened = JetDatabase.Open(libred, readOnly: true); + Assert.DoesNotContain(reopened.Catalog.Relationships, r => r.Name == "FK_ChildDup"); + } + + private static RelationshipSpec Spec(string child, string columns, string parent, string referenced, bool enforced) => new( + Name: $"FK_{child}", + ReferencedTable: parent, + Columns: RelationshipSpec.PairColumns(parent, columns.Split(','), referenced.Split(',')), + IsEnforced: enforced, + CascadeUpdate: false, + CascadeDelete: false, + IsOneToOne: true); + + private static string CreateStart() + { + string start = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "one-start-"); + using (OleDbConnection connection = AceTestDatabase.Open(start)) + foreach (string sql in (string[]) + [ + "CREATE TABLE Parent (Id LONG, CONSTRAINT PK_Parent PRIMARY KEY (Id))", + "CREATE TABLE Parent2 (A LONG, B LONG, CONSTRAINT PK_Parent2 PRIMARY KEY (A, B))", + "CREATE TABLE ChildPlain (Id LONG, ParentId LONG, CONSTRAINT PK_ChildPlain PRIMARY KEY (Id))", + "CREATE TABLE ChildUnique (Id LONG, ParentId LONG, CONSTRAINT PK_ChildUnique PRIMARY KEY (Id))", + "CREATE UNIQUE INDEX IX_ChildUnique_ParentId ON ChildUnique (ParentId)", + "CREATE TABLE ChildPk (Id LONG, CONSTRAINT PK_ChildPk PRIMARY KEY (Id))", + "CREATE TABLE ChildTwo (Id LONG, A LONG, B LONG, CONSTRAINT PK_ChildTwo PRIMARY KEY (Id))", + "CREATE TABLE ChildDup (Id LONG, ParentId LONG, CONSTRAINT PK_ChildDup PRIMARY KEY (Id))", + "CREATE TABLE ChildNulls (Id LONG, ParentId LONG, CONSTRAINT PK_ChildNulls PRIMARY KEY (Id))", + "INSERT INTO Parent VALUES (1)", + "INSERT INTO Parent VALUES (2)", + "INSERT INTO Parent2 VALUES (1, 1)", + "INSERT INTO ChildPlain VALUES (1, 1)", + "INSERT INTO ChildUnique VALUES (1, 1)", + "INSERT INTO ChildPk VALUES (1)", + "INSERT INTO ChildTwo VALUES (1, 1, 1)", + "INSERT INTO ChildDup VALUES (1, 1)", + "INSERT INTO ChildDup VALUES (2, 1)", + "INSERT INTO ChildNulls VALUES (1, NULL)", + "INSERT INTO ChildNulls VALUES (2, NULL)", + ]) + { + using OleDbCommand command = connection.CreateCommand(); + command.CommandText = sql; + command.ExecuteNonQuery(); + } + OleDbConnection.ReleaseObjectPool(); + return start; + } + + /// "related", or the message DAO refused the relationship with. DAO: CreateRelation(name, primary table, + /// foreign table, attributes); Field.Name = primary field, Field.ForeignName = foreign field. + private static string DaoRelate(string path, string child, string columns, string parent, string referenced, int attributes) + { + dynamic engine = AceTestDatabase.CreateDaoEngine() + ?? throw new InvalidOperationException("DAO is not registered in this process."); + dynamic database = engine.OpenDatabase(path); + try + { + string[] childColumns = columns.Split(','), parentColumns = referenced.Split(','); + dynamic relation = database.CreateRelation($"FK_{child}", parent, child, attributes); + for (int i = 0; i < parentColumns.Length; i++) + { + dynamic field = relation.CreateField(parentColumns[i]); + field.ForeignName = childColumns[i]; + relation.Fields.Append(field); + } + database.Relations.Append(relation); + return "related"; + } + catch (System.Runtime.InteropServices.COMException e) + { + return e.Message; + } + finally + { + database.Close(); + AceTestDatabase.ReleaseAbandonedComObjects(); + } + } +} diff --git a/test/LibRed.Core.AccessTests/RenameIndexParityAccessTests.cs b/test/LibRed.Core.AccessTests/RenameIndexParityAccessTests.cs new file mode 100644 index 00000000..1e2350f1 --- /dev/null +++ b/test/LibRed.Core.AccessTests/RenameIndexParityAccessTests.cs @@ -0,0 +1,103 @@ +using System.Data.OleDb; +using Xunit; + +namespace LibRed.Core.Tests; + +/// +/// Renaming an index through ACE and through LibRed, on copies of the same ACE-built file, must leave the same file. +/// ACE has no SQL for it, so its side is DAO's Index.Name, which rewrites only the table's definition: the +/// logical block moves to where its new name sorts, its bytes unchanged. +/// +[Collection(AceCollection.Name)] +public class RenameIndexParityAccessTests(ITestOutputHelper output) : TempDatabaseTest +{ + [Theory] + [InlineData("Child", "IX_Label", "IX_Label_Renamed")] + [InlineData("Child", "IX_Label", "AA_Label")] // moves ahead of FK_Child_Parent in name order + [InlineData("Child", "IX_Label", "ix_label")] // case only + [InlineData("Parent", "PK_Parent", "PK_Parent_Renamed")] // a key a relationship references + [InlineData("Parent", "PK_Parent", "A")] // shrinking + [InlineData("Wide", "IX_Wide", "IX_Wide_Renamed_To_A_Much_Longer_Name")] // a multi-page definition + public void Libred_renames_an_index_byte_for_byte_with_ace(string table, string index, string newName) + { + string start = CreateStart(); + + string ace = TemporaryDatabase.CopyPath(start, "rnix-ace-"); + Assert.Equal("renamed", DaoRename(ace, table, index, newName)); + + string libred = TemporaryDatabase.CopyPath(start, "rnix-lib-"); + using (var db = JetDatabase.Open(libred, readOnly: false)) + Assert.True(db.RenameIndex(table, index, newName)); + + string difference = DropTableParityAccessTests.Difference(ace, libred); + output.WriteLine(difference); + Assert.Equal("", difference); + } + + // ACE refuses the index a relationship created on its child table, and a name another index has, leaving the + // file as it was; so does LibRed. + [Theory] + [InlineData("Child", "FK_Child_Parent", "FK_Child_Parent_Renamed")] + [InlineData("Child", "IX_Label", "PK_Child")] + public void Libred_refuses_a_rename_ace_refuses(string table, string index, string newName) + { + string start = CreateStart(); + + string ace = TemporaryDatabase.CopyPath(start, "rnix-ace-"); + Assert.NotEqual("renamed", DaoRename(ace, table, index, newName)); + + string libred = TemporaryDatabase.CopyPath(start, "rnix-lib-"); + using (var db = JetDatabase.Open(libred, readOnly: false)) + Assert.Throws(() => db.RenameIndex(table, index, newName)); + + Assert.Equal("", DropTableParityAccessTests.Difference(start, ace)); + Assert.Equal("", DropTableParityAccessTests.Difference(start, libred)); + } + + private static string CreateStart() + { + string start = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "rnix-start-"); + using (OleDbConnection connection = AceTestDatabase.Open(start)) + { + Exec(connection, "CREATE TABLE Parent (Id LONG, CONSTRAINT PK_Parent PRIMARY KEY (Id))"); + Exec(connection, "CREATE TABLE Child (Id LONG, ParentId LONG, Label TEXT(10), CONSTRAINT PK_Child PRIMARY KEY (Id), " + + "CONSTRAINT FK_Child_Parent FOREIGN KEY (ParentId) REFERENCES Parent (Id))"); + Exec(connection, "CREATE INDEX IX_Label ON Child (Label)"); + Exec(connection, "INSERT INTO Parent VALUES (1)"); + Exec(connection, "INSERT INTO Child VALUES (1, 1, 'a')"); + Exec(connection, $"CREATE TABLE Wide (Id LONG{string.Concat(Enumerable.Range(1, 254).Select(i => $", c{i:D3} CURRENCY"))})"); + Exec(connection, "CREATE INDEX IX_Wide ON Wide (c001)"); + } + OleDbConnection.ReleaseObjectPool(); + return start; + } + + /// "renamed", or the message DAO refused the rename with. + private static string DaoRename(string path, string table, string index, string newName) + { + dynamic engine = AceTestDatabase.CreateDaoEngine() + ?? throw new InvalidOperationException("DAO is not registered in this process."); + dynamic database = engine.OpenDatabase(path); + try + { + database.TableDefs[table].Indexes[index].Name = newName; + return "renamed"; + } + catch (System.Runtime.InteropServices.COMException e) + { + return e.Message; + } + finally + { + database.Close(); + AceTestDatabase.ReleaseAbandonedComObjects(); + } + } + + private static void Exec(OleDbConnection connection, string sql) + { + using OleDbCommand command = connection.CreateCommand(); + command.CommandText = sql; + command.ExecuteNonQuery(); + } +} diff --git a/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs b/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs index f5373efd..1f1782cd 100644 --- a/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs +++ b/test/LibRed.Core.AccessTests/RenameNameValidationAccessTests.cs @@ -185,6 +185,39 @@ public void Refusing_the_rename_leaves_a_database_ace_can_still_open() Assert.Equal("hello", read.ExecuteScalar()); } + // A damaged file can hold a name ACE's DDL refuses — here SupplierID's 'r' made U+0003. ACE reads it as stored: + // the table opens and SELECT * names the column so. Renamed away through DAO, it cannot be given back: "'…' is + // not a valid name" (measured). LibRed reads it the same way and refuses the rename back as it refuses the name + // from any caller. + [Fact] + public void A_stored_name_create_would_refuse_still_reads_but_cannot_be_given_back() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "rename-stored-name-"); + string damaged = "Supplie" + (char)3 + "ID"; + int page; + using (var database = JetDatabase.Open(path)) page = database.Catalog.FindTable("Suppliers")!.DefinitionPage; + byte[] file = File.ReadAllBytes(path); + int pageSize = Formats.JetFormatBase.FromVersionByte(file[0x14]).PageSize; + int at = file.AsSpan(page * pageSize, pageSize).IndexOf(System.Text.Encoding.Unicode.GetBytes("SupplierID")); + Assert.True(at >= 0); + System.Text.Encoding.Unicode.GetBytes(damaged).CopyTo(file, page * pageSize + at); + File.WriteAllBytes(path, file); + + using (OleDbConnection connection = AceTestDatabase.Open(path)) + using (OleDbCommand read = connection.CreateCommand()) + { + read.CommandText = "SELECT * FROM Suppliers"; + using OleDbDataReader reader = read.ExecuteReader(); + Assert.Equal(damaged, reader.GetName(0)); + } + + using var libred = JetDatabase.Open(path, readOnly: false); + Assert.Equal(damaged, libred.Catalog.FindTable("Suppliers")!.Columns[0].Name); + Assert.Equal(29, libred.OpenTable("Suppliers").Rows().Count()); + Assert.True(libred.RenameColumn("Suppliers", damaged, "Renamed")); + Assert.Throws(() => libred.RenameColumn("Suppliers", "Renamed", damaged)); + } + private static JetDatabase Fresh(out string path) { path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "rename-name-"); diff --git a/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj b/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj new file mode 100644 index 00000000..998e1c49 --- /dev/null +++ b/test/LibRed.Core.Fuzz/LibRed.Core.Fuzz.csproj @@ -0,0 +1,43 @@ + + + + Exe + $(JetTargetFramework) + LibRed.Core.Fuzz + enable + enable + false + AnyCPU;x86;x64 + + true + $(MSBuildThisFileDirectory)..\..\Key.snk + + + + + + + + + + + + + + + + Data\Northwind.accdb + PreserveNewest + + + Data\EncryptedTest.accdb + PreserveNewest + + + + diff --git a/test/LibRed.Core.Fuzz/Program.cs b/test/LibRed.Core.Fuzz/Program.cs new file mode 100644 index 00000000..f182efee --- /dev/null +++ b/test/LibRed.Core.Fuzz/Program.cs @@ -0,0 +1,164 @@ +using System.Buffers.Binary; +using System.Runtime.ExceptionServices; +using LibRed.Catalog; +using LibRed.Formats; +using LibRed.Tests.Shared; +using SharpFuzz; + +namespace LibRed.Core.Fuzz; + +// Coverage-guided fuzzing of LibRed.Core with SharpFuzz + libFuzzer. See README.md for how to run it. +// +// Every target holds LibRed to the contract MalformedFile states: a damaged input may throw +// InvalidDataException, NotSupportedException or UnauthorizedAccessException and nothing else. Anything else +// escaping a target is a crash to libFuzzer. Hangs and runaway allocations are libFuzzer's -timeout and +// -rss_limit_mb, which is the half of the problem the fixed-seed sweep in LibRed.Core.Tests cannot see. +// +// Two ways in: +// LIBRED_FUZZ_TARGET=, run under libfuzzer-dotnet — fuzz (libfuzzer-dotnet passes one argument, +// the dll, so the target travels in the env) +// dotnet LibRed.Core.Fuzz.dll replay — run saved inputs (a crash, a corpus) once +// each, uninstrumented, and report any leak +internal static class Program +{ + private static int Main(string[] args) + { + if (args is ["replay", string replayTarget, string input]) + return Replay(Target(replayTarget), input); + + string? name = Environment.GetEnvironmentVariable("LIBRED_FUZZ_TARGET"); + if (name is null || args is ["replay", ..]) + { + Console.Error.WriteLine("Fuzz: set LIBRED_FUZZ_TARGET and run under libfuzzer-dotnet (see README.md)"); + Console.Error.WriteLine("Replay: LibRed.Core.Fuzz replay "); + Console.Error.WriteLine($"Targets: {string.Join(", ", Targets)}"); + return 2; + } + + Fuzzer.LibFuzzer.Run(Target(name)); + return 0; + } + + private static readonly string[] Targets = ["database", "writes", "properties", "namemap"]; + + private static ReadOnlySpanAction Target(string name) => name switch + { + "database" => new DatabaseTarget(write: false).Run, + "writes" => new DatabaseTarget(write: true).Run, + "properties" => Properties, + "namemap" => NameMapBlob, + _ => throw new ArgumentException($"Unknown target '{name}'. Targets: {string.Join(", ", Targets)}.", nameof(name)), + }; + + /// An LvProp property blob, as the catalog reads one for every table. + private static void Properties(ReadOnlySpan data) + { + try { PropertyBlob.Read(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + } + + /// A name map, in both of its stored layouts: an MSysNameMap row and an LvProp + /// property. + private static void NameMapBlob(ReadOnlySpan data) + { + try { NameMap.ReadRow(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + try { NameMap.ReadProperty(data); } + catch (Exception e) when (MalformedFile.IsExpected(e)) { } + } + + /// Runs each saved input through once and reports what leaks. + private static int Replay(ReadOnlySpanAction target, string input) + { + string[] files = Directory.Exists(input) ? Directory.GetFiles(input) : [input]; + int leaks = 0; + foreach (string file in files) + { + try { target(File.ReadAllBytes(file)); } + catch (Exception e) + { + leaks++; + Console.WriteLine($"LEAK {Path.GetFileName(file)}: {e}"); + } + } + Console.WriteLine($"{files.Length} inputs, {leaks} leaked"); + return leaks == 0 ? 0 : 1; + } +} + +/// +/// A whole database, damaged by the fuzz input and then walked as a caller would (MalformedFile.Exercise) — +/// read only, or with a row of each user table rewritten, deleted and inserted again on the way. +/// +/// +/// The input is not a file. A database is hundreds of pages and libfuzzer-dotnet carries at most 1 MiB, and +/// mutating a whole file spends nearly every mutation on row data. So the input is a patch list against one of +/// a fixed set of good seed databases: [seed][page u16][offset u16][byte]…, each field reduced modulo +/// what it indexes. Inputs stay a few bytes long, every one decodes to a database, and libFuzzer still learns +/// which patches reach new code. Unlike the sweep, page 0 and every offset are in range. The first byte's +/// quotient by the seed count is the write workload's operation flags (). +/// +internal sealed class DatabaseTarget +{ + private const int PatchSize = 5; + + private readonly bool _write; + private readonly string _directory; + private readonly string _path; + private (string Shape, byte[] Bytes, int PageSize, string? Password)[]? _seeds; + + public DatabaseTarget(bool write) + { + _write = write; + _directory = Path.Combine(Path.GetTempPath(), $"libred-fuzz-{Guid.NewGuid():N}"); + Directory.CreateDirectory(_directory); + // libFuzzer ends the process on a crash, which skips this; the folder is then left in %TEMP%. + AppDomain.CurrentDomain.ProcessExit += (_, _) => + { + try { Directory.Delete(_directory, recursive: true); } catch (IOException) { /* best effort */ } + }; + + // One path, rewritten every run. The page cache and lock registries are per path and released on the + // last close, so a run that leaves a handle open fails the next write — a leak worth seeing. + _path = Path.Combine(_directory, "input.accdb"); + } + + public void Run(ReadOnlySpan data) + { + if (data.Length == 0) return; + // Built on the first input, not in the constructor: authoring the seeds and detecting their page size + // run instrumented LibRed.Core code, and SharpFuzz's coverage map only exists once Fuzzer.LibFuzzer.Run + // has started — instrumented code called before that dereferences a null map. + _seeds ??= LoadSeeds(); + (_, byte[] clean, int pageSize, string? password) = _seeds[data[0] % _seeds.Length]; + + byte[] bytes = (byte[])clean.Clone(); + int pages = bytes.Length / pageSize; + for (int i = 1; i + PatchSize <= data.Length; i += PatchSize) + { + int page = BinaryPrimitives.ReadUInt16LittleEndian(data[i..]) % pages; + int offset = BinaryPrimitives.ReadUInt16LittleEndian(data[(i + 2)..]) % pageSize; + bytes[page * pageSize + offset] = data[i + 4]; + } + File.WriteAllBytes(_path, bytes); + + // The rest of the first byte picks the write workload's operations, so a patch list keeps its meaning. + foreach ((_, Exception? leak) in MalformedFile.Exercise(_path, password, _write, operations: data[0] / _seeds.Length)) + if (leak is not null) + ExceptionDispatchInfo.Throw(leak); + } + + private (string Shape, byte[] Bytes, int PageSize, string? Password)[] LoadSeeds() + { + string data = Path.Combine(AppContext.BaseDirectory, "Data"); + var sources = MalformedFile.Sources(_directory, Path.Combine(data, "Northwind.accdb")) + .Select(s => (s.Shape, s.Path, Password: (string?)null)) + .Append(("encrypted", Path.Combine(data, "EncryptedTest.accdb"), "Test")); + + return [.. sources.Select(s => + { + byte[] bytes = File.ReadAllBytes(s.Item2); + return (s.Item1, bytes, JetFormatBase.Detect(new MemoryStream(bytes)).PageSize, s.Item3); + })]; + } +} diff --git a/test/LibRed.Core.Fuzz/README.md b/test/LibRed.Core.Fuzz/README.md new file mode 100644 index 00000000..c471ba5e --- /dev/null +++ b/test/LibRed.Core.Fuzz/README.md @@ -0,0 +1,120 @@ +# LibRed.Core.Fuzz + +Coverage-guided fuzzing of `LibRed.Core` with [SharpFuzz](https://github.com/Metalnem/sharpfuzz) and libFuzzer. +SharpFuzz rewrites `LibRed.Core.dll` to report the branches each input reaches; libFuzzer keeps the inputs that +reach new ones and mutates those. + +The contract is the one the fixed-seed sweep in `LibRed.Core.Tests` (`CorruptFileSweepProbeTests`) enforces, and +both read it from the same file, `test/LibRed.Shared/MalformedFile.cs`: damaged bytes may throw +`InvalidDataException`, `NotSupportedException` or `UnauthorizedAccessException`, and **anything else escaping is +a crash**. On top of that, libFuzzer reports what the sweep cannot see: a **hang** (`-timeout`, e.g. a page chain +that loops) and a **runaway allocation** (`-rss_limit_mb`, e.g. a length field taken at its word). + +The sweep stays the regression guard; this is the search. Nothing here runs in CI. + +## Targets + +| `LIBRED_FUZZ_TARGET` | Input | What it drives | +| --- | --- | --- | +| `database` | a patch list (below) | open, catalog, every table's rows, every index's entries — `MalformedFile.Exercise` | +| `writes` | a patch list (below) | the same walk opened for writing: in each user table still listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted again, then the operations the input selects run (below), before its indexes are walked | +| `properties` | raw bytes | `PropertyBlob.Read`, the `LvProp` blob decoder | +| `namemap` | raw bytes | `NameMap.ReadRow` and `NameMap.ReadProperty` | + +**The `database` and `writes` input is not a file.** A database is hundreds of pages, libfuzzer-dotnet carries at most 1 MiB, +and mutating a whole file spends nearly every mutation on row data. Instead the input is +`[seed][page u16][offset u16][byte]…`, applied to one of six good databases built at startup: Northwind, the four +shapes `MalformedFile.Sources` authors (multi-page TDEF, long values, split index, altered columns), and the Agile +-encrypted fixture opened with its password. Every field is reduced modulo what it indexes, so every input decodes +to a database, page 0 included. + +`writes` holds the write paths to the same contract with one widening: a write may also refuse with +`InvalidOperationException`. Damage to a schema routinely makes a row's own values break it — a Null key, a value +past its column, a record past the page, a write-once column — and the write API refuses those as ACE does, so +treating them as leaks only buries the real findings: an out-of-range index, a null reference, an overflow, a hang. +The cost is that damage which surfaces as `InvalidOperationException` goes unflagged here. The two targets take +the same inputs, so `corpus\database` is a good starting corpus for `corpus\writes`. + +**The first byte also picks the `writes` workload.** Its remainder by six is the seed; its quotient is a set of +flags, bit *n* selecting entry *n* of `MalformedFile.Operations`, run on every user table in this order: + +| Bit | Operation | What it reaches | +| --- | --- | --- | +| 0 | long values | a 9,000-byte value into every Memo and OLE column of the first row, then null: long-value chains allocated and freed | +| 1 | add and drop columns | a Long and a Text column added and dropped: four definition rewrites | +| 2 | create and drop an index | an index built from the table's rows over its first Long or Text column, then dropped | +| 3 | delete and roll back | the first 32 rows deleted by a statement that rolls back | +| 4 | rename and rename back | the table and its first column renamed and named back | +| 5 | drop the table | every page the table owns freed, then released at close | + +Each runs as one statement, in a transaction of its own that a refusal rolls back, as `QueryEngine` runs a writing +statement. A byte holds at most 42 as a quotient, so a single input reaches every operation alone and many of their +combinations, not all of them at once. An input written before the workload existed keeps its patches: it simply +runs the operations its first byte now selects after the row rewrite it always ran. + +## Running it + +You need the SharpFuzz instrumenter and the libFuzzer driver. Both are third-party downloads, not restored by the +build: + +- `dotnet tool install --global SharpFuzz.CommandLine` +- **libfuzzer-dotnet** from — the Windows build is + `libfuzzer-dotnet-windows.exe`. On Linux, build it: `clang -fsanitize=fuzzer libfuzzer-dotnet.cc -o libfuzzer-dotnet`. + +Publish, then instrument **only `LibRed.Core.dll`** — coverage from anything else is noise, and the harness +assembly itself must stay uninstrumented: + +```powershell +dotnet publish test\LibRed.Core.Fuzz -c Release -o fuzz-bin +sharpfuzz fuzz-bin\LibRed.Core.dll +``` + +`sharpfuzz` rewrites the dll in place, so publish afresh rather than instrumenting a dll that already has been. + +Then fuzz one target. libfuzzer-dotnet passes the child exactly one argument (the dll), so the target goes in the +environment. The corpus directory may start empty; libFuzzer grows it. + +```powershell +$env:LIBRED_FUZZ_TARGET = "writes" +mkdir corpus\writes +libfuzzer-dotnet-windows.exe --target_path=dotnet --target_arg=fuzz-bin\LibRed.Core.Fuzz.dll ` + -timeout=10 -rss_limit_mb=4096 -max_len=256 ` + -use_value_profile=1 "-dict=test\LibRed.Core.Fuzz\database.dict" corpus\writes +``` + +The quotes matter in PowerShell: an argument that starts with `-` and contains a `.` is otherwise split at the dot, +and libFuzzer then takes `.Core.Fuzz\database.dict` for a corpus directory that does not exist. + +`-use_value_profile=1` makes libFuzzer count a comparison that got closer as new coverage, which is what gets a +patch past a check on one exact value — a type code, a flag bit, a page number. `database.dict` gives the mutator the +multi-byte values it is slow to guess at random: the u16 page numbers and offsets of the fields a reader steers by +(page 0's map pointers, the TDEF counters, a column descriptor's type and flags) and the values they take. Both apply +to `database` as well; the blob targets want neither. + +`-max_len=256` is about 50 patches, plenty for `database`; the blob targets want more (`-max_len=4096`). Every +`database` run copies and writes a seed file, so it is the slow target — `replay` gets through 300 random inputs +in about four seconds, startup and authoring the seeds included, uninstrumented — and the blob targets are far +faster. Add `-jobs=N -workers=N` to use more cores, `-max_total_time=` to stop on a budget. + +**When a run stops finding anything, change what it is given rather than running it longer.** Merge what earlier +runs found into a fresh, minimal corpus — libFuzzer keeps only the inputs that still add coverage — and start the +next run from that: + +```powershell +mkdir corpus\merged +libfuzzer-dotnet-windows.exe --target_path=dotnet --target_arg=fuzz-bin\LibRed.Core.Fuzz.dll ` + -merge=1 -timeout=10 -rss_limit_mb=4096 corpus\merged corpus\writes corpus\database +``` + +## When it finds something + +libFuzzer stops and writes the input as `crash-` (or `timeout-…`, `oom-…`) in the current directory. +Replay it uninstrumented for the full stack: + +```powershell +dotnet fuzz-bin\LibRed.Core.Fuzz.dll replay database crash- +``` + +`replay` also takes a directory, running every input in it and exiting non-zero if any leaks — useful to check a +corpus against a fix. A leak is fixed in the reader, where the bad value is first read, as the throw site of an +`InvalidDataException` that says what was wrong; never by widening the contract. diff --git a/test/LibRed.Core.Fuzz/database.dict b/test/LibRed.Core.Fuzz/database.dict new file mode 100644 index 00000000..91a962d6 --- /dev/null +++ b/test/LibRed.Core.Fuzz/database.dict @@ -0,0 +1,63 @@ +# libFuzzer dictionary for the database and writes targets (-dict=test\LibRed.Core.Fuzz\database.dict). +# +# The input is a patch list, [seed][page u16][offset u16][byte]..., so the entries that help are the ones random +# mutation is slow to find: little-endian u16 page numbers and in-page offsets of fields that steer a reader, and +# the byte values those fields take. Offsets are Jet 4 / ACE (src/LibRed/LibRed.Core/Formats/Jet4Format.cs). + +# Pages: the database definition, the global maps' holder, the first catalog pages. +page_0="\x00\x00" +page_1="\x01\x00" +page_2="\x02\x00" +page_3="\x03\x00" + +# Page 0: version byte, free-pages and released-pages map pointers. +p0_version="\x14\x00" +p0_free_map="\x18\x00" +p0_free_map_page="\x19\x00" +p0_released_map="\x1c\x00" +p0_released_map_page="\x1d\x00" + +# Data and TDEF page header: owner, row count; TDEF row count and AutoNumber counter. +data_owner="\x04\x00" +data_rows="\x0c\x00" +tdef_rows="\x10\x00" +tdef_autonumber="\x14\x00" + +# Patch bytes: boundaries, sign bits, and the column flag bits (fixed 0x01, updatable 0x02, AutoNumber 0x04, +# GUID 0x40, hyperlink 0x80) and extended flag bits (calculated 0x40, evaluate 0x80). +b_00="\x00" +b_01="\x01" +b_02="\x02" +b_04="\x04" +b_06="\x06" +b_40="\x40" +b_7f="\x7f" +b_80="\x80" +b_c0="\xc0" +b_ff="\xff" + +# Column type codes. +type_boolean="\x01" +type_byte="\x02" +type_int16="\x03" +type_int32="\x04" +type_currency="\x05" +type_single="\x06" +type_double="\x07" +type_datetime="\x08" +type_binary="\x09" +type_text="\x0a" +type_ole="\x0b" +type_memo="\x0c" +type_guid="\x0f" +type_numeric="\x10" +type_complex="\x12" +type_bigint="\x13" +type_datetime2="\x14" + +# Wide values for multi-byte fields (counts, pointers, start pages). +u16_max="\xff\xff" +u16_signed_max="\xff\x7f" +u16_signed_min="\x00\x80" +u32_max="\xff\xff\xff\xff" +u32_signed_min="\x00\x00\x00\x80" diff --git a/test/LibRed.Core.Tests/CatalogTests.cs b/test/LibRed.Core.Tests/CatalogTests.cs index fa85ce02..512416ec 100644 --- a/test/LibRed.Core.Tests/CatalogTests.cs +++ b/test/LibRed.Core.Tests/CatalogTests.cs @@ -40,4 +40,112 @@ public void Resolves_full_column_lists() Assert.Equal(14, db.Catalog.FindTable("Orders")!.Columns.Count); } + + // MSysRelationships.szColumn's type byte damaged from Text (0x0A) to 0x0D, a code no type has. The catalog reads + // that column as text and cannot, so the relationships are refused while every table still reads — as ACE + // refuses its foreign-key list on this damage ("Cannot perform this operation") and reads the tables (measured). + [Fact] + public void A_catalog_column_of_another_type_refuses_that_catalog_table_only() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-type-"); + try + { + int page, userTables; + byte[] raw; + using (var db = JetDatabase.Open(path)) + { + userTables = db.Catalog.UserTables.Count(); + Catalog.TableDefinition relationships = db.Catalog.FindTable("MSysRelationships")!; + page = relationships.DefinitionPage; + raw = relationships.FindColumn("szColumn")!.RawDescriptor!; + } + byte[] file = File.ReadAllBytes(path); + Formats.JetFormatBase format = Formats.JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + Assert.Equal((byte)Catalog.JetDataType.Text, file[page * format.PageSize + at + format.ColumnTypeOffset]); + file[page * format.PageSize + at + format.ColumnTypeOffset] = 0x0D; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path); + Assert.Throws(() => damaged.Catalog.Relationships); + Assert.Equal(91, damaged.OpenTable("Customers").Rows().Count()); + Assert.Equal(userTables, damaged.Catalog.UserTables.Count()); + } + finally { TemporaryDatabase.Delete(path); } + } + + // One column's name damaged into another's: c4 made c3. ACE reads the table and resolves the name to the first + // column that has it — SELECT c3 reads c3's value — and CREATE INDEX succeeds over that name and over another + // column (measured on this shape). + [Fact] + public void A_name_two_columns_share_resolves_to_the_first_of_them() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-dupname-"); + try + { + int page; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("Wide", + [.. Enumerable.Range(0, 6).Select(i => new Catalog.ColumnSpec($"c{i}", Catalog.JetDataType.Int32, 4, IsFixedLength: true))]); + db.OpenTable("Wide").Insert([0, 1, 2, 3, 4, 5]); + page = db.Catalog.FindTable("Wide")!.DefinitionPage; + } + byte[] file = File.ReadAllBytes(path); + int pageSize = Formats.JetFormatBase.FromVersionByte(file[0x14]).PageSize; + // c4's name entry: its length, then the name in UTF-16. + int at = file.AsSpan(page * pageSize, pageSize).IndexOf((byte[])[4, 0, (byte)'c', 0, (byte)'4', 0]); + Assert.True(at >= 0); + file[page * pageSize + at + 4] = (byte)'3'; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Assert.Equal(["c0", "c1", "c2", "c3", "c3", "c5"], damaged.Catalog.FindTable("Wide")!.Columns.Select(c => c.Name)); + damaged.CreateIndex("Wide", "I0", [("c0", false)]); + damaged.CreateIndex("Wide", "I3", [("c3", false)]); + Assert.Equal(3, damaged.Catalog.FindTable("Wide")!.FindIndex("I3")!.Columns.Single().Column.ColumnId); + } + finally { TemporaryDatabase.Delete(path); } + } + + // One MSysRelationships row with one column made NULL through its null bitmap. ACE's foreign-key list leaves out + // the relationship whose row names no child or parent table, and lists it all the same with a null name, flags, + // column order or column (measured on this file's first row, FK_CustomerCustomerDemo: 14 and 15 of 15). + [Theory] + [InlineData("szObject", true)] + [InlineData("szReferencedObject", true)] + [InlineData("szRelationship", false)] + [InlineData("grbit", false)] + [InlineData("icolumn", false)] + [InlineData("szColumn", false)] + public void A_null_in_a_relationship_row_leaves_it_out_only_when_it_names_no_table(string column, bool leftOut) + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "catalog-relnull-"); + try + { + int offset, bit, relationships; + using (var db = JetDatabase.Open(path)) + { + relationships = db.Catalog.Relationships.Count; + Storage.Table rel = db.OpenTable("MSysRelationships"); + int columnId = rel.Definition.FindColumn(column)!.ColumnId; + var (id, _) = rel.Rows().WithIds().First(); + Formats.JetFormatBase format = db.Channel.Format; + Assert.True(Pages.DataPage.TryReadRow(db.Channel.ReadPage(id.Page), format, id.Row, + out Pages.DataPage.RowSlot slot, out ReadOnlySpan row)); + int bitmapSize = Storage.BitmapBits.ByteCount(System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(row)); + offset = id.Page * format.PageSize + slot.Offset + slot.Length - bitmapSize + (columnId >> 3); + bit = 1 << (columnId & 7); + } + byte[] bytes = File.ReadAllBytes(path); + Assert.NotEqual(0, bytes[offset] & bit); + bytes[offset] &= (byte)~bit; + File.WriteAllBytes(path, bytes); + + using var damaged = JetDatabase.Open(path); + Assert.Equal(leftOut ? relationships - 1 : relationships, damaged.Catalog.Relationships.Count); + } + finally { TemporaryDatabase.Delete(path); } + } } diff --git a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs index 86ff7edc..1c2e29e9 100644 --- a/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs +++ b/test/LibRed.Core.Tests/ColumnDescriptorFlagTests.cs @@ -29,7 +29,9 @@ public void BuildColumnDescriptor_composes_the_documented_flags_from_the_model() } // ACE writes 0xC0 on a calculated column but reads only 0x40: with 0x80 alone a column is an ordinary one, its - // value read as stored, and with 0x40 alone it is calculated (measured by patching the bit into a text column). + // value read as stored, and with 0x40 alone it is calculated (measured by patching the bit into a text column) — + // here one with no Expression property, so ACE will not load the table: SELECT, COUNT(*) and the column schema + // all fail "Property not found." (measured on this very file). [Theory] [InlineData(0x80, false)] [InlineData(0x40, true)] @@ -58,10 +60,15 @@ public void Only_bit_0x40_makes_a_column_calculated(byte bit, bool calculated) File.WriteAllBytes(path, file); using var read = JetDatabase.Open(path); + if (calculated) + { + Assert.Throws(() => read.OpenTable("T")); + return; + } Table table = read.OpenTable("T"); ColumnDef column = table.Definition.FindColumn("A")!; - Assert.Equal(calculated, column.IsCalculated); - if (!calculated) Assert.Equal("plain", table.Rows().Single()[column.Index]); + Assert.False(column.IsCalculated); + Assert.Equal("plain", table.Rows().Single()[column.Index]); } finally { TemporaryDatabase.Delete(path); } } @@ -198,6 +205,150 @@ public void A_write_once_column_takes_a_value_on_insert_and_refuses_one_on_updat finally { TemporaryDatabase.Delete(path); } } + // The AutoNumber bit 0x04 on a Text column (a damaged descriptor): ACE still takes an explicit value, and sets the + // counter at 0x14 to the value's first four bytes as UTF-16LE, zero-padded (measured: Customers.Address flagged, + // "Street", "500" and "A" inserted). + [Theory] + [InlineData("Street", 0x00740053)] + [InlineData("500", 0x00300035)] + [InlineData("A", 65)] + public void An_explicit_value_in_a_text_column_flagged_AutoNumber_sets_the_counter_to_its_first_four_bytes( + string value, int counter) + { + string path = TemporaryDatabase.CreatePath("autonumber-text-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("A")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + int Counter() => TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format); + Assert.Equal(0, Counter()); + + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("A")!.IsAutoNumber); + table.Insert([1, value]); + Assert.Equal([1, value], table.Rows().Single()); + } + Assert.Equal(counter, Counter()); + } + finally { TemporaryDatabase.Delete(path); } + } + + // The same bit on an OLE column: an explicit binary value sets the counter to its first four bytes (measured: + // Categories.Picture flagged, bytes 01 02 03 04 05 06 set 0x14 to 0x04030201). + [Fact] + public void An_explicit_value_in_an_ole_column_flagged_AutoNumber_sets_the_counter_to_its_first_four_bytes() + { + string path = TemporaryDatabase.CreatePath("autonumber-ole-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("P", JetDataType.Ole, 0, IsFixedLength: false)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("P")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + + byte[] value = [1, 2, 3, 4, 5, 6]; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("P")!.IsAutoNumber); + table.Insert([1, value]); + Assert.Equal(value, table.Rows().Single()[1]); + } + Assert.Equal(0x04030201, TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format)); + } + finally { TemporaryDatabase.Delete(path); } + } + + // The same bit on fixed columns. A 4-byte Single takes its own bits as the counter; a column of any other width + // cannot hold the 4-byte counter, and ACE refuses the row — explicit value and all — with the id burned + // (measured: Order Details.Discount 0.25 set 0x14 to 0x3E800000; Quantity, UnitPrice, Orders.Freight and + // OrderDate refused "The field is too small to accept the amount of data you attempted to add.", 0x14 + 1). + [Theory] + [InlineData(JetDataType.Single, 4, 0.25f, 0x3E800000, false)] + [InlineData(JetDataType.Int16, 2, (short)-2, 1, true)] + [InlineData(JetDataType.Currency, 8, 12.5, 1, true)] + [InlineData(JetDataType.DateTime, 8, "2000-01-02", 1, true)] + public void An_explicit_value_in_a_fixed_column_flagged_AutoNumber_needs_four_bytes( + JetDataType type, int length, object value, int counter, bool refused) + { + string path = TemporaryDatabase.CreatePath("autonumber-fixed-"); + try + { + JetDatabase.Create(path); + int page; + byte[] raw; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("V", type, length, IsFixedLength: true)]); + var t = db.Catalog.FindTable("T")!; + page = t.DefinitionPage; + raw = t.FindColumn("V")!.RawDescriptor!; + } + + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + file[page * format.PageSize + at + format.ColumnFlagsOffset] |= (byte)ColumnFlags.AutoNumber; + File.WriteAllBytes(path, file); + + object stored = type switch + { + JetDataType.Currency => Convert.ToDecimal(value, System.Globalization.CultureInfo.InvariantCulture), + JetDataType.DateTime => DateTime.Parse((string)value, System.Globalization.CultureInfo.InvariantCulture), + _ => value, + }; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Table table = db.OpenTable("T"); + Assert.True(table.Definition.FindColumn("V")!.IsAutoNumber); + if (refused) + { + var ex = Assert.Throws(() => table.Insert([1, stored])); + Assert.Contains("too small to accept", ex.Message, StringComparison.Ordinal); + Assert.Empty(table.Rows()); + } + else + { + table.Insert([1, stored]); + Assert.Equal([1, stored], table.Rows().Single()); + } + } + Assert.Equal(counter, TableDefinition.ReadLastAutoNumber(TestDatabases.ReadPage(path, page), format)); + } + finally { TemporaryDatabase.Delete(path); } + } + // Without 0x80 ACE will not evaluate a calculated column, whatever its expression: every read of it fails "This // calculated column contains an invalid expression" (measured by clearing the bit on a DAO-created [Qty]*2). [Fact] diff --git a/test/LibRed.Core.Tests/ComplexColumnTests.cs b/test/LibRed.Core.Tests/ComplexColumnTests.cs index 3dd3665f..045474a9 100644 --- a/test/LibRed.Core.Tests/ComplexColumnTests.cs +++ b/test/LibRed.Core.Tests/ComplexColumnTests.cs @@ -379,6 +379,42 @@ public void A_column_that_is_not_complex_is_rejected() Assert.Throws(() => db.ReadComplexValues("Customers", "CustomerID", 1)); } + // MSysComplexColumns.ConceptualTableID's type byte damaged from Long (0x04) to Byte (0x02): a write still looks up + // its table's complex columns there, by the table's definition page — 283 for Shippers, which no Byte holds. ACE + // inserts and deletes a Shippers row on this file as usual (measured), and so does LibRed. + [Fact] + public void A_write_goes_ahead_when_the_registry_types_its_owner_column_as_another_kind() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "complex-owner-type-"); + try + { + int page; + byte[] raw; + using (var db = JetDatabase.Open(path)) + { + TableDefinition registry = db.Catalog.FindTable("MSysComplexColumns")!; + page = registry.DefinitionPage; + raw = registry.FindColumn("ConceptualTableID")!.RawDescriptor!; + Assert.True(db.Catalog.FindTable("Shippers")!.DefinitionPage > byte.MaxValue); + } + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(raw); + Assert.True(at >= 0); + Assert.Equal((byte)JetDataType.Int32, file[page * format.PageSize + at + format.ColumnTypeOffset]); + file[page * format.PageSize + at + format.ColumnTypeOffset] = (byte)JetDataType.Byte; + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + var shippers = damaged.OpenTable("Shippers"); + shippers.Insert([null, "Fuzz", null]); + var (id, _) = shippers.Rows().WithIds().Single(r => (string?)r.Values[1] == "Fuzz"); + shippers.Delete(id); + Assert.Equal(3, shippers.Rows().Count()); + } + finally { TemporaryDatabase.Delete(path); } + } + [Theory] [InlineData(new byte[] { 1, 2, 3 })] // shorter than the outer header [InlineData(new byte[] { 9, 0, 0, 0, 4, 0, 0, 0, 1, 2, 3, 4 })] // unknown compression flag diff --git a/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs b/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs index 6fe3b6eb..5335b45e 100644 --- a/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs +++ b/test/LibRed.Core.Tests/CorruptFileSweepProbeTests.cs @@ -1,46 +1,20 @@ -using LibRed; -using LibRed.Catalog; -using LibRed.Storage; using Xunit; namespace LibRed.Core.Tests; // Structural mutation sweep: take a good database, corrupt one field of one page header, and drive every -// read path over the result. -// -// The contract is not "must not throw" — a damaged file SHOULD throw. It is that a damaged file must throw -// InvalidDataException, LibRed's one signal for "these bytes are not a valid database". A caller that wants -// to tell a corrupt file from a bug in the reader has nothing else to catch, and .NET gives it no help: the -// exceptions a parser leaks by accident (ArgumentOutOfRangeException, IndexOutOfRangeException, -// EndOfStreamException) share no base class with InvalidDataException, which derives from SystemException -// rather than IOException. An unhandled one does not degrade, it crashes the caller. -// -// The source databases are AUTHORED HERE, not read from a corpus. Two reasons that matters: -// -// * Coverage is otherwise bounded by whatever one fixture happens to contain. Northwind has no multi-page -// TDEF, no chained long value, no dropped-then-added column and no deep index, so those decode paths -// would never see a corrupt byte at all. LibRed can synthesise a file page-by-page, so the awkward -// shapes are ours to make. -// * A file LibRed wrote tests our reader against our own writer. A leak then points at one of the two, -// rather than at "ACE wrote something we mishandle". -// -// Northwind stays in the set as the one ACE-authored shape, since agreeing with a real Access file is the -// whole point of the format work. +// read path over the result. What counts as a leak, the databases corrupted and the walk over them live in +// MalformedFile (test/LibRed.Shared), shared with the coverage-guided harness in LibRed.Core.Fuzz. public class CorruptFileSweepProbeTests(ITestOutputHelper output) { - /// The exception types a malformed file is allowed to produce. - private static bool IsExpected(Exception e) => - e is InvalidDataException // the contract: these bytes are not a database - or NotSupportedException // a real feature LibRed does not implement yet - or UnauthorizedAccessException; // encrypted, wrong or missing password - [Fact] public void No_structural_mutation_escapes_an_unexpected_exception_type() { // Deliberately small and fixed-seed: this is a REGRESSION guard, not a search. It runs the same 600 // mutations every time, so once green it stays green and finds nothing new. Discovery means raising // this and varying the seed in an offline run — done at 2500 (12,500 mutations, 208k table reads, - // 236k index walks, ~2 min) with no leaks, which is what the committed size is guarding. + // 236k index walks, ~2 min) with no leaks, which is what the committed size is guarding. Open-ended + // search is LibRed.Core.Fuzz's job. const int perSource = 120; var random = new Random(20260907); @@ -52,7 +26,7 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() int mutations = 0, reachedCatalog = 0, readTables = 0, walkedIndexes = 0; try { - foreach ((string shape, string source) in Sources(directory)) + foreach ((string shape, string source) in MalformedFile.Sources(directory, TestDatabases.NorthwindAccdb)) { byte[] clean = File.ReadAllBytes(source); int pageSize = TestDatabases.FormatOf(source).PageSize; @@ -76,7 +50,7 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() mutations++; string where = $"{shape} page {page} offset 0x{offset:X2} = 0x{value:X2}"; - foreach ((string stage, Exception? leak) in Exercise(path)) + foreach ((string stage, Exception? leak) in MalformedFile.Exercise(path)) { if (stage.StartsWith("catalog: ok", StringComparison.Ordinal)) reachedCatalog++; if (stage.StartsWith("table '", StringComparison.Ordinal) @@ -114,148 +88,4 @@ public void No_structural_mutation_escapes_an_unexpected_exception_type() Assert.True(walkedIndexes > 0, "no mutation reached an index page — the sweep proved nothing"); Assert.Empty(leaks); } - - /// - /// The good databases to corrupt: one ACE-authored fixture, then shapes LibRed synthesises itself to - /// reach structures the fixture does not contain. - /// - private static IEnumerable<(string Shape, string Path)> Sources(string directory) - { - yield return ("northwind", TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "fuzz-nw-")); - - yield return ("wide-tdef", Author(directory, "wide-tdef", database => - { - // 200 columns spills the definition onto continuation pages, so the TDEF chain gets fuzzed. - database.CreateTable("Wide", - [.. Enumerable.Range(0, 200).Select(i => new ColumnSpec($"c{i}", JetDataType.Int32, 4, IsFixedLength: true))]); - var table = database.OpenTable("Wide"); - var row = new object?[200]; - for (int i = 0; i < 200; i++) row[i] = i; - table.Insert(row); - })); - - yield return ("long-values", Author(directory, "long-values", database => - { - database.CreateTable("Docs", - [new ColumnSpec("Id", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("Body", JetDataType.Memo, 0, IsFixedLength: false)]); - var table = database.OpenTable("Docs"); - // Inline, single-page and chained, so all three long-value storage forms are present. - foreach ((int id, int length) in new[] { (1, 20), (2, 2000), (3, 40_000) }) - table.Insert([id, new string((char)('a' + id), length)]); - })); - - yield return ("split-index", Author(directory, "split-index", database => - { - database.CreateTable("Keyed", - [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("V", JetDataType.Text, 60, IsFixedLength: false)], - primaryKey: ["K"]); - var table = database.OpenTable("Keyed"); - // Enough rows to drive the B-tree past a single leaf, so node pages exist to corrupt. - for (int i = 0; i < 1500; i++) table.Insert([i, $"value {i}"]); - })); - - yield return ("altered-columns", Author(directory, "altered-columns", database => - { - database.CreateTable("Churn", - [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), - new ColumnSpec("A", JetDataType.Text, 30, IsFixedLength: false), - new ColumnSpec("B", JetDataType.Text, 30, IsFixedLength: false), - new ColumnSpec("N", JetDataType.Int32, 4, IsFixedLength: true)]); - var table = database.OpenTable("Churn"); - table.Insert([1, "a1", "b1", 11]); - - // The gapped index space and burned ids of a table that has been edited — the shapes that - // produced the row-layout bugs, which a freshly created table cannot reach. - database.DropColumn("Churn", "B"); - database.AddColumn("Churn", new ColumnSpec("D", JetDataType.Text, 30, IsFixedLength: false)); - database.OpenTable("Churn").Insert([2, "a2", 22, "d2"]); - database.AlterColumnTypeInPlace("Churn", "N", - new ColumnSpec("N", JetDataType.Text, 20, IsFixedLength: false)); - })); - } - - /// Synthesises a database from scratch and applies to it. - private static string Author(string directory, string name, Action build) - { - string path = Path.Combine(directory, $"source-{name}.accdb"); - JetDatabase.Create(path); - using (var database = JetDatabase.Open(path, readOnly: false)) - build(database); - return path; - } - - /// - /// Walks everything a caller would, one stage at a time and continuing past failures: open, list - /// the catalog, then each table's rows separately. - /// - /// - /// Per-stage on purpose. Stopping at the first exception means one damaged TDEF hides every path behind - /// it, and the interesting leak is rarely the first thing that breaks. - /// - private static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path) - { - JetDatabase? database = null; - try - { - (string open, Exception? leak) = Try("open", () => database = JetDatabase.Open(path)); - yield return (open, leak); - if (database is null) yield break; - - List tables = []; - yield return Try("catalog", () => tables = [.. database.Catalog.Tables]); - - foreach (TableDefinition table in tables) - { - int rows = 0; - (string read, Exception? rowLeak) = Try($"table '{table.Name}'", () => - { - foreach (object?[] _ in database.OpenTable(table.Name).Rows()) rows++; - }); - yield return ($"{read} ({rows} rows)", rowLeak); - - // A table SCAN reads the usage map and the data pages and never descends a B-tree, so - // without this every index page the sweep corrupts goes unread — the split-index shape was - // building node pages that nothing then looked at. Walking the entries decodes every page - // of the index, which is more of it than a handful of seeks would touch. - foreach (IndexDef index in table.Indexes) - { - int entries = 0; - (string walked, Exception? indexLeak) = - Try($"index '{table.Name}.{index.Name}'", () => - { - Table opened = database.OpenTable(table.Name); - foreach ((byte[] _, RowId _) in - new IndexCursor(opened.Channel, index.RootPage).RawEntries()) entries++; - }); - yield return ($"{walked} ({entries} entries)", indexLeak); - } - } - } - finally { database?.Dispose(); } - } - - private static (string Outcome, Exception? Leak) Try(string stage, Action action) - { - try - { - action(); - return ($"{stage}: ok", null); - } - catch (Exception e) when (IsExpected(e)) - { - return ($"{stage}: rejected — {e.GetType().Name}: {Summarise(e.Message)}", null); - } - catch (Exception e) - { - return ($"{stage}: !! LEAKED {e.GetType().Name}: {Summarise(e.Message)}", e); - } - } - - private static string Summarise(string message) - { - string one = message.ReplaceLineEndings(" ").Trim(); - return one.Length <= 100 ? one : one[..100] + "…"; - } -} \ No newline at end of file +} diff --git a/test/LibRed.Core.Tests/GlobalMapPointerTests.cs b/test/LibRed.Core.Tests/GlobalMapPointerTests.cs index 73ca3d0e..bb4b9f54 100644 --- a/test/LibRed.Core.Tests/GlobalMapPointerTests.cs +++ b/test/LibRed.Core.Tests/GlobalMapPointerTests.cs @@ -126,6 +126,30 @@ public void Released_pages_at_the_end_of_the_file_are_materialized_but_not_alloc finally { TemporaryDatabase.Delete(path); } } + // 0x18 aimed at row 0 of page 94, a long value of 4,076 bytes: read as an inline map it starts at page 352,321,631, + // so its first free page lies past the 2 GiB limit no file can grow beyond. ACE refuses every statement that needs + // a page on this file and adds none (measured), and so does the allocator — at once, without growing the file + // towards the page first. + [Fact] + public void Allocation_refuses_a_free_page_past_the_largest_file() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "globalptr-past-limit-"); + try + { + byte[] longValue = TestDatabases.ReadPage(path, 94); + Assert.Equal("LVAL", System.Text.Encoding.ASCII.GetString(longValue, Format.DataOwnerOffset, 4)); + TestDatabases.WriteMapPointer(path, Format.FreePagesMapPointerOffset, 0, 94); + + using (var channel = PageChannel.Open(path, readOnly: false)) + { + Assert.Throws(() => channel.Allocator.Allocate()); + Assert.Equal(NorthwindPages, channel.PageCount); + } + Assert.Equal(longValue, TestDatabases.ReadPage(path, 94)); + } + finally { TemporaryDatabase.Delete(path); } + } + /// Each case breaks one pointer and leaves the other as Northwind stores it. public static TheoryData InvalidPointers { diff --git a/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs b/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs index 00437db7..b996c096 100644 --- a/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs +++ b/test/LibRed.Core.Tests/IndexTraversalCorruptionTests.cs @@ -139,6 +139,56 @@ public void Full_index_cursor_rejects_a_cycle_without_recursive_descent() finally { TemporaryDatabase.Delete(path); } } + // B's variable index patched to A's, so the two columns share one slot: B reads A's value, while B's index still + // holds the row under the value B was written with. A write of that row looks for the entry under the value it + // reads and finds none. ACE refuses the same write on the same damage — Customers.City moved onto CompanyName's + // slot — with "The search key was not found in any record." and leaves the table as it was (measured), so this is + // damage, not a refused value, and the statement rolls back. + [Theory] + [InlineData("update")] + [InlineData("delete")] + public void A_write_whose_index_entry_the_row_no_longer_matches_is_rejected_as_corruption(string statement) + { + string path = TemporaryDatabase.CreatePath("index-orphaned-"); + try + { + JetDatabase.Create(path); + int page; + byte[] a, b; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false), + new ColumnSpec("B", JetDataType.Text, 40, IsFixedLength: false)]); + db.CreateIndex("T", "ix", [("B", false)]); + db.OpenTable("T").Insert([1, "aa", "bb"]); + TableDefinition t = db.Catalog.FindTable("T")!; + (page, a, b) = (t.DefinitionPage, t.FindColumn("A")!.RawDescriptor!, t.FindColumn("B")!.RawDescriptor!); + } + byte[] file = File.ReadAllBytes(path); + JetFormatBase format = JetFormatBase.FromVersionByte(file[0x14]); + int at = file.AsSpan(page * format.PageSize, format.PageSize).IndexOf(b); + Assert.True(at >= 0); + a.AsSpan(format.ColumnVariableIndexOffset, 2).CopyTo(file.AsSpan(page * format.PageSize + at + format.ColumnVariableIndexOffset)); + File.WriteAllBytes(path, file); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Table table = damaged.OpenTable("T"); + (RowId id, object?[] row) = table.Rows().WithIds().Single(); + Assert.Equal([1, "aa", "aa"], row); + if (statement == "delete") + Assert.Throws(() => table.Delete(id)); + else + { + var changed = (object?[])row.Clone(); + changed[2] = "cc"; + Assert.Throws(() => table.Update(id, changed)); + } + Assert.Equal([1, "aa", "aa"], table.Rows().Single()); + } + finally { TemporaryDatabase.Delete(path); } + } + private static (int Root, int Owner) IndexIdentity(string path) { using var db = JetDatabase.Open(path); diff --git a/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj b/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj index 114954d7..d00c4c18 100644 --- a/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj +++ b/test/LibRed.Core.Tests/LibRed.Core.Tests.csproj @@ -35,7 +35,8 @@ wholesale (..\Shared\**\*.cs) and do not all reference LibRed.Core. --> - + + diff --git a/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs b/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs index 0bebc525..d8f74f94 100644 --- a/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs +++ b/test/LibRed.Core.Tests/PageAndRowCorruptionTests.cs @@ -64,6 +64,33 @@ public void Direct_row_seek_applies_the_same_slot_validation() DataPage.TryReadRow(new PageBuffer(page, 7), Format, 1, out _, out _)); } + // CREATE INDEX appends the new index's usage map to the page holding the table's own maps when it has room. That + // page's row count pushed past what a page holds is refused there as on every read of it, not walked off the + // page's end. + [Fact] + public void Creating_an_index_applies_the_same_header_validation_to_the_usage_map_page() + { + string path = TemporaryDatabase.CreatePath("index-mappage-"); + try + { + JetDatabase.Create(path); + int mapPage; + using (var db = JetDatabase.Open(path, readOnly: false)) + { + db.CreateTable("T", [new("Id", JetDataType.Int32, 4, IsFixedLength: true), new ColumnSpec("A", JetDataType.Text, 40, IsFixedLength: false)]); + mapPage = db.Channel.ReadPage(db.Catalog.FindTable("T")!.DefinitionPage).ReadRecordPointer(Format.TdefOwnedPagesOffset).Page; + } + byte[] page = TestDatabases.ReadPage(path, mapPage); + BinaryPrimitives.WriteUInt16LittleEndian(page.AsSpan(Format.DataRowCountOffset, 2), + (ushort)(BinaryPrimitives.ReadUInt16LittleEndian(page.AsSpan(Format.DataRowCountOffset, 2)) | 0x4500)); + TestDatabases.WritePage(path, mapPage, page); + + using var damaged = JetDatabase.Open(path, readOnly: false); + Assert.Throws(() => damaged.CreateIndex("T", "ix", [("A", false)])); + } + finally { TemporaryDatabase.Delete(path); } + } + [Fact] public void Zero_length_deleted_overflow_tombstone_remains_a_valid_slot_shape() { diff --git a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs index cb704d21..88218b9f 100644 --- a/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs +++ b/test/LibRed.Core.Tests/ReleaseAtCloseTests.cs @@ -120,6 +120,81 @@ public void The_close_lengthens_the_released_map_to_cover_the_highest_page_relea finally { TemporaryDatabase.Delete(path); } } + // A released map whose start page is -2,147,483,648 (its high byte damaged), every bit clear: ACE's close leaves + // it as it was and merges the pages a session released into the free map exactly as on the undamaged file + // (measured, releasing a picture's three long-value pages). + [Fact] + public void The_close_leaves_a_released_map_starting_below_page_zero_as_it_is_and_frees_the_pages() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "release-negative-"); + try + { + int holderPage; + byte[] holder, record; + using (var channel = PageChannel.Open(path, readOnly: true)) + { + DataPage.RowSlot slot; + (_, holderPage, holder, slot) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + System.Buffers.Binary.BinaryPrimitives.WriteInt32LittleEndian( + InlineMap(holder, slot)[Format.UsageMapStartPageOffset..], int.MinValue); + record = InlineMap(holder, slot).ToArray(); + } + TestDatabases.WritePage(path, holderPage, holder); + + using (var db = JetDatabase.Open(path, readOnly: false)) + { + var allocator = db.OpenTable("MSysObjects").Channel.Allocator; + allocator.Release(300); + allocator.Release(301); + } + + using (var channel = PageChannel.Open(path, readOnly: true)) + { + Assert.True(FreeMapBit(channel, 300)); + Assert.True(FreeMapBit(channel, 301)); + (_, _, byte[] after, DataPage.RowSlot slot) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + Assert.Equal(record, InlineMap(after, slot).ToArray()); + } + } + finally { TemporaryDatabase.Delete(path); } + } + + // A close whose release cannot run — here a released map turned reference form, which needs a bitmap page, and + // a free map with no free page and a nonzero start page, which LibRed does not grow — does not throw out of + // Dispose. The release runs in its own transaction, so it writes nothing, and the released page stays released. + [Fact] + public void A_close_whose_release_cannot_run_writes_nothing_and_does_not_throw() + { + string path = TemporaryDatabase.CopyPath(TestDatabases.NorthwindAccdb, "release-cannot-"); + try + { + int holderPage; + byte[] holder; + using (var channel = PageChannel.Open(path, readOnly: true)) + { + DataPage.RowSlot free, released; + (_, holderPage, holder, free) = TestDatabases.GlobalMap(channel, Format.FreePagesMapPointerOffset); + (_, _, _, released) = TestDatabases.GlobalMap(channel, Format.ReleasedPagesMapPointerOffset); + Span freeMap = InlineMap(holder, free); + System.Buffers.Binary.BinaryPrimitives.WriteInt32LittleEndian(freeMap[Format.UsageMapStartPageOffset..], 8); + UsageMap.InlineBits(freeMap, Format).Clear(); + Assert.Equal(Format.UsageMapReferenceRecordSize, released.Length); + Assert.All(UsageMap.InlineBits(InlineMap(holder, released), Format).ToArray(), b => Assert.Equal(0, b)); + holder[released.Offset] = (byte)UsageMapType.Reference; + } + TestDatabases.WritePage(path, holderPage, holder); + + var db = JetDatabase.Open(path, readOnly: false); + PageAllocator allocator = db.OpenTable("MSysObjects").Channel.Allocator; + Assert.Throws(() => allocator.Allocate()); // the free map LibRed cannot grow + allocator.Release(300); + db.Dispose(); + + Assert.Equal(holder, TestDatabases.ReadPage(path, holderPage)); + } + finally { TemporaryDatabase.Delete(path); } + } + [Fact] public void Pages_already_in_the_released_map_are_merged_by_a_close_that_wrote_but_not_by_an_idle_one() { diff --git a/test/LibRed.Engine.AccessTests/RenameIndexDaoProbeTest.cs b/test/LibRed.Engine.AccessTests/RenameIndexDaoProbeTest.cs new file mode 100644 index 00000000..fd1c38a2 --- /dev/null +++ b/test/LibRed.Engine.AccessTests/RenameIndexDaoProbeTest.cs @@ -0,0 +1,175 @@ +using System.Data.OleDb; +using LibRed.Catalog; +using Xunit; + +namespace LibRed.Engine.Tests; + +/// +/// Probe: whether DAO can rename an existing index by setting Index.Name — a plain index, a primary key, and +/// the index a relationship created — and what that changes on disk. Reports; asserts nothing. ACE's SQL has no +/// statement for it, so DAO is the only engine route there could be. +/// +/// +/// Each case renames on its own copy of one database, then reopens the copy through a fresh DAO engine and through +/// LibRed to list the table's indexes, and lists the pages that differ from the untouched copy. Both files are kept +/// under %TEMP%\libred-rename-index-probe for a byte diff. +/// +[Collection(AceCollection.Name)] +public class RenameIndexDaoProbeTest(ITestOutputHelper output) +{ + private static readonly string KeepDirectory = Path.Combine(Path.GetTempPath(), "libred-rename-index-probe"); + + [Theory(Explicit = true)] + [InlineData("Child", "IX_Note", "IX_Note_Renamed")] + [InlineData("Child", "IX_Note", "AA_Note")] // moves ahead of FK_Child_Parent in name order + [InlineData("Child", "IX_Note", "ix_note")] // case only + [InlineData("Child", "IX_Note", "PK_Child")] // onto another index's name + [InlineData("Parent", "PK_Parent", "PK_Parent_Renamed")] + [InlineData("Parent", "PK_Parent", "A")] // the parent also holds the relationship's hidden block + [InlineData("Child", "FK_Child_Parent", "FK_Child_Parent_Renamed")] + [InlineData("Wide", "IX_Wide", "IX_Wide_Renamed_To_A_Much_Longer_Name")] // a multi-page definition + public void Dao_renames_an_index(string table, string index, string newName) + { + Assert.SkipWhen(AceTestDatabase.CreateDaoEngine() is null, "DAO is not registered in this process."); + Directory.CreateDirectory(KeepDirectory); + + string source = CreateProbeDatabase(); + string before = Path.Combine(KeepDirectory, $"{index}-{newName}-before.accdb"); + string after = Path.Combine(KeepDirectory, $"{index}-{newName}-after.accdb"); + try + { + File.Copy(source, before, overwrite: true); + File.Copy(source, after, overwrite: true); + + output.WriteLine($"Before: {string.Join(", ", DaoIndexNames(before, table))}"); + + string outcome = Outcome(() => + { + dynamic engine = AceTestDatabase.CreateDaoEngine()!; + dynamic database = engine.OpenDatabase(after); + try + { + database.TableDefs[table].Indexes[index].Name = newName; + } + finally { database.Close(); } + }); + output.WriteLine($"DAO rename {table}.{index} -> {newName}: {outcome}"); + + output.WriteLine($"After (DAO): {string.Join(", ", DaoIndexNames(after, table))}"); + string libred = ""; + string libredOutcome = Outcome(() => libred = LibRedIndexNames(after, table)); + output.WriteLine($"After (LibRed): {(libredOutcome == "accepted" ? libred : libredOutcome)}"); + output.WriteLine($"Relationships (DAO): {string.Join(", ", DaoRelations(after))}"); + output.WriteLine($"Pages differing from before: {string.Join(", ", DifferingPages(before, after))}"); + output.WriteLine($"Kept: {before} | {after}"); + } + finally + { + AceTestDatabase.ReleaseAbandonedComObjects(); + TemporaryDatabase.Delete(source); + } + } + + private static string CreateProbeDatabase() + { + string path = TemporaryDatabase.CreatePath("rename-index-"); + JetDatabase.Create(path); + using (OleDbConnection connection = AceTestDatabase.Open(path)) + foreach (string sql in (string[]) + [ + "CREATE TABLE Parent (Id LONG, CONSTRAINT PK_Parent PRIMARY KEY (Id))", + "CREATE TABLE Child (Id LONG, ParentId LONG, Label TEXT(10), CONSTRAINT PK_Child PRIMARY KEY (Id), " + + "CONSTRAINT FK_Child_Parent FOREIGN KEY (ParentId) REFERENCES Parent (Id))", + "CREATE INDEX IX_Note ON Child (Label)", + "INSERT INTO Parent VALUES (1)", + "INSERT INTO Child VALUES (1, 1, 'a')", + $"CREATE TABLE Wide (Id LONG{string.Concat(Enumerable.Range(1, 254).Select(i => $", c{i:D3} CURRENCY"))})", + "CREATE INDEX IX_Wide ON Wide (c001)", + ]) + { + using OleDbCommand command = connection.CreateCommand(); + command.CommandText = sql; + try { command.ExecuteNonQuery(); } + catch (OleDbException e) { throw new InvalidOperationException($"ACE refused setup: {sql}", e); } + } + OleDbConnection.ReleaseObjectPool(); + return path; + } + + private static List DaoIndexNames(string path, string table) + { + var names = new List(); + dynamic engine = AceTestDatabase.CreateDaoEngine()!; + dynamic database = engine.OpenDatabase(path, false, true); + try + { + dynamic indexes = database.TableDefs[table].Indexes; + for (int i = 0; i < indexes.Count; i++) + { + dynamic ix = indexes[i]; + names.Add($"{ix.Name}{(ix.Primary ? " [PK]" : "")}{(ix.Foreign ? " [FK]" : "")}{(ix.Unique ? " [U]" : "")}"); + } + } + finally { database.Close(); } + return names; + } + + private static List DaoRelations(string path) + { + var names = new List(); + dynamic engine = AceTestDatabase.CreateDaoEngine()!; + dynamic database = engine.OpenDatabase(path, false, true); + try + { + dynamic relations = database.Relations; + for (int i = 0; i < relations.Count; i++) + { + dynamic relation = relations[i]; + names.Add($"{relation.Name} ({relation.ForeignTable} -> {relation.Table})"); + } + } + finally { database.Close(); } + return names; + } + + private static string LibRedIndexNames(string path, string table) + { + using var db = JetDatabase.Open(path, readOnly: true); + TableDefinition definition = db.Catalog.FindTable(table) + ?? throw new InvalidOperationException($"LibRed cannot find {table}."); + TableDefinition msysObjects = db.Catalog.FindTable("MSysObjects") + ?? throw new InvalidOperationException("LibRed cannot find MSysObjects."); + return $"{string.Join(", ", definition.Indexes.Select(i => i.Name))} " + + $"(TDEF page {definition.DefinitionPage}; MSysObjects TDEF page {msysObjects.DefinitionPage})"; + } + + private static List DifferingPages(string before, string after) + { + byte[] a = File.ReadAllBytes(before); + byte[] b = File.ReadAllBytes(after); + const int pageSize = 4096; + var pages = new List(); + int count = Math.Max(a.Length, b.Length) / pageSize; + for (int page = 0; page < count; page++) + { + ReadOnlySpan pa = page * pageSize < a.Length ? a.AsSpan(page * pageSize, pageSize) : default; + ReadOnlySpan pb = page * pageSize < b.Length ? b.AsSpan(page * pageSize, pageSize) : default; + if (!pa.SequenceEqual(pb)) pages.Add(page); + } + return pages; + } + + private static string Outcome(Action run) + { + try + { + run(); + return "accepted"; + } + catch (Exception e) when (e is System.Runtime.InteropServices.COMException or InvalidOperationException + or Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) + { + return $"{e.GetType().Name}: {e.Message}"; + } + } +} diff --git a/test/LibRed.Engine.AccessTests/StatementAtomicityTests.cs b/test/LibRed.Engine.AccessTests/StatementAtomicityTests.cs index 6688eca9..233dcf63 100644 --- a/test/LibRed.Engine.AccessTests/StatementAtomicityTests.cs +++ b/test/LibRed.Engine.AccessTests/StatementAtomicityTests.cs @@ -144,6 +144,55 @@ public void Failed_multirow_update_rolls_back_lval_allocation_byte_for_byte_and_ finally { TemporaryDatabase.Delete(path); } } + // A row grown past the page, not just past the 4060-byte cap: both writers build the row in a page-sized buffer, + // and checked only after it was built, the row threw an ArgumentException out of the copy into that buffer. ACE + // refuses either statement with "Record is too large", and so must LibRed, leaving the rows as they were. + [Theory] + [InlineData("UPDATE W SET T8 = T0, T9 = T1")] // grows by two 500-byte chunks + [InlineData("ALTER TABLE W ALTER COLUMN T7 TEXT(255)")] // the re-lay keeps T7's old chunk and appends the new one + public void A_row_grown_past_the_page_is_refused_as_ace_refuses_it(string statement) + { + string origin = TemporaryDatabase.CopyPath(Path.Combine(AppContext.BaseDirectory, "Data", "Northwind.accdb"), "atomic-page-"); + string ace = "", libred = ""; + try + { + string full = new('a', 250); + using (var db = JetDatabase.Open(origin, readOnly: false)) + { + var e = new QueryEngine(db); + e.ExecuteNonQuery("CREATE TABLE W (Id LONG PRIMARY KEY, " + + string.Join(", ", Enumerable.Range(0, 7).Select(i => $"T{i} TEXT(255)")) + + ", T7 TEXT(250), T8 TEXT(255), T9 TEXT(255))"); + // 8 × 500 bytes and 32 of overhead: 4032, inside the cap. + e.ExecuteNonQuery("INSERT INTO W (Id, " + string.Join(", ", Enumerable.Range(0, 8).Select(i => $"T{i}")) + + ") VALUES (1, " + string.Join(", ", Enumerable.Range(0, 8).Select(_ => $"'{full}'")) + ")"); + } + ace = TemporaryDatabase.CopyPath(origin, "atomic-page-ace-"); + libred = TemporaryDatabase.CopyPath(origin, "atomic-page-lib-"); + + string? aceRefusal = WholeFileParityProbeTest.RunThroughAce(ace, [statement]).Single(); + Assert.NotNull(aceRefusal); + Assert.Contains("Record is too large", aceRefusal); + + using (var db = JetDatabase.Open(libred, readOnly: false)) + { + var error = Assert.Throws(() => new QueryEngine(db).ExecuteNonQuery(statement)); + Assert.Contains("Record is too large", error.Message); + } + + using var connection = AceTestDatabase.Open(libred); + AssertScalar(connection, "SELECT COUNT(*) FROM W WHERE T8 IS NULL AND T9 IS NULL", 1); + Assert.Equal(full, ExecuteScalar(connection, "SELECT T7 FROM W WHERE Id = 1")); + Assert.Equal(250, Convert.ToInt32(connection.GetSchema("Columns", [null, null, "W", "T7"]).Rows[0]["CHARACTER_MAXIMUM_LENGTH"])); + } + finally + { + TemporaryDatabase.Delete(origin); + TemporaryDatabase.Delete(ace); + TemporaryDatabase.Delete(libred); + } + } + private static object? ExecuteScalar(OleDbConnection connection, string sql) { using var command = connection.CreateCommand(); diff --git a/test/LibRed.Engine.Tests/AlterTableRenameTests.cs b/test/LibRed.Engine.Tests/AlterTableRenameTests.cs index f49568ea..e1ee0bd6 100644 --- a/test/LibRed.Engine.Tests/AlterTableRenameTests.cs +++ b/test/LibRed.Engine.Tests/AlterTableRenameTests.cs @@ -311,4 +311,45 @@ public void Rename_rejects_a_name_that_is_already_taken_and_a_table_that_does_no TemporaryDatabase.Delete(path); } } + + // ACE renames an index through DAO's Index.Name (byte parity in RenameIndexParityAccessTests): a plain index and + // a key a relationship references both rename, the relationship's own index and a name another index has do not. + [Fact] + public void Rename_index_renames_a_plain_index_and_a_referenced_key_and_refuses_what_ace_refuses() + { + string path = Fresh(); + try + { + using (var db = JetDatabase.Open(path, readOnly: false)) + { + var e = new QueryEngine(db); + CreateParentChild(e); + + e.ExecuteNonQuery("ALTER TABLE Parent RENAME INDEX IX_Parent_Name TO IX_Parent_Name_Renamed"); + e.ExecuteNonQuery("ALTER TABLE Parent RENAME INDEX PK_Parent TO PK_Parent_Renamed"); + + Assert.Throws( + () => e.ExecuteNonQuery("ALTER TABLE Child RENAME INDEX FK_Child_Parent TO FK_Renamed")); + Assert.Throws( + () => e.ExecuteNonQuery("ALTER TABLE Child RENAME INDEX PK_Child TO FK_Child_Parent")); + Assert.Throws( + () => e.ExecuteNonQuery("ALTER TABLE Child RENAME INDEX NoSuchIndex TO Whatever")); + + // The relationship over the renamed key still holds. + Assert.ThrowsAny(() => e.ExecuteNonQuery("INSERT INTO Child (Id, ParentId) VALUES (2, 99)")); + } + + using (var db = JetDatabase.Open(path, readOnly: false)) + { + Assert.Equal(["IX_Parent_Name_Renamed", "PK_Parent_Renamed"], + db.Catalog.FindTable("Parent")!.Indexes.Select(i => i.Name).Order()); + Assert.Contains(db.Catalog.FindTable("Child")!.LogicalIndexes, l => l.Name == "FK_Child_Parent"); + Assert.Contains(db.Catalog.FindTable("Child")!.LogicalIndexes, l => l.Name == "PK_Child"); + } + } + finally + { + TemporaryDatabase.Delete(path); + } + } } diff --git a/test/LibRed.Shared/MalformedFile.cs b/test/LibRed.Shared/MalformedFile.cs new file mode 100644 index 00000000..e0aabe73 --- /dev/null +++ b/test/LibRed.Shared/MalformedFile.cs @@ -0,0 +1,336 @@ +using LibRed.Catalog; +using LibRed.Storage; + +namespace LibRed.Tests.Shared; + +/// +/// What a damaged database file is allowed to do to a reader, the good databases to damage, and the walk that +/// drives every read path over the result. Shared by the fixed-seed sweep in LibRed.Core.Tests and the +/// coverage-guided harness in LibRed.Core.Fuzz, so the two cannot disagree about what counts as a leak. +/// +/// +/// The contract is not "must not throw" — a damaged file SHOULD throw. It is that a damaged file must throw +/// InvalidDataException, LibRed's one signal for "these bytes are not a valid database". A caller that wants +/// to tell a corrupt file from a bug in the reader has nothing else to catch, and .NET gives it no help: the +/// exceptions a parser leaks by accident (ArgumentOutOfRangeException, IndexOutOfRangeException, +/// EndOfStreamException) share no base class with InvalidDataException, which derives from SystemException +/// rather than IOException. An unhandled one does not degrade, it crashes the caller. +/// +internal static class MalformedFile +{ + /// The exception types a malformed file is allowed to produce. + public static bool IsExpected(Exception e) => + e is InvalidDataException // the contract: these bytes are not a database + or NotSupportedException // a real feature LibRed does not implement yet + or UnauthorizedAccessException; // encrypted, wrong or missing password + + /// + /// The good databases to corrupt: one ACE-authored fixture, then shapes LibRed synthesises itself to + /// reach structures the fixture does not contain. Each is written into . + /// + /// + /// The source databases are AUTHORED HERE, not read from a corpus. Two reasons that matters: + /// + /// Coverage is otherwise bounded by whatever one fixture happens to contain. Northwind has no multi-page + /// TDEF, no chained long value, no dropped-then-added column and no deep index, so those decode paths + /// would never see a corrupt byte at all. LibRed can synthesise a file page-by-page, so the awkward + /// shapes are ours to make. + /// A file LibRed wrote tests our reader against our own writer. A leak then points at one of the two, + /// rather than at "ACE wrote something we mishandle". + /// + /// Northwind stays in the set as the one ACE-authored shape, since agreeing with a real Access file is the + /// whole point of the format work. + /// + public static IEnumerable<(string Shape, string Path)> Sources(string directory, string northwind) + { + string copy = Path.Combine(directory, "source-northwind.accdb"); + File.Copy(northwind, copy); + yield return ("northwind", copy); + + yield return ("wide-tdef", Author(directory, "wide-tdef", database => + { + // 200 columns spills the definition onto continuation pages, so the TDEF chain gets fuzzed. + database.CreateTable("Wide", + [.. Enumerable.Range(0, 200).Select(i => new ColumnSpec($"c{i}", JetDataType.Int32, 4, IsFixedLength: true))]); + var table = database.OpenTable("Wide"); + var row = new object?[200]; + for (int i = 0; i < 200; i++) row[i] = i; + table.Insert(row); + })); + + yield return ("long-values", Author(directory, "long-values", database => + { + database.CreateTable("Docs", + [new ColumnSpec("Id", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("Body", JetDataType.Memo, 0, IsFixedLength: false)]); + var table = database.OpenTable("Docs"); + // Inline, single-page and chained, so all three long-value storage forms are present. + foreach ((int id, int length) in new[] { (1, 20), (2, 2000), (3, 40_000) }) + table.Insert([id, new string((char)('a' + id), length)]); + })); + + yield return ("split-index", Author(directory, "split-index", database => + { + database.CreateTable("Keyed", + [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("V", JetDataType.Text, 60, IsFixedLength: false)], + primaryKey: ["K"]); + var table = database.OpenTable("Keyed"); + // Enough rows to drive the B-tree past a single leaf, so node pages exist to corrupt. + for (int i = 0; i < 1500; i++) table.Insert([i, $"value {i}"]); + })); + + yield return ("altered-columns", Author(directory, "altered-columns", database => + { + database.CreateTable("Churn", + [new ColumnSpec("K", JetDataType.Int32, 4, IsFixedLength: true), + new ColumnSpec("A", JetDataType.Text, 30, IsFixedLength: false), + new ColumnSpec("B", JetDataType.Text, 30, IsFixedLength: false), + new ColumnSpec("N", JetDataType.Int32, 4, IsFixedLength: true)]); + var table = database.OpenTable("Churn"); + table.Insert([1, "a1", "b1", 11]); + + // The gapped index space and burned ids of a table that has been edited — the shapes that + // produced the row-layout bugs, which a freshly created table cannot reach. + database.DropColumn("Churn", "B"); + database.AddColumn("Churn", new ColumnSpec("D", JetDataType.Text, 30, IsFixedLength: false)); + database.OpenTable("Churn").Insert([2, "a2", 22, "d2"]); + database.AlterColumnTypeInPlace("Churn", "N", + new ColumnSpec("N", JetDataType.Text, 20, IsFixedLength: false)); + })); + } + + /// Synthesises a database from scratch and applies to it. + private static string Author(string directory, string name, Action build) + { + string path = Path.Combine(directory, $"source-{name}.accdb"); + JetDatabase.Create(path); + using (var database = JetDatabase.Open(path, readOnly: false)) + build(database); + return path; + } + + /// + /// Walks everything a caller would, one stage at a time and continuing past failures: open, list + /// the catalog, then each table's rows separately. With , in each user table still + /// listed, the first of its first 32 rows the write accepts is also rewritten in place, deleted and inserted + /// again, then each of the selects runs, before its + /// indexes are walked. + /// + /// + /// Per-stage on purpose. Stopping at the first exception means one damaged TDEF hides every path behind + /// it, and the interesting leak is rarely the first thing that breaks. + /// + public static IEnumerable<(string Stage, Exception? Leak)> Exercise(string path, string? password = null, bool write = false, + int operations = 0) + { + JetDatabase? database = null; + try + { + (string open, Exception? leak) = Try("open", () => database = JetDatabase.Open(path, readOnly: !write, password: password)); + yield return (open, leak); + if (database is null) yield break; + + List tables = []; + yield return Try("catalog", () => tables = [.. database.Catalog.Tables]); + + foreach (TableDefinition table in tables) + { + // A write allocates through page 0's free-pages map wherever it points, and so does ACE: aimed at a + // table's own map, ACE takes that table's live pages without looking at them (measured, + // docs/format/page-05-usage-maps.md §9.1). So on a damaged file a write can overwrite the catalog's + // pages, and a table listed above is gone when the walk reaches it — or reaches its indexes, after + // its own write. Asking for it by name then gets the answer for a table that is not there; that is + // a refusal of the name, not a leak, so the walk only follows what is still listed. + bool listed = true; + if (write) + { + yield return Try($"find '{table.Name}'", () => listed = database.Catalog.FindTable(table.Name) is not null); + if (!listed) continue; + } + + int rows = 0; + (string read, Exception? rowLeak) = Try($"table '{table.Name}'", () => + { + foreach (object?[] _ in database.OpenTable(table.Name).Rows()) rows++; + }); + yield return ($"{read} ({rows} rows)", rowLeak); + + // A write reads what it changes — the slot it rewrites, the free-space map it allocates from, + // the index entry it removes — and takes every value it finds there as its next offset. Writing + // the row back with its own values keeps the workload valid on an undamaged file. On a damaged one + // the row's values can break its own damaged schema — a Null key, a value past its column, a record + // past the page — and a write refuses them with InvalidOperationException, as ACE refuses them too. + // So here that is a refusal, not a leak, and the next row is tried; what a write may not do is leak + // anything else. The rewrite declares no column changed and leaves Table.Update to find that none + // did: declaring them all would also "update" a write-once column, which ACE refuses whatever the + // value, and so refuse every row. Only the first rows are tried: when they are all refused, the damage + // is the table's — a schema whose every record is too large — and trying each of thousands of rows + // spends the fuzzer's time limit on the same refusal. + if (write && !table.IsSystem) + yield return Try($"write '{table.Name}'", () => + { + Table opened = database.OpenTable(table.Name); + foreach ((RowId id, object?[] values) in opened.Rows().WithIds().Take(32).ToList()) + { + try + { + opened.Update(id, values, new HashSet()); + opened.Delete(id); + opened.Insert(values); + break; + } + catch (InvalidOperationException) { } + } + }); + if (write) + { + yield return Try($"find '{table.Name}' again", () => listed = database.Catalog.FindTable(table.Name) is not null); + if (!listed) continue; + } + + // Then the operations selected — the code a row rewrite never reaches: long-value chains, schema edits, + // a rolled-back transaction. Each is one statement, as QueryEngine runs every writing statement: in a + // transaction of its own, rolled back when the operation is refused. + for (int bit = 0; write && !table.IsSystem && listed && bit < Operations.Length; bit++) + { + if ((operations & (1 << bit)) == 0) continue; + (string name, Action operation, bool rollBack) = Operations[bit]; + yield return Try($"{name} '{table.Name}'", () => Statement(database, () => operation(database, table.Name), rollBack)); + yield return Try($"find '{table.Name}' again", () => listed = database.Catalog.FindTable(table.Name) is not null); + } + if (!listed) continue; + + // A table SCAN reads the usage map and the data pages and never descends a B-tree, so + // without this every index page the sweep corrupts goes unread — the split-index shape was + // building node pages that nothing then looked at. Walking the entries decodes every page + // of the index, which is more of it than a handful of seeks would touch. + foreach (IndexDef index in table.Indexes) + { + int entries = 0; + (string walked, Exception? indexLeak) = + Try($"index '{table.Name}.{index.Name}'", () => + { + Table opened = database.OpenTable(table.Name); + foreach ((byte[] _, RowId _) in + new IndexCursor(opened.Channel, index.RootPage).RawEntries()) entries++; + }); + yield return ($"{walked} ({entries} entries)", indexLeak); + } + } + } + finally { database?.Dispose(); } + } + + /// + /// What a write workload can run on each user table after its row rewrite, in this order; bit n of + /// 's operations selects entry n. Each uses only the public API, and none + /// leaves the schema changed on an undamaged file, so the walk after it reads what it read before — except the + /// last, which drops the table. + /// + internal static readonly (string Name, Action Run, bool RollBack)[] Operations = + [ + // A chained long value written into every Memo and OLE column of the first row, then taken out again: the + // long-value allocation and the free of a chain. + ("long values", (database, name) => + { + Table table = database.OpenTable(name); + List longValues = [.. table.Definition.Columns.Where(c => c.Type is JetDataType.Memo or JetDataType.Ole)]; + if (longValues.Count == 0 || table.Rows().WithIds().Take(1).ToList() is not [(RowId id, object?[] row)]) return; + var changed = (object?[])row.Clone(); + foreach (ColumnDef column in longValues) + changed[column.Index] = column.Type == JetDataType.Memo ? new string('m', 9000) : new byte[9000]; + table.Update(id, changed, longValues.Select(c => c.Index).ToHashSet()); + foreach (ColumnDef column in longValues) changed[column.Index] = null; + table.Update(id, changed, longValues.Select(c => c.Index).ToHashSet()); + }, false), + // Two columns added, one fixed and one variable, and dropped again: the definition rewritten four times. + ("add and drop columns", (database, name) => + { + database.AddColumn(name, new ColumnSpec("FuzzLong", JetDataType.Int32, 4, IsFixedLength: true)); + database.AddColumn(name, new ColumnSpec("FuzzText", JetDataType.Text, 40, IsFixedLength: false)); + database.DropColumn(name, "FuzzLong"); + database.DropColumn(name, "FuzzText"); + }, false), + // An index built over the table's rows and dropped again: a B-tree built from damaged rows, then freed. + ("create and drop an index", (database, name) => + { + if (database.OpenTable(name).Definition.Columns.FirstOrDefault(c => c.Type is JetDataType.Int32 or JetDataType.Text) + is not { } column) return; + database.CreateIndex(name, "FuzzIndex", [(column.Name, false)]); + database.DropIndex(name, "FuzzIndex"); + }, false), + // The first rows deleted by a statement that then rolls back: every page it wrote restored from the overlay. + ("delete and roll back", (database, name) => + { + Table table = database.OpenTable(name); + foreach ((RowId id, _) in table.Rows().WithIds().Take(32).ToList()) + { + try { table.Delete(id); } + catch (InvalidOperationException) { } + } + }, true), + // The table and its first column renamed and named back: the catalog row and the definition rewritten. Only a + // name a caller could give is named back: damage can store one ACE refuses, which reads but cannot be given + // back, there or here. + ("rename and rename back", (database, name) => + { + if (Nameable(name) && database.RenameTable(name, "FuzzRenamed")) database.RenameTable("FuzzRenamed", name); + string column = database.OpenTable(name).Definition.Columns[0].Name; + if (Nameable(column) && database.RenameColumn(name, column, "FuzzColumn")) + database.RenameColumn(name, "FuzzColumn", column); + }, false), + // The table dropped: every page it owns freed, then released at close. + ("drop the table", (database, name) => database.DropTable(name), false), + ]; + + private static bool Nameable(string name) + { + try { JetName.Validate(name); return true; } + catch (ArgumentException) { return false; } + } + + /// Runs as one statement: in a transaction of its own, committed — or, with + /// , rolled back — or rolled back when the operation is refused with + /// , as ACE refuses a write a damaged schema breaks. Anything else rolls + /// back too and goes on to be judged by the contract. + private static void Statement(JetDatabase database, Action operation, bool rollBack) + { + database.BeginTransaction(); + try + { + operation(); + if (rollBack) database.Rollback(); + else database.Commit(flush: false); + } + catch (InvalidOperationException) { database.Rollback(failed: true); } + catch + { + database.Rollback(failed: true); + throw; + } + } + + private static (string Outcome, Exception? Leak) Try(string stage, Action action) + { + try + { + action(); + return ($"{stage}: ok", null); + } + catch (Exception e) when (IsExpected(e)) + { + return ($"{stage}: rejected — {e.GetType().Name}: {Summarise(e.Message)}", null); + } + catch (Exception e) + { + return ($"{stage}: !! LEAKED {e.GetType().Name}: {Summarise(e.Message)}", e); + } + } + + private static string Summarise(string message) + { + string one = message.ReplaceLineEndings(" ").Trim(); + return one.Length <= 100 ? one : one[..100] + "…"; + } +}