Added a test project for F# functional tests. (#34541)
- 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
This commit is contained in:
Родитель
56716b08d9
Коммит
017fb22e4b
|
@ -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}
|
||||
|
|
|
@ -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>
|
|
@ -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"
|
|
@ -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)))
|
|
@ -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(
|
||||
|
|
Загрузка…
Ссылка в новой задаче