Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .NET Core 3 #62

Merged
merged 4 commits into from May 18, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Add constants and update tests to support .NET Core 3

Changes for TestBase relate to reflection changes for readonly statics, see: dotnet/coreclr#21268
  • Loading branch information...
Turnerj committed May 18, 2019
commit d861636d80c399e89201ea968399a638a152c369
@@ -50,7 +50,7 @@ public static MongoDbConnection FromConnectionString(string connectionString)
return FromUrl(new MongoUrl(connectionString));
}

#if !NETCOREAPP2_0
#if (!NETCOREAPP2_0 && !NETCOREAPP3_0)
public static MongoDbConnection FromConfig(string connectionName)
{
var connectionStringConfig = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName];
@@ -13,6 +13,10 @@
<DefineConstants>NETCOREAPP2_0</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<DefineConstants>NETCOREAPP3_0</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.8.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
@@ -6,7 +6,7 @@ namespace MongoFramework.Tests
[TestClass]
public class MongoDbConnectionTests
{
#if !NETCOREAPP2_0
#if (!NETCOREAPP2_0 && !NETCOREAPP3_0)
[TestMethod]
public void ConnectionFromConfig()
{
@@ -3,13 +3,17 @@
<PropertyGroup>
<AssemblyName>MongoFramework.Tests</AssemblyName>
<RootNamespace>MongoFramework.Tests</RootNamespace>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp2.0'">
<DefineConstants>NETCOREAPP2_0</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<DefineConstants>NETCOREAPP3_0</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
@@ -29,16 +29,28 @@ private static void ResetMongoDbDriver()
//driver updates. If someone knows a better way to reset the MongoDB driver, please open a pull request!

var classMapField = typeof(BsonClassMap).GetField("__classMaps", BindingFlags.NonPublic | BindingFlags.Static);
classMapField.SetValue(null, new Dictionary<Type, BsonClassMap>());
if (classMapField.GetValue(null) is Dictionary<Type, BsonClassMap> classMaps)
{
classMaps.Clear();
}

var knownTypesField = typeof(BsonSerializer).GetField("__typesWithRegisteredKnownTypes", BindingFlags.NonPublic | BindingFlags.Static);
knownTypesField.SetValue(null, new HashSet<Type>());
if (knownTypesField.GetValue(null) is HashSet<Type> knownTypes)
{
knownTypes.Clear();
}

var discriminatorTypesField = typeof(BsonSerializer).GetField("__discriminatedTypes", BindingFlags.NonPublic | BindingFlags.Static);
discriminatorTypesField.SetValue(null, new HashSet<Type>());
if (discriminatorTypesField.GetValue(null) is HashSet<Type> discriminatorTypes)
{
discriminatorTypes.Clear();
}

var discriminatorsField = typeof(BsonSerializer).GetField("__discriminators", BindingFlags.NonPublic | BindingFlags.Static);
discriminatorsField.SetValue(null, new Dictionary<BsonValue, HashSet<Type>>());
if (discriminatorsField.GetValue(null) is Dictionary<BsonValue, HashSet<Type>> discriminators)
{
discriminators.Clear();
}

var serializerRegistryField = typeof(BsonSerializer).GetField("__serializerRegistry", BindingFlags.NonPublic | BindingFlags.Static);
if (serializerRegistryField.GetValue(null) is BsonSerializerRegistry registry)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.