コード例 #1
0
            public async Task Should_Invoke_Registered_Attributed_Command_Handler()
            {
                var commandHandler = new TestAttributedCommandHandler(_outputHelper);
                var registration   = new CommandHandlerAttributeRegistration();

                registration.Register(() => commandHandler);

                var dispatcher = new CommandDispatcher(registration);
                await dispatcher.DispatchAsync(new DoSomethingCommand());

                Assert.Equal(1, commandHandler.HandledCommands.Count);
                Assert.Contains(commandHandler.HandledCommands, c => c is DoSomethingCommand);
            }
コード例 #2
0
            public void Should_Register_All_Command_Handlers_Methods()
            {
                var commandHandler = new TestAttributedCommandHandler(_outputHelper);

                var registration = new CommandHandlerAttributeRegistration();

                registration.Register(() => commandHandler);

                CommandHandlerDelegate commandHandlerDelegate = registration.ResolveCommandHandler <DoSomethingCommand>();

                Assert.NotNull(commandHandlerDelegate);

                // Delegate should invoke the actual command handler - TestAttributedCommandHandler.
                commandHandlerDelegate.Invoke(new DoSomethingCommand());

                Assert.Equal(1, commandHandler.HandledCommands.Count);
                Assert.Contains(commandHandler.HandledCommands, c => c is DoSomethingCommand);
            }
            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();
            }