-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add metadata to each client action (#2124)
- Loading branch information
Showing
79 changed files
with
1,178 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Conventions | ||
{ | ||
public class ClientRouteTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(GetClientClasses))] | ||
public void ClassMethodsAreMarkedAsGeneratedManualOrDotNetSpecific(Type clientClass) | ||
{ | ||
var methodFailures = new List<MethodInfo>(); | ||
|
||
foreach (var method in clientClass.GetMethodsOrdered().Where(IsNotBoilerplateMethod)) | ||
{ | ||
var success = MethodIsMarkedGeneratedManualOrDotNetSpecific(method); | ||
if (!success) | ||
{ | ||
methodFailures.Add(method); | ||
} | ||
} | ||
|
||
if (methodFailures.Count > 0) | ||
{ | ||
var methodNames = string.Join(", ", methodFailures.Select(m => m.Name)); | ||
throw new Xunit.Sdk.XunitException($"These methods on {clientClass.Name} are not marked with one of ManualRouteAttribute, GeneratedRouteAttribute or DotNetSpecificRouteAttribute: '{methodNames}'"); | ||
} | ||
} | ||
|
||
static bool MethodIsMarkedGeneratedManualOrDotNetSpecific(MethodInfo method) | ||
{ | ||
var manualRoute = method.GetCustomAttribute<ManualRouteAttribute>(); | ||
if (manualRoute != null) | ||
{ | ||
return true; | ||
} | ||
|
||
var generatedRoute = method.GetCustomAttribute<GeneratedRouteAttribute>(); | ||
if (generatedRoute != null) | ||
{ | ||
return true; | ||
} | ||
|
||
var dotnetSpecificRoute = method.GetCustomAttribute<DotNetSpecificRouteAttribute>(); | ||
if (dotnetSpecificRoute != null) | ||
{ | ||
return true; | ||
} | ||
|
||
var obsolete = method.GetCustomAttribute<ObsoleteAttribute>(); | ||
if (obsolete != null) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static bool IsNotBoilerplateMethod(MethodInfo method) | ||
{ | ||
if (method.IsSpecialName) | ||
{ | ||
return false; | ||
} | ||
|
||
if (method.Name == "GetType" || method.Name == "ToString" || method.Name == "GetHashCode" || method.Name == "Equals") | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static IEnumerable<object[]> GetClientClasses() | ||
{ | ||
return typeof(IGitHubClient) | ||
.GetTypeInfo() | ||
.Assembly | ||
.ExportedTypes | ||
.Where(TypeExtensions.IsClientClass) | ||
.Where(t => t != typeof(StatisticsClient)) // This convention doesn't apply to this one type. | ||
.Where(t => t != typeof(GitHubClient)) | ||
.Select(type => new[] { type }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.