public void Commands_are_pushed_into_observable() { var busEngine = new InMemoryBusEngine(); var builder = new NybusBusBuilder(busEngine); var list = new List <TestCommand>(); var disposable = builder.ObserveCommand <TestCommand>().Select(c => c.Message).Subscribe(list.Add); var observable = scheduler.CreateHotObservable( OnNext(500, fixture.Create <CommandMessage <TestCommand> >()), OnNext(600, fixture.Create <CommandMessage <TestCommand> >()), OnNext(1000, fixture.Create <CommandMessage <TestCommand> >()), OnNext(1200, fixture.Create <CommandMessage <TestCommand> >()), OnNext(1500, fixture.Create <CommandMessage <TestCommand> >()) ); var results = scheduler.Start(() => observable.Do(msg => Task.WaitAll(busEngine.HandleCommand(msg))).Select(c => c.Command), 100, 150, 3000); disposable.Dispose(); for (int i = 0; i < list.Count; i++) { Assert.That(list[i], Is.SameAs(results.Messages[i].Value.Value)); } }
static void Main(string[] args) { var logger = new NLogLogger(NLog.LogManager.GetLogger("Test")); var options = new NybusOptions { Logger = logger }; var engine = new InMemoryBusEngine(); var busBuilder = new NybusBusBuilder(engine, options); var consoleLocker = new object(); IDisposable testEventHandle = busBuilder.ObserveEvent<TestEvent>().Buffer(TimeSpan.FromSeconds(1)).Subscribe(tc => { lock (consoleLocker) { Console.WriteLine($"Received {tc.Count} events during the last 1 seconds"); foreach (var i in tc) { Console.WriteLine($"\t{i.CorrelationId:D} - {i.Message.Id} - '{i.Message.Message}'"); } Console.WriteLine(); } }); IDisposable testCommandHandle = busBuilder.ObserveCommand<TestCommand>().Buffer(10).Subscribe(tc => { lock (consoleLocker) { Console.WriteLine($"Received {tc.Count} commands"); foreach (var i in tc) { Console.WriteLine($"\t{i.CorrelationId:D} - {i.Message.Id} - '{i.Message.Message}'"); } Console.WriteLine(); } }); IBus bus = busBuilder.Build(); Task.WaitAll(bus.Start()); Task.WhenAll(InvokeManyEvents(bus, 50), InvokeManyCommands(bus, 50)).WaitAndUnwrapException(); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); testEventHandle.Dispose(); testCommandHandle.Dispose(); Task.WaitAll(bus.Stop()); }
public void InMemoryBusEngine_IsCommandHandled_is_true_when_ObserveCommand() { var busEngine = new InMemoryBusEngine(); var builder = new NybusBusBuilder(busEngine); var observable = builder.ObserveCommand <TestCommand>(); busEngine.IsCommandHandled <TestCommand>(); }