public void Events_are_pushed_into_observable()
        {
            var busEngine = new InMemoryBusEngine();
            var builder   = new NybusBusBuilder(busEngine);

            var list = new List <TestEvent>();

            var disposable = builder.ObserveEvent <TestEvent>().Select(c => c.Message).Subscribe(list.Add);

            var observable = scheduler.CreateHotObservable(
                OnNext(500, fixture.Create <EventMessage <TestEvent> >()),
                OnNext(600, fixture.Create <EventMessage <TestEvent> >()),
                OnNext(1000, fixture.Create <EventMessage <TestEvent> >()),
                OnNext(1200, fixture.Create <EventMessage <TestEvent> >()),
                OnNext(1500, fixture.Create <EventMessage <TestEvent> >())
                );

            var results = scheduler.Start(() => observable.Do(msg => Task.WaitAll(busEngine.HandleEvent(msg))).Select(c => c.Event), 100, 150, 3000);

            disposable.Dispose();

            for (int i = 0; i < list.Count; i++)
            {
                Assert.That(list[i], Is.SameAs(results.Messages[i].Value.Value));
            }
        }
Beispiel #2
0
        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_IsEventHandled_is_true_when_ObserveEvent()
        {
            var busEngine = new InMemoryBusEngine();
            var builder   = new NybusBusBuilder(busEngine);

            var observable = builder.ObserveEvent <TestEvent>();

            busEngine.IsEventHandeld <TestEvent>();
        }