Skip to content

Commit 6d8644b

Browse files
committed
Port FunctionalTests.Transitional to .NET Core 3
1 parent 5539989 commit 6d8644b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+76
-2242
lines changed

src/EntityFramework/Infrastructure/DependencyResolution/DefaultProviderFactoryResolver.cs

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace System.Data.Entity.Infrastructure.DependencyResolution
55
using System.Collections.Generic;
66
using System.Data.Common;
77
using System.Data.Entity.Resources;
8+
using System.Data.SqlClient;
89
using System.Linq;
910

1011
internal class DefaultProviderFactoryResolver : IDbDependencyResolver
@@ -31,6 +32,11 @@ private static object GetService(Type type, object key, Func<ArgumentException,
3132
}
3233
catch (ArgumentException e)
3334
{
35+
if (string.Equals(name, "System.Data.SqlClient", StringComparison.OrdinalIgnoreCase))
36+
{
37+
return SqlClientFactory.Instance;
38+
}
39+
3440
return handleFailedLookup(e, name);
3541
}
3642
}

src/EntityFramework/Utilities/DbProviderFactoryExtensions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace System.Data.Entity.Utilities
99
using System.Data.Entity.Infrastructure;
1010
using System.Data.Entity.Infrastructure.DependencyResolution;
1111
using System.Data.Entity.Resources;
12+
using System.Data.SqlClient;
1213
using System.Diagnostics;
1314
using System.Linq;
1415

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

3031
if (row == null)
3132
{
33+
if (factory.GetType() == typeof(SqlClientFactory))
34+
{
35+
return "System.Data.SqlClient";
36+
}
37+
3238
throw new NotSupportedException(Strings.ProviderNameNotFound(factory));
3339
}
3440

test/EntityFramework/FunctionalTests.Transitional/CodeFirst/AdvancedMappingScenarioTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public class UserRole
120120
public virtual string RoleId2 { get; set; }
121121
}
122122

123+
#if NET452
123124
[Fact]
124125
public void Sql_ce_should_get_explicit_max_lengths_for_string_and_binary_properties_by_convention()
125126
{
@@ -171,6 +172,7 @@ public void Sql_ce_should_get_explicit_max_lengths_for_fixed_length_string_and_f
171172
databaseMapping.Assert<MaxLengthProperties>(e => e.Prop2).DbEqual(false, f => f.IsMaxLength);
172173
databaseMapping.Assert<MaxLengthProperties>(e => e.Prop2).DbEqual("binary", c => c.TypeName);
173174
}
175+
#endif
174176

175177
[Fact]
176178
public void Sql_should_get_implicit_max_lengths_for_string_and_binary_properties_by_convention()

test/EntityFramework/FunctionalTests.Transitional/CodeFirst/BasicMappingScenarioTests.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ namespace FunctionalTests
1414
using System.Data.Entity.ModelConfiguration.Edm;
1515
using System.Data.Entity.ModelConfiguration.Edm.Services;
1616
using System.Linq;
17-
using System.Windows.Media;
1817
using FunctionalTests.Model;
1918
using Xunit;
2019

20+
#if NET452
21+
using System.Windows.Media;
22+
#endif
23+
2124
public class BasicMappingScenarioTests : TestBase
2225
{
2326
[Fact]
@@ -333,6 +336,7 @@ public void Explicitly_configured_entity_set_names_are_uniqued()
333336
Assert.Equal("Foo1", databaseMapping.Model.Containers.Single().EntitySets.Last().Name);
334337
}
335338

339+
#if NET452
336340
[Fact]
337341
public void Build_model_for_type_with_framework_type()
338342
{
@@ -350,6 +354,7 @@ public class Stimulus
350354
public int Id { get; set; }
351355
public Brush Background { get; set; }
352356
}
357+
#endif
353358

354359
[Fact]
355360
public void Build_model_for_type_with_internal_member_to_configure_type()

test/EntityFramework/FunctionalTests.Transitional/CodeFirst/DataServicesTests.cs

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

3+
#if NET452
4+
35
namespace FunctionalTests
46
{
57
using System.Data.Entity;
@@ -52,3 +54,5 @@ public class Inner
5254
public string Data { get; set; }
5355
}
5456
}
57+
58+
#endif

test/EntityFramework/FunctionalTests.Transitional/Design/BasicDesignTimeScenarios.cs

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

3+
#if NET452
4+
35
namespace System.Data.Entity.Design
46
{
57
using System.CodeDom.Compiler;
@@ -172,3 +174,5 @@ void IResultHandler.SetResult(object value)
172174
}
173175
}
174176
}
177+
178+
#endif

