예제 #1
0
        public async Task Dispatch_Command_With_Result_Should_Go_To_Correct_Path()
        {
            var bus = new InMemoryCommandBus();

            var cmd      = new TestResultOkCommand();
            var okResult = await bus.DispatchAsync(cmd);

            okResult.IsSuccess.Should().BeTrue();

            var cmd2       = new TestResultFailCommand();
            var failResult = await bus.DispatchAsync(cmd2);

            failResult.IsSuccess.Should().BeFalse();
        }
예제 #2
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();
        }
예제 #3
0
        public async Task Dispatch_Command_SpecificResult_Should_Not_Loose_Value()
        {
            var bus = new InMemoryCommandBus();

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

            result.Should().BeOfType <Result <string> >();
        }
예제 #4
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();
        }
        public async Task DispatchRangeCommands(int nbCommands)
        {
            var bus = new InMemoryCommandBus();

            for (int i = 0; i < nbCommands; i++)
            {
                await bus.DispatchAsync(new TestCommand(i, SimulateWork, JobDuration));
            }
        }
예제 #6
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);
        }
예제 #7
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();
        }
예제 #8
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");
        }
예제 #9
0
        public async Task InMemoryCommandBus_DispatchAsync_Reflexion()
        {
            CleanRegistrationInDispatcher();
            var bus = new InMemoryCommandBus();

            (await bus.DispatchAsync(new TestCommand {
                Data = "test_ioc"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestCommandHandler.HandlerData.Should().Be("test_ioc");
            TestCommandHandler.Origin.Should().Be("reflexion");
        }
예제 #10
0
        public async Task InMemoryCommandBus_DispatchAsync_FromCoreDispatcher()
        {
            CleanRegistrationInDispatcher();
            CoreDispatcher.AddHandlerToDispatcher(new TestCommandHandler("coreDispatcher"));
            var bus = new InMemoryCommandBus();

            (await bus.DispatchAsync(new TestCommand {
                Data = "test_dispatcher"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestCommandHandler.HandlerData.Should().Be("test_dispatcher");
            TestCommandHandler.Origin.Should().Be("spec_ctor");
        }
예제 #11
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");
        }
예제 #12
0
        public async Task InMemoryCommandBus_DispatchAsync_HandlerFromIoC()
        {
            var factory = new TestScopeFactory();

            factory.Instances.Add(typeof(ICommandHandler <TestCommand>), new TestCommandHandler("tt"));

            CleanRegistrationInDispatcher();
            var bus = new InMemoryCommandBus(null, factory);

            (await bus.DispatchAsync(new TestCommand {
                Data = "test_ioc"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestCommandHandler.HandlerData.Should().Be("test_ioc");
            TestCommandHandler.Origin.Should().Be("spec_ctor");
        }
 public async Task DispatchACommand()
 {
     var bus = new InMemoryCommandBus();
     await bus.DispatchAsync(new TestCommand(0, SimulateWork, JobDuration));
 }