Skip to content

Commit

Permalink
Added a test project for F# functional tests. (#34541)
Browse files Browse the repository at this point in the history
- Added the project EFCore.FSharp.FunctionalTests
- Created a fixture for the Northwind database
- Implemented a sample test analogous to the Visual Basic tests

Fixes #14572
  • Loading branch information
koenigst authored Aug 27, 2024
1 parent 56716b0 commit 017fb22
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
7 changes: 7 additions & 0 deletions EFCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<AssemblyName>Microsoft.EntityFrameworkCore.FSharp.FunctionalTests</AssemblyName>
<SkipTests Condition="'$(OS)' != 'Windows_NT' AND '$(Test__SqlServer__DefaultConnection)' == ''">True</SkipTests>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="NorthwindFSharpQuerySqlServerFixture.fs" />
<Compile Include="NorthwindQueryFSharpTest.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 38 additions & 0 deletions test/EFCore.FSharp.FunctionalTests/NorthwindQueryFSharpTest.fs
Original file line number Diff line number Diff line change
@@ -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<NorthwindFSharpQuerySqlServerFixture<NoopModelCustomizer>>(fixture)

do fixture.TestSqlLoggerFactory.Clear()

let assertSql (sql: string) =
fixture.TestSqlLoggerFactory.AssertBaseline([|sql|])

[<ConditionalTheory>]
[<MemberData(nameof NorthwindQueryFSharpTest.IsAsyncData)>]
let ListLiteral_Contains (isAsync: bool) =
task {
do! self.AssertQuery(isAsync, (fun ss -> ss.Set<Customer>().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)))
10 changes: 8 additions & 2 deletions test/EFCore.Specification.Tests/Query/QueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ namespace Microsoft.EntityFrameworkCore.Query;
public abstract class QueryTestBase<TFixture> : IClassFixture<TFixture>
where TFixture : class, IQueryFixtureBase, new()
{
private readonly Lazy<QueryAsserter> _queryAsserterCache;

protected QueryTestBase(TFixture fixture)
{
Fixture = fixture;
QueryAsserter = CreateQueryAsserter(fixture);

_queryAsserterCache = new Lazy<QueryAsserter>(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(
Expand Down

0 comments on commit 017fb22

Please sign in to comment.