added exception for return value mismatch

This commit is contained in:
Brendan Forster
2014-02-20 22:28:59 +11:00
parent 87638fc41d
commit 235ac7d4f3
3 changed files with 29 additions and 1 deletions

View File

@@ -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);
}
}
}

View File

@@ -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" />

View File

@@ -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)