Skip to content

Commit

Permalink
Port FunctionalTests.Transitional to .NET Core 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed May 18, 2019
1 parent 5539989 commit 6d8644b
Show file tree
Hide file tree
Showing 47 changed files with 76 additions and 2,242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace System.Data.Entity.Infrastructure.DependencyResolution
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity.Resources;
using System.Data.SqlClient;
using System.Linq;

internal class DefaultProviderFactoryResolver : IDbDependencyResolver
Expand All @@ -31,6 +32,11 @@ private static object GetService(Type type, object key, Func<ArgumentException,
}
catch (ArgumentException e)
{
if (string.Equals(name, "System.Data.SqlClient", StringComparison.OrdinalIgnoreCase))
{
return SqlClientFactory.Instance;
}

return handleFailedLookup(e, name);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/EntityFramework/Utilities/DbProviderFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace System.Data.Entity.Utilities
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.DependencyResolution;
using System.Data.Entity.Resources;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;

Expand All @@ -29,6 +30,11 @@ public static string GetProviderInvariantName(this DbProviderFactory factory)

if (row == null)
{
if (factory.GetType() == typeof(SqlClientFactory))
{
return "System.Data.SqlClient";
}

throw new NotSupportedException(Strings.ProviderNameNotFound(factory));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class UserRole
public virtual string RoleId2 { get; set; }
}

#if NET452
[Fact]
public void Sql_ce_should_get_explicit_max_lengths_for_string_and_binary_properties_by_convention()
{
Expand Down Expand Up @@ -171,6 +172,7 @@ public void Sql_ce_should_get_explicit_max_lengths_for_fixed_length_string_and_f
databaseMapping.Assert<MaxLengthProperties>(e => e.Prop2).DbEqual(false, f => f.IsMaxLength);
databaseMapping.Assert<MaxLengthProperties>(e => e.Prop2).DbEqual("binary", c => c.TypeName);
}
#endif

[Fact]
public void Sql_should_get_implicit_max_lengths_for_string_and_binary_properties_by_convention()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ namespace FunctionalTests
using System.Data.Entity.ModelConfiguration.Edm;
using System.Data.Entity.ModelConfiguration.Edm.Services;
using System.Linq;
using System.Windows.Media;
using FunctionalTests.Model;
using Xunit;

#if NET452
using System.Windows.Media;
#endif

public class BasicMappingScenarioTests : TestBase
{
[Fact]
Expand Down Expand Up @@ -333,6 +336,7 @@ public void Explicitly_configured_entity_set_names_are_uniqued()
Assert.Equal("Foo1", databaseMapping.Model.Containers.Single().EntitySets.Last().Name);
}

#if NET452
[Fact]
public void Build_model_for_type_with_framework_type()
{
Expand All @@ -350,6 +354,7 @@ public class Stimulus
public int Id { get; set; }
public Brush Background { get; set; }
}
#endif

[Fact]
public void Build_model_for_type_with_internal_member_to_configure_type()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#if NET452

namespace FunctionalTests
{
using System.Data.Entity;
Expand Down Expand Up @@ -52,3 +54,5 @@ public class Inner
public string Data { get; set; }
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#if NET452

namespace System.Data.Entity.Design
{
using System.CodeDom.Compiler;
Expand Down Expand Up @@ -172,3 +174,5 @@ void IResultHandler.SetResult(object value)
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<RootNamespace>System.Data.Entity</RootNamespace>
<AssemblyName>EntityFramework.FunctionalTests.Transitional</AssemblyName>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net452;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand All @@ -18,22 +18,28 @@

<ItemGroup>
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="Microsoft.SqlServer.Compact" Version="$(MicrosoftSqlServerCompactVersion)" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="$(MicrosoftSqlServerTypesVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServerCompact\EntityFramework.SqlServerCompact.csproj" />
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServer\EntityFramework.SqlServer.csproj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServerCompact\EntityFramework.SqlServerCompact.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<Compile Include="$(NuGetPackageRoot)Microsoft.SqlServer.Types\$(MicrosoftSqlServerTypesVersion)\content\SqlServerTypes\Loader.cs">
<Link>SqlServerTypes\Loader.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<Content Include="$(NuGetPackageRoot)Microsoft.SqlServer.Types\$(MicrosoftSqlServerTypesVersion)\content\readme.htm">
<Link>SqlServerTypes\readme.htm</Link>
</Content>
Expand Down Expand Up @@ -74,7 +80,7 @@
</ItemGroup>

<PropertyGroup>
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT'">
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' And '$(TargetFramework)' == 'net452'">
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
xcopy /s /y "$(NuGetPackageRoot)Microsoft.SqlServer.Compact\$(MicrosoftSqlServerCompactVersion)\NativeBinaries\x86\*.*" "$(TargetDir)x86"
if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace System.Data.Entity.Migrations
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity.Infrastructure;
using System.Data.SqlServerCe;
using System.Linq;

public class InfoContext : DbContext
Expand Down Expand Up @@ -192,7 +191,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
kcu.ColumnName
});

if (Database.Connection is SqlCeConnection)
if (this.IsSqlCe())
{
column.Property(c => c.NumericPrecision).HasColumnType("smallint");
column.Property(c => c.DateTimePrecision).HasColumnType("int");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace System.Data.Entity.Migrations
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using System.Data.SqlServerCe;

public class MigrationsCustomerBase
{
Expand Down Expand Up @@ -199,7 +198,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<Order>().Property(o => o.Type).IsUnicode(false);
modelBuilder.Entity<MigrationsProduct>();

if (!(Database.Connection is SqlCeConnection))
if (!this.IsSqlCe())
{
// NotSupported in CE
modelBuilder.Entity<MigrationsCustomer>().MapToStoredProcedures();
Expand Down Expand Up @@ -242,7 +241,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MigrationsCustomer>().ToTable("tbl_customers", "crm");

if (!(Database.Connection is SqlCeConnection))
if (!this.IsSqlCe())
{
// NotSupported in CE
modelBuilder.Entity<MigrationsCustomer>().Property(c => c.Name).HasColumnName("new_name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Can_replace_connection()
}
}

#if NET452
[Fact]
public void Can_replace_connection_with_different_provider()
{
Expand All @@ -54,6 +55,7 @@ public void Can_replace_connection_with_different_provider()
}
}
}
#endif

private void Can_replace_connection_implementation(
ReplaceConnectionContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace System.Data.Entity
{
using System.Data.Entity.Migrations;

#if NET452
using System.Data.SqlServerCe;
#endif

public static class DbContextExtensions
{
Expand All @@ -15,7 +18,7 @@ public static TypeAssertion<TStructuralType> Assert<TStructuralType>(this DbCont

public static void IgnoreSpatialTypesOnSqlCe(this DbContext context, DbModelBuilder modelBuilder)
{
if (context.Database.Connection is SqlCeConnection)
if (context.IsSqlCe())
{
modelBuilder.Entity<MigrationsStore>().Ignore(e => e.Location);
modelBuilder.Entity<MigrationsStore>().Ignore(e => e.FloorPlan);
Expand All @@ -24,7 +27,11 @@ public static void IgnoreSpatialTypesOnSqlCe(this DbContext context, DbModelBuil

public static bool IsSqlCe(this DbContext context)
{
#if NET452
return context.Database.Connection is SqlCeConnection;
#else
return false;
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Assembly Compile()
public Assembly Compile(AssemblyName assemblyName)
{
var assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);

foreach (var attribute in Attributes)
{
Expand Down Expand Up @@ -336,7 +336,7 @@ private Type DefineEnumType(ModuleBuilder module, DynamicEnumType enumTypeInfo)
Convert.ChangeType(enumMember.Value, enumTypeInfo.UnderlyingType));
}

return enumBuilder.CreateType();
return enumBuilder.CreateTypeInfo().AsType();
}

private static TypeAttributes GetTypeAccess(MemberAccess typeAccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace System.Data.Entity.TestHelpers
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.DependencyResolution;
using System.Data.Entity.SqlServer;
using System.Data.Entity.SqlServerCompact;
using System.Linq;
#if NET452
using System.Data.Entity.SqlServerCompact;
#endif

public class FunctionalTestsConfiguration : DbConfiguration
{
Expand Down Expand Up @@ -60,7 +62,9 @@ private static void OnLoaded(object sender, DbConfigurationLoadedEventArgs event

public FunctionalTestsConfiguration()
{
#if NET452
SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);
#endif
SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);

SetDefaultConnectionFactory(new DefaultUnitTestsConnectionFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class TestBase : MarshalByRefObject
{
static TestBase()
{
#if NET452
SqlServerTypes.Utilities.LoadNativeAssemblies(
Path.GetDirectoryName(typeof(FunctionalTestBase).Assembly.Location));
#endif

DbConfiguration.SetConfiguration(new FunctionalTestsConfiguration());

Expand Down Expand Up @@ -572,6 +574,7 @@ public static Configuration CreateEmptyConfig()

#endregion

#if NET452
public static void RunTestInAppDomain(Type testType)
{
var domain = AppDomain.CreateDomain("TestAppDomain", null, AppDomain.CurrentDomain.SetupInformation);
Expand All @@ -588,5 +591,6 @@ public static void RunTestInAppDomain(Type testType)
AppDomain.Unload(domain);
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServer\EntityFramework.SqlServer.csproj" />
<ProjectReference Include="..\FunctionalTests.Transitional\FunctionalTests.Transitional.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: TestCaseOrderer("System.Data.Entity.TestHelpers.SimpleTestCaseOrderer", "EntityFramework.FunctionalTests.netcoreapp3.0")]
[assembly: TestCollectionOrderer("System.Data.Entity.TestHelpers.SimpleTestCollectionOrderer", "EntityFramework.FunctionalTests.netcoreapp3.0")]
[assembly: TestCaseOrderer("System.Data.Entity.TestHelpers.SimpleTestCaseOrderer", "EntityFramework.FunctionalTests.Transitional")]
[assembly: TestCollectionOrderer("System.Data.Entity.TestHelpers.SimpleTestCollectionOrderer", "EntityFramework.FunctionalTests.Transitional")]

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6d8644b

Please sign in to comment.