mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
added exception for return value mismatch
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Octokit.Tests.Conventions
|
||||
{
|
||||
public class ReturnValueMismatchException : Exception
|
||||
{
|
||||
public ReturnValueMismatchException(MethodInfo method, Type expected, Type actual)
|
||||
: base(CreateMessage(method, expected, actual)) { }
|
||||
|
||||
public ReturnValueMismatchException(MethodInfo method, Type expected, Type actual, Exception innerException)
|
||||
: base(CreateMessage(method, expected, actual), innerException) { }
|
||||
|
||||
protected ReturnValueMismatchException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) { }
|
||||
|
||||
static string CreateMessage(MethodInfo method, Type expected, Type actual)
|
||||
{
|
||||
return String.Format("Return value for {0}.{1} must be {2} but is {3}", method.DeclaringType.Name, method.Name, expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@
|
||||
<Compile Include="Exception\InterfaceHasAdditionalMethodsException.cs" />
|
||||
<Compile Include="Exception\InterfaceMissingMethodsException.cs" />
|
||||
<Compile Include="Exception\InterfaceNotFoundException.cs" />
|
||||
<Compile Include="Exception\ReturnValueMismatchException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SyncObservableClients.cs" />
|
||||
<Compile Include="TypeExtensions.cs" />
|
||||
|
||||
@@ -59,7 +59,11 @@ namespace Octokit.Tests.Conventions
|
||||
var mainReturnType = mainMethod.ReturnType;
|
||||
var observableReturnType = observableMethod.ReturnType;
|
||||
var expectedType = GetObservableExpectedType(mainReturnType);
|
||||
Assert.Equal(expectedType, observableReturnType);
|
||||
|
||||
if (expectedType != observableReturnType)
|
||||
{
|
||||
throw new ReturnValueMismatchException(observableMethod, expectedType, observableReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
private static Type GetObservableExpectedType(Type mainType)
|
||||
|
||||
Reference in New Issue
Block a user