test/EntityFramework/FunctionalTests.Transitional/FunctionalTests.Transitional.csproj

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<PropertyGroup>
44
<RootNamespace>System.Data.Entity</RootNamespace>
55
<AssemblyName>EntityFramework.FunctionalTests.Transitional</AssemblyName>
6-
<TargetFramework>net452</TargetFramework>
6+
<TargetFrameworks>net452;netcoreapp3.0</TargetFrameworks>
77
</PropertyGroup>
88

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

1919
<ItemGroup>
2020
<PackageReference Include="Moq" Version="$(MoqVersion)" />
21+
</ItemGroup>
22+
23+
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
2124
<PackageReference Include="Microsoft.SqlServer.Compact" Version="$(MicrosoftSqlServerCompactVersion)" />
2225
<PackageReference Include="Microsoft.SqlServer.Types" Version="$(MicrosoftSqlServerTypesVersion)" />
2326
</ItemGroup>
2427

2528
<ItemGroup>
26-
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServerCompact\EntityFramework.SqlServerCompact.csproj" />
2729
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServer\EntityFramework.SqlServer.csproj" />
2830
</ItemGroup>
2931

30-
<ItemGroup>
32+
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
33+
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServerCompact\EntityFramework.SqlServerCompact.csproj" />
34+
</ItemGroup>
35+
36+
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
3137
<Compile Include="$(NuGetPackageRoot)Microsoft.SqlServer.Types\$(MicrosoftSqlServerTypesVersion)\content\SqlServerTypes\Loader.cs">
3238
<Link>SqlServerTypes\Loader.cs</Link>
3339
</Compile>
3440
</ItemGroup>
3541

36-
<ItemGroup>
42+
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
3743
<Content Include="$(NuGetPackageRoot)Microsoft.SqlServer.Types\$(MicrosoftSqlServerTypesVersion)\content\readme.htm">
3844
<Link>SqlServerTypes\readme.htm</Link>
3945
</Content>
@@ -74,7 +80,7 @@
7480
</ItemGroup>
7581

7682
<PropertyGroup>
77-
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT'">
83+
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' And '$(TargetFramework)' == 'net452'">
7884
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
7985
xcopy /s /y "$(NuGetPackageRoot)Microsoft.SqlServer.Compact\$(MicrosoftSqlServerCompactVersion)\NativeBinaries\x86\*.*" "$(TargetDir)x86"
8086
if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"

test/EntityFramework/FunctionalTests.Transitional/Migrations/TestHelpers/InfoContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace System.Data.Entity.Migrations
55
using System.Collections.Generic;
66
using System.Data.Common;
77
using System.Data.Entity.Infrastructure;
8-
using System.Data.SqlServerCe;
98
using System.Linq;
109

1110
public class InfoContext : DbContext
@@ -192,7 +191,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
192191
kcu.ColumnName
193192
});
194193

195-
if (Database.Connection is SqlCeConnection)
194+
if (this.IsSqlCe())
196195
{
197196
column.Property(c => c.NumericPrecision).HasColumnType("smallint");
198197
column.Property(c => c.DateTimePrecision).HasColumnType("int");

test/EntityFramework/FunctionalTests.Transitional/Migrations/TestModel/TestModels.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace System.Data.Entity.Migrations
66
using System.ComponentModel.DataAnnotations;
77
using System.ComponentModel.DataAnnotations.Schema;
88
using System.Data.Entity.Spatial;
9-
using System.Data.SqlServerCe;
109

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

202-
if (!(Database.Connection is SqlCeConnection))
201+
if (!this.IsSqlCe())
203202
{
204203
// NotSupported in CE
205204
modelBuilder.Entity<MigrationsCustomer>().MapToStoredProcedures();
@@ -242,7 +241,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
242241
{
243242
modelBuilder.Entity<MigrationsCustomer>().ToTable("tbl_customers", "crm");
244243

245-
if (!(Database.Connection is SqlCeConnection))
244+
if (!this.IsSqlCe())
246245
{
247246
// NotSupported in CE
248247
modelBuilder.Entity<MigrationsCustomer>().Property(c => c.Name).HasColumnName("new_name");

test/EntityFramework/FunctionalTests.Transitional/ProductivityApi/DbContextTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void Can_replace_connection()
3939
}
4040
}
4141

42+
#if NET452
4243
[Fact]
4344
public void Can_replace_connection_with_different_provider()
4445
{
@@ -54,6 +55,7 @@ public void Can_replace_connection_with_different_provider()
5455
}
5556
}
5657
}
58+
#endif
5759

