From c9d0ead55feec4abc8db2819b671a203dcd9e4c1 Mon Sep 17 00:00:00 2001 From: Adrian Alonso Date: Tue, 31 May 2016 12:22:48 -0300 Subject: [PATCH] Use the CommandBus type explicitly to get the declared methods And avoid null reference exception when the running command bus instance was created using an inherited class (so the private inherited methods won't be found) --- src/Commands/Merq.Commands.Tests/CommandBusSpec.cs | 8 ++++++++ src/Commands/Merq.Commands/CommandBus.cs | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Commands/Merq.Commands.Tests/CommandBusSpec.cs b/src/Commands/Merq.Commands.Tests/CommandBusSpec.cs index 032ba04f..1c4abdb5 100644 --- a/src/Commands/Merq.Commands.Tests/CommandBusSpec.cs +++ b/src/Commands/Merq.Commands.Tests/CommandBusSpec.cs @@ -278,5 +278,13 @@ IEnumerable ICommandHandler>.Exe yield return result; } } + + // Ensure all test to be run using a derived command bus class + class CommandBus : Merq.CommandBus + { + public CommandBus (IEnumerable handlers) : base (handlers) { } + + public CommandBus (params ICommandHandler[] handlers) : base (handlers) { } + } } } diff --git a/src/Commands/Merq.Commands/CommandBus.cs b/src/Commands/Merq.Commands/CommandBus.cs index 094d73b9..0dac5575 100644 --- a/src/Commands/Merq.Commands/CommandBus.cs +++ b/src/Commands/Merq.Commands/CommandBus.cs @@ -138,9 +138,9 @@ object ExecuteImpl (string methodName, Type[] typeArguments, params object[] par // // commandBus.Execute (new MyCommand ()) // void command // var result = commandBus.execute (new MyCommandWithResult ()) // command with result - + try { - return this.GetType () + return typeof (CommandBus) .GetTypeInfo () .GetDeclaredMethod (methodName) .MakeGenericMethod (typeArguments)