public static void PublishWithoutLocalDispatch(this IBus bus, IEvent @event) { using (LocalDispatch.Disable()) { bus.Publish(@event); } }
public static Task <CommandResult> SendWithoutLocalDispatch(this IBus bus, ICommand command) { using (LocalDispatch.Disable()) { return(bus.Send(command)); } }
public void SendCommandWithoutLocalDispatch() { using (var bus = CreateBusFactory().WithHandlers(typeof(ManualCommandHandler)).CreateAndStartBus()) { using (LocalDispatch.Disable()) { bus.Send(new ManualCommand(42)).Wait(); } Console.WriteLine(ManualCommandHandler.LastId); } }
public void PublishEventWithoutLocalDispatch() { using (var bus = CreateBusFactory().WithHandlers(typeof(ManualEventHandler)).CreateAndStartBus()) { using (LocalDispatch.Disable()) { bus.Publish(new ManualEvent(42)); } Wait.Until(() => ManualEventHandler.ReceivedEventCount == 1, 300.Seconds()); } }
public void should_reset_local_dispatch_status() { var tcs = new TaskCompletionSource <object>(); _dispatchQueue.Start(); var firstTask = EnqueueAsyncInvocation(new AsyncExecutableEvent { Callback = async _ => { LocalDispatch.Enabled.ShouldBeTrue(); using (LocalDispatch.Disable()) { // An await inside a LocalDispatch.Disable() context is broken // => don't let this mess up other invocations await tcs.Task.ConfigureAwait(true); } } }); var secondTask = EnqueueAsyncInvocation(new AsyncExecutableEvent { Callback = async _ => { LocalDispatch.Enabled.ShouldBeTrue(); await tcs.Task.ConfigureAwait(true); LocalDispatch.Enabled.ShouldBeTrue(); } }); var thirdTask = EnqueueInvocation(new ExecutableEvent { Callback = x => { LocalDispatch.Enabled.ShouldBeTrue(); Task.Run(() => tcs.SetResult(null)); } }); var allTasks = new[] { firstTask, secondTask, thirdTask }; Task.WhenAll(allTasks).Wait(2000.Milliseconds()).ShouldBeTrue(); foreach (var task in allTasks) { task.Result.Errors.ShouldBeEmpty(); } }
public void should_not_handle_event_locally_when_local_dispatch_is_disabled() { var message = new FakeEvent(1); var handled = false; SetupDispatch(message, x => handled = true); SetupPeersHandlingMessage <FakeEvent>(_self); using (LocalDispatch.Disable()) using (MessageId.PauseIdGeneration()) { _bus.Publish(message); handled.ShouldBeFalse(); _transport.ExpectExactly(new TransportMessageSent(message.ToTransportMessage(_self), _self)); } }
public void should_not_handle_command_locally_when_local_dispatch_is_disabled() { var command = new FakeCommand(1); var handled = false; SetupDispatch(command, _ => handled = true); SetupPeersHandlingMessage <FakeCommand>(_self); using (LocalDispatch.Disable()) using (MessageId.PauseIdGeneration()) { var completed = _bus.Send(command).Wait(5); handled.ShouldBeFalse(); completed.ShouldBeFalse(); _transport.ExpectExactly(new TransportMessageSent(command.ToTransportMessage(_self), _self)); } }