diff --git a/EFCore.sln b/EFCore.sln index 3f1cd5ae7c2..22394d18d26 100644 --- a/EFCore.sln +++ b/EFCore.sln @@ -141,6 +141,8 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "EFCore.VisualBasic.Function EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Tasks", "src\EFCore.Tasks\EFCore.Tasks.csproj", "{711EE8F3-F92D-4470-8B0B-25D8B13EF282}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "EFCore.FSharp.FunctionalTests", "test\EFCore.FSharp.FunctionalTests\EFCore.FSharp.FunctionalTests.fsproj", "{89180105-1D98-4844-9C24-3A5DA2C53329}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -371,6 +373,10 @@ Global {711EE8F3-F92D-4470-8B0B-25D8B13EF282}.Debug|Any CPU.Build.0 = Debug|Any CPU {711EE8F3-F92D-4470-8B0B-25D8B13EF282}.Release|Any CPU.ActiveCfg = Release|Any CPU {711EE8F3-F92D-4470-8B0B-25D8B13EF282}.Release|Any CPU.Build.0 = Release|Any CPU + {89180105-1D98-4844-9C24-3A5DA2C53329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89180105-1D98-4844-9C24-3A5DA2C53329}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89180105-1D98-4844-9C24-3A5DA2C53329}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89180105-1D98-4844-9C24-3A5DA2C53329}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -433,6 +439,7 @@ Global {3D935B7D-80BD-49AD-BDC9-E1B0C9D9494F} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3} = {258D5057-81B9-40EC-A872-D21E27452749} {711EE8F3-F92D-4470-8B0B-25D8B13EF282} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} + {89180105-1D98-4844-9C24-3A5DA2C53329} = {258D5057-81B9-40EC-A872-D21E27452749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705} diff --git a/test/EFCore.FSharp.FunctionalTests/EFCore.FSharp.FunctionalTests.fsproj b/test/EFCore.FSharp.FunctionalTests/EFCore.FSharp.FunctionalTests.fsproj new file mode 100644 index 00000000000..4d158d20380 --- /dev/null +++ b/test/EFCore.FSharp.FunctionalTests/EFCore.FSharp.FunctionalTests.fsproj @@ -0,0 +1,20 @@ + + + + Microsoft.EntityFrameworkCore + $(DefaultNetCoreTargetFramework) + Microsoft.EntityFrameworkCore.FSharp.FunctionalTests + True + latest + + + + + + + + + + + + diff --git a/test/EFCore.FSharp.FunctionalTests/NorthwindFSharpQuerySqlServerFixture.fs b/test/EFCore.FSharp.FunctionalTests/NorthwindFSharpQuerySqlServerFixture.fs new file mode 100644 index 00000000000..43cb9ccb5e3 --- /dev/null +++ b/test/EFCore.FSharp.FunctionalTests/NorthwindFSharpQuerySqlServerFixture.fs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.FSharp.FunctionalTests + +open Microsoft.EntityFrameworkCore.Infrastructure +open Microsoft.EntityFrameworkCore.Query + +type NorthwindFSharpQuerySqlServerFixture<'TModelCustomizer + when 'TModelCustomizer : (new: unit -> 'TModelCustomizer) + and 'TModelCustomizer :> ITestModelCustomizer>() = + inherit NorthwindQuerySqlServerFixture<'TModelCustomizer>() + + override self.StoreName = "NorthwindFSharp" diff --git a/test/EFCore.FSharp.FunctionalTests/NorthwindQueryFSharpTest.fs b/test/EFCore.FSharp.FunctionalTests/NorthwindQueryFSharpTest.fs new file mode 100644 index 00000000000..323ad23369b --- /dev/null +++ b/test/EFCore.FSharp.FunctionalTests/NorthwindQueryFSharpTest.fs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.FSharp.FunctionalTests + +open System.Linq +open Microsoft.EntityFrameworkCore.Query +open Microsoft.EntityFrameworkCore.TestModels.Northwind +open Microsoft.EntityFrameworkCore.TestUtilities +open global.Xunit + +type NorthwindQueryFSharpTest(fixture) as self = + inherit QueryTestBase>(fixture) + + do fixture.TestSqlLoggerFactory.Clear() + + let assertSql (sql: string) = + fixture.TestSqlLoggerFactory.AssertBaseline([|sql|]) + + [] + [] + let ListLiteral_Contains (isAsync: bool) = + task { + do! self.AssertQuery(isAsync, (fun ss -> ss.Set().Where(fun c -> ["ALFKI"; "ALFKI2"].Contains(c.CustomerID)))) + assertSql( + "SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] IN (N'ALFKI', N'ALFKI2')") + } + + member private self.RewriteExpectedQueryExpressionRedirect expression = base.RewriteExpectedQueryExpression expression + member private self.RewriteServerQueryExpressionRedirect expression = base.RewriteServerQueryExpression expression + + override self.CreateQueryAsserter fixture = + new RelationalQueryAsserter( + fixture, + (fun e -> self.RewriteExpectedQueryExpressionRedirect(e)), + (fun e -> self.RewriteServerQueryExpressionRedirect(e))) diff --git a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs index 0072b3bac73..3b7f268f4be 100644 --- a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs @@ -8,14 +8,20 @@ namespace Microsoft.EntityFrameworkCore.Query; public abstract class QueryTestBase : IClassFixture where TFixture : class, IQueryFixtureBase, new() { + private readonly Lazy _queryAsserterCache; + protected QueryTestBase(TFixture fixture) { Fixture = fixture; - QueryAsserter = CreateQueryAsserter(fixture); + + _queryAsserterCache = new Lazy(CreateQueryAsserter); } protected TFixture Fixture { get; } - protected QueryAsserter QueryAsserter { get; } + protected QueryAsserter QueryAsserter => _queryAsserterCache.Value; + + private QueryAsserter CreateQueryAsserter() + => CreateQueryAsserter(Fixture); protected virtual QueryAsserter CreateQueryAsserter(TFixture fixture) => new(