Skip to content

Commit

Permalink
Port FunctionalTests.ProviderAgnostic to .NET Core 3
Browse files Browse the repository at this point in the history
Part of dotnet#271
  • Loading branch information
bricelam committed May 21, 2019
1 parent 74d1a22 commit 3c0307a
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 40 deletions.
20 changes: 18 additions & 2 deletions src/EntityFramework/Core/Objects/ELinq/MethodCallTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ protected TrimBaseTranslator(IEnumerable<MethodInfo> methods, string canonicalFu
// Supported only if the argument is an empty array.
internal override CqtExpression Translate(ExpressionConverter parent, MethodCallExpression call)
{
if (!IsEmptyArray(call.Arguments[0]))
if (call.Arguments.Count != 0 && !IsEmptyArray(call.Arguments[0]))
{
throw new NotSupportedException(Strings.ELinq_UnsupportedTrimStartTrimEndCase(call.Method));
}
Expand All @@ -1597,7 +1597,7 @@ internal override CqtExpression Translate(ExpressionConverter parent, MethodCall

internal static bool IsEmptyArray(LinqExpression expression)
{
var newArray = (NewArrayExpression)expression;
var newArray = expression as NewArrayExpression;
if (expression.NodeType
== ExpressionType.NewArrayInit)
{
Expand Down Expand Up @@ -1630,6 +1630,10 @@ internal TrimTranslator()

private static IEnumerable<MethodInfo> GetMethods()
{
#if NETSTANDARD2_1
yield return
typeof(String).GetDeclaredMethod("Trim", typeof(Char));
#endif
yield return
typeof(String).GetDeclaredMethod("Trim", typeof(Char[]));
}
Expand All @@ -1644,6 +1648,12 @@ internal TrimStartTranslator()

private static IEnumerable<MethodInfo> GetMethods()
{
#if NETSTANDARD2_1
yield return
typeof(String).GetDeclaredMethod("TrimStart");
yield return
typeof(String).GetDeclaredMethod("TrimStart", typeof(Char));
#endif
yield return
typeof(String).GetDeclaredMethod("TrimStart", typeof(Char[]));
}
Expand All @@ -1658,6 +1668,12 @@ internal TrimEndTranslator()

private static IEnumerable<MethodInfo> GetMethods()
{
#if NETSTANDARD2_1
yield return
typeof(String).GetDeclaredMethod("TrimEnd");
yield return
typeof(String).GetDeclaredMethod("TrimEnd", typeof(Char));
#endif
yield return
typeof(String).GetDeclaredMethod("TrimEnd", typeof(Char[]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ namespace System.Data.Entity.CodeFirst

public class InheritanceScenarioTests
{
[Fact] // CodePlex 583
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)] // CodePlex 583
public void Subclasses_with_different_properties_to_same_column_using_TPH_can_round_trip()
{
using (var context = new FunctionalTests.InheritanceScenarioTests.TphPersonContext())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#if !NET40
#if NET452
namespace System.Data.Entity.Configuration
{
using MySql.Data.MySqlClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#if !NET40
#if NET452
namespace System.Data.Entity.Configuration
{
using System.Data.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@

namespace System.Data.Entity.Configuration
{
#if !NET40
using MySql.Data.MySqlClient;
#endif
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServer;

#if NET452
using System.Runtime.Remoting.Messaging;
using MySql.Data.MySqlClient;
#else
using System.Threading;
#endif

public class ProviderAgnosticConfiguration : DbConfiguration
{
#if NET452
private static readonly string _providerInvariantName = ConfigurationManager.AppSettings["ProviderInvariantName"];
private static readonly string _baseConnectionString = ConfigurationManager.AppSettings["BaseConnectionString"];
#else
private static readonly string _providerInvariantName = "System.Data.SqlClient";
private static readonly string _baseConnectionString = @"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True;";
private static readonly AsyncLocal<bool> _suspendExecutionStrategy = new AsyncLocal<bool>();
#endif

public ProviderAgnosticConfiguration()
{
#if !NET40
#if NET452
SetHistoryContext(
"MySql.Data.MySqlClient",
(connection, defaultSchema) => new MySqlHistoryContext(connection, defaultSchema));
Expand All @@ -34,7 +43,7 @@ public ProviderAgnosticConfiguration()
SetDefaultConnectionFactory(new SqlConnectionFactory(_baseConnectionString));
break;

#if !NET40
#if NET452
case "MySql.Data.MySqlClient" :
SetDefaultConnectionFactory(new MySqlConnectionFactory());
break;
Expand All @@ -49,14 +58,13 @@ public ProviderAgnosticConfiguration()

public static bool SuspendExecutionStrategy
{
get
{
return (bool?)CallContext.LogicalGetData("SuspendExecutionStrategy") ?? false;
}
set
{
CallContext.LogicalSetData("SuspendExecutionStrategy", value);
}
#if NET452
get => (bool?)CallContext.LogicalGetData("SuspendExecutionStrategy") ?? false;
set => CallContext.LogicalSetData("SuspendExecutionStrategy", value);
#else
get => _suspendExecutionStrategy.Value;
set => _suspendExecutionStrategy.Value = value;
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<RootNamespace>System.Data.Entity</RootNamespace>
<AssemblyName>EntityFramework.FunctionalTests.ProviderAgnostic</AssemblyName>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net452;netcoreapp3.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);EF_FUNCTIONALS</DefineConstants>
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@
<PackageReference Include="MySql.Data.Entity" Version="$(MySqlDataEntityVersion)" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Transactions" />
Expand All @@ -38,4 +38,11 @@
<ProjectReference Include="..\FunctionalTests.Transitional\FunctionalTests.Transitional.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<None Update="App.config">
<Link>xunit.console.dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace System.Data.Entity.Query.LinqToEntities

public class EnumTests
{
[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Cast_property_to_enum()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -25,7 +29,11 @@ public void Cast_property_to_enum()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Cast_constant_to_enum()
{
using (var context = new ProviderAgnosticContext())
Expand Down Expand Up @@ -74,7 +82,11 @@ public void Enum_in_OrderBy_clause()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Enum_in_GroupBy_clause()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -97,7 +109,11 @@ public void Enum_in_GroupBy_clause()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Enum_in_Join_clause()
{
using (var context = new ProviderAgnosticContext())
Expand Down Expand Up @@ -126,7 +142,11 @@ public void Enum_in_Join_clause()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Enum_with_coalesce_operator()
{
using (var context = new ProviderAgnosticContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace System.Data.Entity.Query.LinqToEntities

public class IncludeTests
{
[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_on_one_to_many_relationship()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -29,7 +33,11 @@ public void Include_on_one_to_many_relationship()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_on_many_to_many_relationship()
{
using (var context = new ProviderAgnosticContext())
Expand Down Expand Up @@ -61,7 +69,11 @@ public void Include_one_to_one_relationship()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Multiple_includes()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -85,7 +97,11 @@ public void Multiple_includes()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_with_string_overload()
{
using (var context = new ProviderAgnosticContext())
Expand Down Expand Up @@ -128,7 +144,11 @@ public void Include_propagation_over_sort()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_propagation_over_type_filter()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -140,7 +160,11 @@ public void Include_propagation_over_type_filter()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_propagation_over_first()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -152,7 +176,11 @@ public void Include_propagation_over_first()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_propagation_over_first_with_predicate()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -164,7 +192,11 @@ public void Include_propagation_over_first_with_predicate()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_propagation_over_first_or_default()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -176,7 +208,11 @@ public void Include_propagation_over_first_or_default()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_propagation_over_first_or_default_with_predicate()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -188,7 +224,11 @@ public void Include_propagation_over_first_or_default_with_predicate()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_from_concat_combined()
{
using (var context = new ProviderAgnosticContext())
Expand All @@ -201,7 +241,11 @@ public void Include_from_concat_combined()
}
}

[Fact]
[Fact(
#if NETCOREAPP3_0
Skip = "dotnet/corefx#37849"
#endif
)]
public void Include_from_union_combined()
{
using (var context = new ProviderAgnosticContext())
Expand Down
Loading

0 comments on commit 3c0307a

Please sign in to comment.