diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index bff4f4f0..ccc2e2c4 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -4,6 +4,8 @@ using NSubstitute; using Octokit.Internal; using Xunit; using System.Collections.Generic; +using System.Reflection; +using System.Linq; namespace Octokit.Tests { @@ -211,5 +213,54 @@ namespace Octokit.Tests httpClient.Received(1).SetRequestTimeout(TimeSpan.FromSeconds(15)); } } + + public class TheNestedClients + { + private static void VisitAllClientTypes(Type rootType, HashSet result) + { + const BindingFlags ifPropBinding = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + if (!result.Add(rootType)) + return; + + foreach (var pi in rootType.GetProperties(ifPropBinding).Where(pi => pi.CanRead && pi.PropertyType.Name.EndsWith("Client", StringComparison.Ordinal))) + { + VisitAllClientTypes(pi.PropertyType, result); + } + } + + internal static IEnumerable GetGitHubClientNestedInterfaces() + { + var visitedTypes = new HashSet(); + var rootType = typeof(GitHubClient); + VisitAllClientTypes(rootType, visitedTypes); + visitedTypes.Remove(rootType); + return visitedTypes; + } + + public static IEnumerable GetGitHubClientNestedInterfacesMemberData() => + GetGitHubClientNestedInterfaces().Select(t => new[] { t }); + + [Theory] + [MemberData(nameof(GetGitHubClientNestedInterfacesMemberData))] + public void HasImplementationClassWithIApiConnectionCtor(Type clientInterface) + { + var octokitAssembly = typeof(GitHubClient).Assembly; + + var implTypes = octokitAssembly.GetTypes() + .Where(t => t.IsClass && t.IsPublic) + .Where(t => t.GetInterfaces().Contains(clientInterface)) + .ToList(); + + Assert.Single(implTypes, t => + { + const BindingFlags ctorBinding = BindingFlags.Instance | BindingFlags.Public; + var ctor = t.GetConstructor(ctorBinding, Type.DefaultBinder, + new[] { typeof(IApiConnection) }, null) + ?? t.GetConstructor(ctorBinding, Type.DefaultBinder, + new[] { typeof(IConnection) }, null); + return !(ctor is null); + }); + } + } } } diff --git a/Octokit/Clients/ChecksClient.cs b/Octokit/Clients/ChecksClient.cs index 08a6ccfb..63574e46 100644 --- a/Octokit/Clients/ChecksClient.cs +++ b/Octokit/Clients/ChecksClient.cs @@ -12,7 +12,7 @@ /// Initializes a new GitHub Checks API client. /// /// An API connection - public ChecksClient(ApiConnection apiConnection) + public ChecksClient(IApiConnection apiConnection) { Run = new CheckRunsClient(apiConnection); Suite = new CheckSuitesClient(apiConnection);