5860
private void Can_replace_connection_implementation(
5961
ReplaceConnectionContext context,

test/EntityFramework/FunctionalTests.Transitional/TestHelpers/DbContextExtensions.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace System.Data.Entity
44
{
55
using System.Data.Entity.Migrations;
6+
7+
#if NET452
68
using System.Data.SqlServerCe;
9+
#endif
710

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

1619
public static void IgnoreSpatialTypesOnSqlCe(this DbContext context, DbModelBuilder modelBuilder)
1720
{
18-
if (context.Database.Connection is SqlCeConnection)
21+
if (context.IsSqlCe())
1922
{
2023
modelBuilder.Entity<MigrationsStore>().Ignore(e => e.Location);
2124
modelBuilder.Entity<MigrationsStore>().Ignore(e => e.FloorPlan);
@@ -24,7 +27,11 @@ public static void IgnoreSpatialTypesOnSqlCe(this DbContext context, DbModelBuil
2427

2528
public static bool IsSqlCe(this DbContext context)
2629
{
30+
#if NET452
2731
return context.Database.Connection is SqlCeConnection;
32+
#else
33+
return false;
34+
#endif
2835
}
2936
}
3037
}

test/EntityFramework/FunctionalTests.Transitional/TestHelpers/DynamicAssembly.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Assembly Compile()
104104
public Assembly Compile(AssemblyName assemblyName)
105105
{
106106
var assemblyBuilder =
107-
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
107+
AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
108108

109109
foreach (var attribute in Attributes)
110110
{
@@ -336,7 +336,7 @@ private Type DefineEnumType(ModuleBuilder module, DynamicEnumType enumTypeInfo)
336336
Convert.ChangeType(enumMember.Value, enumTypeInfo.UnderlyingType));
337337
}
338338

339-
return enumBuilder.CreateType();
339+
return enumBuilder.CreateTypeInfo().AsType();
340340
}
341341

342342
private static TypeAttributes GetTypeAccess(MemberAccess typeAccess)

test/EntityFramework/FunctionalTests.Transitional/TestHelpers/FunctionalTestsConfiguration.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ namespace System.Data.Entity.TestHelpers
66
using System.Data.Entity.Infrastructure;
77
using System.Data.Entity.Infrastructure.DependencyResolution;
88
using System.Data.Entity.SqlServer;
9-
using System.Data.Entity.SqlServerCompact;
109
using System.Linq;
10+
#if NET452
11+
using System.Data.Entity.SqlServerCompact;
12+
#endif
1113

1214
public class FunctionalTestsConfiguration : DbConfiguration
1315
{
@@ -60,7 +62,9 @@ private static void OnLoaded(object sender, DbConfigurationLoadedEventArgs event
6062

6163
public FunctionalTestsConfiguration()
6264
{
65+
#if NET452
6366
SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);
67+
#endif
6468
SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
6569

6670
SetDefaultConnectionFactory(new DefaultUnitTestsConnectionFactory());

test/EntityFramework/FunctionalTests.Transitional/TestHelpers/TestBase.cs

+4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public class TestBase : MarshalByRefObject
2626
{
2727
static TestBase()
2828
{
29+
#if NET452
2930
SqlServerTypes.Utilities.LoadNativeAssemblies(
3031
Path.GetDirectoryName(typeof(FunctionalTestBase).Assembly.Location));
32+
#endif
3133

3234
DbConfiguration.SetConfiguration(new FunctionalTestsConfiguration());
3335

@@ -572,6 +574,7 @@ public static Configuration CreateEmptyConfig()
572574

573575
#endregion
574576

577+
#if NET452
575578
public static void RunTestInAppDomain(Type testType)
576579
{
577580
var domain = AppDomain.CreateDomain("TestAppDomain", null, AppDomain.CurrentDomain.SetupInformation);
@@ -588,5 +591,6 @@ public static void RunTestInAppDomain(Type testType)
588591
AppDomain.Unload(domain);
589592
}
590593
}
594+
#endif
591595
}
592596
}

test/EntityFramework/FunctionalTests.netcoreapp3.0/FunctionalTests.netcoreapp3.0.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\..\..\src\EntityFramework.SqlServer\EntityFramework.SqlServer.csproj" />
10+
<ProjectReference Include="..\FunctionalTests.Transitional\FunctionalTests.Transitional.csproj" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

test/EntityFramework/FunctionalTests.netcoreapp3.0/Properties/XunitAttributes.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
using Xunit;
44

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

test/EntityFramework/FunctionalTests.netcoreapp3.0/TestHelpers/CodeFirstScaffoldingContext.cs

-18
This file was deleted.

test/EntityFramework/FunctionalTests.netcoreapp3.0/TestHelpers/CodeFirstScaffoldingContextWithConnection.cs

-19
This file was deleted.

0 commit comments

Comments
 (0)