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(); }
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(); }
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> >(); }
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)); } }
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); }
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(); }
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"); }
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"); }
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"); }
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"); }
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)); }