public async Task ShouldRegisterAllMethodsOfTypeThatIsMarkedWithCommandHandlerAttribute() { var commandHandler = new TestAttributedCommandHandler(_outputHelper); var registration = new SingleMessageHandlerRegistration(); registration.RegisterCommandHandlersByAttribute(() => commandHandler); IMessageHandlerResolver resolver = registration.BuildMessageHandlerResolver(); MessageHandlerDelegate commandHandlerDelegate = resolver.ResolveMessageHandler(typeof(TestCommand)); commandHandlerDelegate.Should().NotBeNull(); // Delegate should invoke the actual command handler - TestAttributedCommandHandler. await commandHandlerDelegate.Invoke(new TestCommand()); commandHandler.HandledCommands.Should().HaveCount(1); commandHandler.HasHandledCommand <TestCommand>().Should().BeTrue(); }
public async Task ShouldRegisterAllCommandHandlerAttributeMethods() { var commandHandler = new TestAttributedCommandHandler(_outputHelper); // Get methods marked with [CommandHandler] attribute. IEnumerable <CommandHandlerAttributeMethod> methods = CommandHandlerAttributeMethod.FromType(() => commandHandler); var registration = new SingleMessageHandlerRegistration(); registration.RegisterCommandHandlersByAttribute(methods); IMessageHandlerResolver resolver = registration.BuildMessageHandlerResolver(); MessageHandlerDelegate commandHandlerDelegate = resolver.ResolveMessageHandler(typeof(TestCommand)); commandHandlerDelegate.Should().NotBeNull(); // Delegate should invoke the actual command handler - TestAttributedCommandHandler. await commandHandlerDelegate.Invoke(new TestCommand()); commandHandler.HandledCommands.Should().HaveCount(1); commandHandler.HasHandledCommand <TestCommand>().Should().BeTrue(); }