From 4869fd54236b9a046a9a98c327fd5bc241a1074c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Derriey?= Date: Mon, 7 Aug 2017 10:21:58 +1000 Subject: [PATCH] Fix broken JSON deserialization in .NET 4.5 (#1647) * Cross target Octokit.Tests against netcoreapp1.0 and net452 * Add net45-specific references This fixes a build error after adding the net452 target: error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' * Add SimpleJson conditional compilation symbols for net45 * Disable AppDomain when running tests Thanks to Dominick and Patrik: https://twitter.com/leastprivilege/status/893376624233762816 * Use nameof operator instead of magic strings * Remove conditional compilation symbols as they are not used in the conventions tests project * Enable cross targetting in the conventions tests project * Run tests against netcoreapp1.0 only when not on Windows * Going too fast bites you --- .../ClientConstructorTests.cs | 2 +- Octokit.Tests.Conventions/ModelTests.cs | 14 +++++------ .../Octokit.Tests.Conventions.csproj | 11 ++++----- Octokit.Tests.Conventions/PaginationTests.cs | 4 ++-- .../SyncObservableClients.cs | 2 +- Octokit.Tests.Conventions/xunit.runner.json | 3 +++ Octokit.Tests/Octokit.Tests.csproj | 12 ++++++++-- Octokit.Tests/xunit.runner.json | 3 +++ Octokit/Octokit.csproj | 2 +- build/Context.cs | 23 +++++++++++++++++++ build/Tasks/ConventionTests.cs | 8 +------ build/Tasks/UnitTests.cs | 8 +------ 12 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 Octokit.Tests.Conventions/xunit.runner.json create mode 100644 Octokit.Tests/xunit.runner.json diff --git a/Octokit.Tests.Conventions/ClientConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs index 048e3a5c..94f79a9d 100644 --- a/Octokit.Tests.Conventions/ClientConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Conventions public class ClientConstructorTests { [Theory] - [MemberData("GetTestConstructorClasses")] + [MemberData(nameof(GetTestConstructorClasses))] public void CheckTestConstructorNames(Type type) { const string constructorTestClassName = "TheCtor"; diff --git a/Octokit.Tests.Conventions/ModelTests.cs b/Octokit.Tests.Conventions/ModelTests.cs index 577fe55e..fbfe1a73 100644 --- a/Octokit.Tests.Conventions/ModelTests.cs +++ b/Octokit.Tests.Conventions/ModelTests.cs @@ -14,7 +14,7 @@ namespace Octokit.Tests.Conventions private static readonly Assembly Octokit = typeof(AuthorizationUpdate).GetTypeInfo().Assembly; [Theory] - [MemberData("ModelTypes")] + [MemberData(nameof(ModelTypes))] public void AllModelsHaveDebuggerDisplayAttribute(Type modelType) { var attribute = modelType.GetTypeInfo().GetCustomAttribute(inherit: false); @@ -41,7 +41,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("ResponseModelTypes")] + [MemberData(nameof(ResponseModelTypes))] public void AllResponseModelsHavePublicParameterlessCtors(Type modelType) { var ctor = modelType.GetConstructor(Type.EmptyTypes); @@ -53,7 +53,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("ResponseModelTypes")] + [MemberData(nameof(ResponseModelTypes))] public void ResponseModelsHaveGetterOnlyProperties(Type modelType) { var mutableProperties = new List(); @@ -77,7 +77,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("ResponseModelTypes")] + [MemberData(nameof(ResponseModelTypes))] public void ResponseModelsHaveReadOnlyCollections(Type modelType) { var mutableCollectionProperties = new List(); @@ -111,7 +111,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("ResponseModelTypes")] + [MemberData(nameof(ResponseModelTypes))] public void ResponseModelsUseStringEnumWrapper(Type modelType) { var enumProperties = modelType.GetProperties() @@ -124,7 +124,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("ModelTypesWithUrlProperties")] + [MemberData(nameof(ModelTypesWithUrlProperties))] public void ModelsHaveUrlPropertiesOfTypeString(Type modelType) { var propertiesWithInvalidType = modelType @@ -140,7 +140,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("EnumTypes")] + [MemberData(nameof(EnumTypes))] public void EnumMembersHaveParameterAttribute(Type enumType) { if (enumType == typeof(Language)) diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 63c269eb..4372cf1c 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -4,7 +4,7 @@ Convention-based tests for Octokit Octokit.Tests.Conventions GitHub - netcoreapp1.0 + netcoreapp1.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests.Conventions Octokit.Tests.Conventions @@ -24,18 +24,17 @@ + + PreserveNewest + - + - - $(DefineConstants);NO_SERIALIZABLE;HAS_TYPEINFO - - diff --git a/Octokit.Tests.Conventions/PaginationTests.cs b/Octokit.Tests.Conventions/PaginationTests.cs index 0b28e3e8..56e33ff6 100644 --- a/Octokit.Tests.Conventions/PaginationTests.cs +++ b/Octokit.Tests.Conventions/PaginationTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Conventions public class PaginationTests { [Theory(Skip = "Enable this to run it and find all the places where things break")] - [MemberData("GetClientInterfaces")] + [MemberData(nameof(GetClientInterfaces))] public void CheckObservableClients(Type clientInterface) { var methodsOrdered = clientInterface.GetMethodsOrdered(); @@ -28,7 +28,7 @@ namespace Octokit.Tests.Conventions } [Theory] - [MemberData("GetClientInterfaces")] + [MemberData(nameof(GetClientInterfaces))] public void CheckPaginationGetAllMethodNames(Type clientInterface) { var methodsOrdered = clientInterface.GetMethodsOrdered(); diff --git a/Octokit.Tests.Conventions/SyncObservableClients.cs b/Octokit.Tests.Conventions/SyncObservableClients.cs index e15fc001..079d5cc9 100644 --- a/Octokit.Tests.Conventions/SyncObservableClients.cs +++ b/Octokit.Tests.Conventions/SyncObservableClients.cs @@ -11,7 +11,7 @@ namespace Octokit.Tests.Conventions public class SyncObservableClients { [Theory] - [MemberData("GetClientInterfaces")] + [MemberData(nameof(GetClientInterfaces))] public void CheckObservableClients(Type clientInterface) { var observableClient = clientInterface.GetObservableClientInterface(); diff --git a/Octokit.Tests.Conventions/xunit.runner.json b/Octokit.Tests.Conventions/xunit.runner.json new file mode 100644 index 00000000..510a5d48 --- /dev/null +++ b/Octokit.Tests.Conventions/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "appDomain": "denied" +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 5e07c8c1..7ac9997f 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -4,7 +4,7 @@ Tests for Octokit Octokit.Tests GitHub - netcoreapp1.0 + netcoreapp1.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests Octokit.Tests @@ -23,9 +23,12 @@ + + PreserveNewest + - + @@ -41,6 +44,11 @@ + + + + + diff --git a/Octokit.Tests/xunit.runner.json b/Octokit.Tests/xunit.runner.json new file mode 100644 index 00000000..510a5d48 --- /dev/null +++ b/Octokit.Tests/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "appDomain": "denied" +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 679ca4be..8ed1ac46 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -24,7 +24,7 @@ - $(DefineConstants);HAS_ENVIRONMENT;HAS_REGEX_COMPILED_OPTIONS + $(DefineConstants);HAS_ENVIRONMENT;HAS_REGEX_COMPILED_OPTIONS;SIMPLE_JSON_INTERNAL,SIMPLE_JSON_OBJARRAYINTERNAL,SIMPLE_JSON_READONLY_COLLECTIONS diff --git a/build/Context.cs b/build/Context.cs index 87e0bf76..78edb7cf 100644 --- a/build/Context.cs +++ b/build/Context.cs @@ -1,3 +1,6 @@ +using Cake.Common; +using Cake.Common.Diagnostics; +using Cake.Common.Tools.DotNetCore.Test; using Cake.Core; using Cake.Core.IO; using Cake.Frosting; @@ -23,6 +26,26 @@ public class Context : FrostingContext public Project[] Projects { get; set; } + public DotNetCoreTestSettings GetTestSettings() + { + var settings = new DotNetCoreTestSettings + { + Configuration = Configuration, + NoBuild = true, + Verbose = false + }; + + if (!this.IsRunningOnWindows()) + { + var testFramework = "netcoreapp1.0"; + + this.Information($"Running tests against {testFramework} only as we're not on Windows."); + settings.Framework = testFramework; + } + + return settings; + } + public Context(ICakeContext context) : base(context) { diff --git a/build/Tasks/ConventionTests.cs b/build/Tasks/ConventionTests.cs index c927b22a..e1c93d97 100644 --- a/build/Tasks/ConventionTests.cs +++ b/build/Tasks/ConventionTests.cs @@ -1,7 +1,6 @@ using System.Linq; using Cake.Common.Diagnostics; using Cake.Common.Tools.DotNetCore; -using Cake.Common.Tools.DotNetCore.Test; using Cake.Frosting; [Dependency(typeof(Build))] @@ -12,12 +11,7 @@ public sealed class ConventionTests : FrostingTask foreach (var project in context.Projects.Where(x => x.ConventionTests)) { context.Information("Executing Convention Tests Project {0}...", project.Name); - context.DotNetCoreTest(project.Path.FullPath, new DotNetCoreTestSettings - { - Configuration = context.Configuration, - NoBuild = true, - Verbose = false - }); + context.DotNetCoreTest(project.Path.FullPath, context.GetTestSettings()); } } } \ No newline at end of file diff --git a/build/Tasks/UnitTests.cs b/build/Tasks/UnitTests.cs index 240d641c..42584c64 100644 --- a/build/Tasks/UnitTests.cs +++ b/build/Tasks/UnitTests.cs @@ -1,7 +1,6 @@ using System.Linq; using Cake.Common.Diagnostics; using Cake.Common.Tools.DotNetCore; -using Cake.Common.Tools.DotNetCore.Test; using Cake.Frosting; [Dependency(typeof(Build))] @@ -12,12 +11,7 @@ public sealed class UnitTests : FrostingTask foreach (var project in context.Projects.Where(x => x.UnitTests)) { context.Information("Executing Unit Tests Project {0}...", project.Name); - context.DotNetCoreTest(project.Path.FullPath, new DotNetCoreTestSettings - { - Configuration = context.Configuration, - NoBuild = true, - Verbose = false - }); + context.DotNetCoreTest(project.Path.FullPath, context.GetTestSettings()); } } } \ No newline at end of file