From 235ac7d4f3d3d2472d5830f804f1ac2e71347f6f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 20 Feb 2014 22:28:59 +1100 Subject: [PATCH] added exception for return value mismatch --- .../Exception/ReturnValueMismatchException.cs | 23 +++++++++++++++++++ .../Octokit.Tests.Conventions.csproj | 1 + .../SyncObservableClients.cs | 6 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests.Conventions/Exception/ReturnValueMismatchException.cs diff --git a/Octokit.Tests.Conventions/Exception/ReturnValueMismatchException.cs b/Octokit.Tests.Conventions/Exception/ReturnValueMismatchException.cs new file mode 100644 index 00000000..121751d7 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/ReturnValueMismatchException.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 8979df85..8caa28f7 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -53,6 +53,7 @@ + diff --git a/Octokit.Tests.Conventions/SyncObservableClients.cs b/Octokit.Tests.Conventions/SyncObservableClients.cs index c78e5a47..c78eb4cd 100644 --- a/Octokit.Tests.Conventions/SyncObservableClients.cs +++ b/Octokit.Tests.Conventions/SyncObservableClients.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)