예제 #1
0
        public async Task InMemoryCommandBus_Configuration_MultipleHandlers_ConfigurationOk()
        {
            var c = new InMemoryCommandBusConfigurationBuilder()
                    .AllowMultipleHandlersFor <TestMultipleHandlerFromConfig>();
            var bus = new InMemoryCommandBus(c.Build());

            (await bus.DispatchAsync(new TestMultipleHandlerFromConfig()).ConfigureAwait(false)).IsSuccess.Should().BeTrue();
        }
예제 #2
0
        public async Task InMemoryCommandBus_DispatchAsync_NoHandlerCanBeCreated()
        {
            var hInvoked = false;
            var c        = new InMemoryCommandBusConfigurationBuilder().AddHandlerWhenHandlerIsNotFound((cmd, ctx) => hInvoked = true).Build();
            var bus      = new InMemoryCommandBus(c);

            (await bus.DispatchAsync(new TestNoCreatableHandler()).ConfigureAwait(false)).IsSuccess.Should().BeFalse();
            hInvoked.Should().BeTrue();
        }
예제 #3
0
        public async Task Dispatch_Command_OneFail_Should_Returns_Failed_Result()
        {
            var c = new InMemoryCommandBusConfigurationBuilder()
                    .AllowMultipleHandlersFor <TestMultilpleCommand>()
                    .Build();
            var bus = new InMemoryCommandBus(c);

            var cmd    = new TestMultilpleCommand();
            var result = await bus.DispatchAsync(cmd);

            result.IsSuccess.Should().BeFalse();
        }
예제 #4
0
        public async Task Dispatch_Command_CriticalHandlerThrow_Should_NotCallNextHandlers()
        {
            HandlersData = "";
            var cmd = new CriticalCommand();

            var c   = new InMemoryCommandBusConfigurationBuilder().AllowMultipleHandlersFor <CriticalCommand>(true).Build();
            var bus = new InMemoryCommandBus(c);

            await bus.DispatchAsync(cmd);

            HandlersData.Should().Be("A");
        }
예제 #5
0
        public async Task InMemoryCommandBus_Configuration_MultipleHandlers_ConfigurationOk_ShouldWait()
        {
            s_Order.Clear();
            var c = new InMemoryCommandBusConfigurationBuilder()
                    .AllowMultipleHandlersFor <TestMultipleHandlerFromConfigParallel>(true);
            var bus = new InMemoryCommandBus(c.Build());

            (await bus.DispatchAsync(new TestMultipleHandlerFromConfigParallel()).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            s_Order.Should().HaveCount(3);
            s_Order.Should().Contain("One");
            s_Order.Should().Contain("Two");
            s_Order.Should().Contain("Three");
        }
예제 #6
0
        /// <summary>
        /// Configure the system to use InMemory Command bus for dipsatching commands, with the provided configuration.
        /// </summary>
        /// <param name="bootstrapper">Bootstrapper instance.</param>
        /// <param name="configurationBuilderAction">Action to apply on builder.</param>
        /// <param name="excludedCommandsDLLs">DLLs name to exclude from auto-configuration into IoC
        /// (IAutoRegisterType will be ineffective).</param>
        /// <returns>Bootstrapper Instance.</returns>
        public static Bootstrapper UseInMemoryCommandBus(this Bootstrapper bootstrapper, Action <InMemoryCommandBusConfigurationBuilder> configurationBuilderAction,
                                                         params string[] excludedCommandsDLLs)
        {
            if (configurationBuilderAction == null)
            {
                throw new ArgumentNullException(nameof(configurationBuilderAction));
            }

            InMemoryCommandBus.InitHandlersCollection(excludedCommandsDLLs);
            var builder = new InMemoryCommandBusConfigurationBuilder();

            configurationBuilderAction(builder);

            return(UseInMemoryCommandBus(bootstrapper, builder.Build()));
        }
예제 #7
0
        public async Task InMemoryCommandBus_Configuration_DispatchIfClause()
        {
            TestIfCommandHandler.ResetData();
            var cfgBuilder =
                new InMemoryCommandBusConfigurationBuilder()
                .DispatchOnlyIf <TestIfCommand>(e => e.Data > 1);

            var b = new InMemoryCommandBus(cfgBuilder.Build());

            TestIfCommandHandler.Data.Should().Be(0);

            await b.DispatchAsync(new TestIfCommand { Data = 1 }).ConfigureAwait(false);

            TestIfCommandHandler.Data.Should().Be(0);

            await b.DispatchAsync(new TestIfCommand { Data = 10 }).ConfigureAwait(false);

            TestIfCommandHandler.Data.Should().Be(10);
        }