diff --git a/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs b/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs new file mode 100644 index 00000000..4bccc557 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; + +namespace Octokit.Tests.Conventions +{ + public class InterfaceHasAdditionalMethodsException : Exception + { + public InterfaceHasAdditionalMethodsException(Type type, IEnumerable methodsMissingOnReactiveClient) + : base(CreateMessage(type, methodsMissingOnReactiveClient)) { } + + public InterfaceHasAdditionalMethodsException(Type type, IEnumerable methodsMissingOnReactiveClient, Exception innerException) + : base(CreateMessage(type, methodsMissingOnReactiveClient), innerException) { } + + protected InterfaceHasAdditionalMethodsException(SerializationInfo info, StreamingContext context) + : base(info, context) { } + + static string CreateMessage(Type type, IEnumerable methods) + { + var methodsFormatted = String.Join("\r\n", methods.Select(m => String.Format(" - {0}", m))); + return String.Format("Methods found on type {0} which should be removed:\r\n{1}", type.Name, methodsFormatted); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs b/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs new file mode 100644 index 00000000..65fc8c76 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; + +namespace Octokit.Tests.Conventions +{ + public class InterfaceMissingMethodsException : Exception + { + public InterfaceMissingMethodsException(Type type, IEnumerable methodsMissingOnReactiveClient) + : base(CreateMessage(type, methodsMissingOnReactiveClient)) { } + + public InterfaceMissingMethodsException(Type type, IEnumerable methodsMissingOnReactiveClient, Exception innerException) + : base(CreateMessage(type, methodsMissingOnReactiveClient), innerException) { } + + protected InterfaceMissingMethodsException(SerializationInfo info, StreamingContext context) + : base(info, context) { } + + static string CreateMessage(Type type, IEnumerable methods) + { + var methodsFormatted = String.Join("\r\n", methods.Select(m => String.Format(" - {0}", m))); + return String.Format("Methods not found on interface {0} which are required:\r\n{1}", type.Name, methodsFormatted); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Exception/InterfaceNotFoundException.cs b/Octokit.Tests.Conventions/Exception/InterfaceNotFoundException.cs new file mode 100644 index 00000000..3a428331 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/InterfaceNotFoundException.cs @@ -0,0 +1,25 @@ +using System; +using System.Runtime.Serialization; + +namespace Octokit.Tests.Conventions +{ + public class InterfaceNotFoundException : Exception + { + public InterfaceNotFoundException() { } + + public InterfaceNotFoundException(string type) + : base(CreateMessage(type)) { } + + public InterfaceNotFoundException(string type, Exception innerException) + : base(CreateMessage(type), innerException) { } + + protected InterfaceNotFoundException(SerializationInfo info, StreamingContext context) + : base(info, context) { } + + static string CreateMessage(string type) + { + return String.Format("Could not find the interface {0}. Add this to the Octokit.Reactive project", type); + } + + } +} diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 7b378297..8979df85 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -50,6 +50,9 @@ + + + diff --git a/Octokit.Tests.Conventions/SyncObservableClients.cs b/Octokit.Tests.Conventions/SyncObservableClients.cs index 376750ac..c78e5a47 100644 --- a/Octokit.Tests.Conventions/SyncObservableClients.cs +++ b/Octokit.Tests.Conventions/SyncObservableClients.cs @@ -13,23 +13,30 @@ namespace Octokit.Tests.Conventions { public class SyncObservableClients { - [Fact] - private void CheckObservableClientExample() - { - CheckObservableClients(typeof(ISearchClient)); - } - [Theory] [ClassData(typeof(ClientInterfaces))] - private void CheckObservableClients(Type clientInterface) + public void CheckObservableClients(Type clientInterface) { var observableClient = clientInterface.GetObservableClientInterface(); var mainMethods = clientInterface.GetMethodsOrdered(); var observableMethods = observableClient.GetMethodsOrdered(); var mainNames = Array.ConvertAll(mainMethods, m => m.Name); var observableNames = Array.ConvertAll(observableMethods, m => m.Name); - AssertEx.Empty(observableNames.Except(mainNames), "Extra observable methods"); - AssertEx.Empty(mainNames.Except(observableNames), "Missing observable methods"); + + var methodsMissingOnReactiveClient = mainNames.Except(observableNames); + + if (methodsMissingOnReactiveClient.Any()) + { + throw new InterfaceMissingMethodsException(observableClient, methodsMissingOnReactiveClient); + } + + var additionalMethodsOnReactiveClient = observableNames.Except(mainNames); + + if (additionalMethodsOnReactiveClient.Any()) + { + throw new InterfaceHasAdditionalMethodsException(observableClient, additionalMethodsOnReactiveClient); + } + int index = 0; foreach(var mainMethod in mainMethods) { @@ -88,7 +95,7 @@ namespace Octokit.Tests.Conventions { var observableParameter = observableParameters[index]; Assert.Equal(mainParameter.Name, observableParameter.Name); - var mainType = mainParameter.ParameterType; + var mainType = mainParameter.ParameterType; var typeInfo = mainType.GetTypeInfo(); var expectedType = GetObservableExpectedType(mainType); Assert.Equal(expectedType, observableParameter.ParameterType); diff --git a/Octokit.Tests.Conventions/TypeExtensions.cs b/Octokit.Tests.Conventions/TypeExtensions.cs index ea7900a9..4028b26e 100644 --- a/Octokit.Tests.Conventions/TypeExtensions.cs +++ b/Octokit.Tests.Conventions/TypeExtensions.cs @@ -80,7 +80,7 @@ namespace Octokit.Tests.Conventions var observableInterface = observableClient.Assembly.GetType(observableClientName); if(observableInterface == null) { - throw new Exception("Cannot find observable interface "+observableClientName); + throw new InterfaceNotFoundException(observableClientName); } return observableInterface; }