Files
octokit.net/Octokit.Tests.Conventions/ClientConstructorTests.cs
Mickaël Derriey 4869fd5423 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
2017-08-07 10:21:58 +10:00

48 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit;
namespace Octokit.Tests.Conventions
{
public class ClientConstructorTests
{
[Theory]
[MemberData(nameof(GetTestConstructorClasses))]
public void CheckTestConstructorNames(Type type)
{
const string constructorTestClassName = "TheCtor";
const string constructorTestMethodName = "EnsuresNonNullArguments";
var classes = new HashSet<string>(type.GetTypeInfo().GetNestedTypes().Select(t => t.Name));
if (!classes.Contains(constructorTestClassName))
{
throw new MissingClientConstructorTestClassException(type);
}
var ctors = type.GetTypeInfo().GetNestedTypes().Where(t => t.Name == constructorTestClassName)
.SelectMany(t => t.GetMethods())
.Where(info => info.ReturnType == typeof(void) && info.IsPublic)
.Select(info => info.Name);
var methods = new HashSet<string>(ctors);
if (!methods.Contains(constructorTestMethodName))
{
throw new MissingClientConstructorTestMethodException(type);
}
}
public static IEnumerable<object[]> GetTestConstructorClasses()
{
var tests = typeof(GitHubClientTests)
.GetTypeInfo()
.Assembly
.ExportedTypes
.Where(type => type.GetTypeInfo().IsClass && type.GetTypeInfo().IsPublic && type.Name.EndsWith("ClientTests"))
.Select(type => new[] { type });
return tests;
}
}
}