mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
throw a wobbly when you're doing overloads wrong
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Octokit.Tests.Conventions
|
||||
{
|
||||
public class InterfaceMethodsMismatchException : Exception
|
||||
{
|
||||
public InterfaceMethodsMismatchException(Type observableType, Type clientInterface)
|
||||
: base(CreateMessage(observableType, clientInterface)) { }
|
||||
|
||||
public InterfaceMethodsMismatchException(Type type,Type clientInterface, Exception innerException)
|
||||
: base(CreateMessage(type, clientInterface), innerException) { }
|
||||
|
||||
protected InterfaceMethodsMismatchException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) { }
|
||||
|
||||
static string Format(ParameterInfo parameterInfo)
|
||||
{
|
||||
return String.Format("{0} {1}", parameterInfo.ParameterType.Name, parameterInfo.Name);
|
||||
}
|
||||
|
||||
static string Format(MethodInfo methodInfo)
|
||||
{
|
||||
var parameters = methodInfo.GetParameters().Select(Format);
|
||||
|
||||
return String.Format("{0} {1}({2})", methodInfo.ReturnType, methodInfo.Name, String.Join(", ", parameters));
|
||||
}
|
||||
|
||||
static string CreateMessage(Type observableInterface, Type clientInterface)
|
||||
{
|
||||
var mainMethods = clientInterface.GetMethodsOrdered();
|
||||
var observableMethods = observableInterface.GetMethodsOrdered();
|
||||
|
||||
var formattedMainMethods = String.Join("\r\n", mainMethods.Select(Format).Select(m => String.Format(" - {0}", m)));
|
||||
var formattedObservableMethods = String.Join("\r\n", observableMethods.Select(Format).Select(m => String.Format(" - {0}", m)));
|
||||
|
||||
return String.Format("There are some overloads which are confusing the convention tests. Check everything is okay in these types:\r\n{0}\r\n{2}\r\n{1}\r\n{3}", clientInterface.Name, observableInterface.Name, formattedMainMethods, formattedObservableMethods);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DebuggerDisplayOnModels.cs" />
|
||||
<Compile Include="Exception\InterfaceHasAdditionalMethodsException.cs" />
|
||||
<Compile Include="Exception\InterfaceMethodsMismatchException.cs" />
|
||||
<Compile Include="Exception\InterfaceMissingMethodsException.cs" />
|
||||
<Compile Include="Exception\InterfaceNotFoundException.cs" />
|
||||
<Compile Include="Exception\ParameterCountMismatchException.cs" />
|
||||
|
||||
@@ -34,6 +34,11 @@ namespace Octokit.Tests.Conventions
|
||||
throw new InterfaceHasAdditionalMethodsException(observableClient, additionalMethodsOnReactiveClient);
|
||||
}
|
||||
|
||||
if (mainNames.Count() != observableNames.Count())
|
||||
{
|
||||
throw new InterfaceMethodsMismatchException(observableClient, clientInterface);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
foreach(var mainMethod in mainMethods)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user