Esempio n. 1
0
        public void Should_return_false_if_there_are_no_subscribers()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            UserUpdate update = new UserUpdate();

            var result = channel.Publish(update);

            Assert.IsFalse(result);
        }
Esempio n. 2
0
        public void Should_return_false_if_there_are_no_subscribers()
        {
            Fiber fiber = new SynchronousFiber();

            Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new Channel<UserUpdate>[] {});

            var update = new UserUpdate();

            channel.Send(update);

            // exception here? or just ignore
        }
Esempio n. 3
0
        public void Should_filter_out_unwanted_messages()
        {
            var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            Fiber fiber = new SynchronousFiber();

            var future = new Future<UserUpdate>();

            var filter = new FilterChannel<UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now);

            Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new[] {filter});

            channel.Send(update);

            Assert.IsFalse(future.WaitUntilCompleted(1.Seconds()));
        }
Esempio n. 4
0
        public void Should_filter_out_unwanted_messages()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            UserUpdate update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            CommandQueue queue = new SynchronousCommandQueue();

            var future = new Future<UserUpdate>();

            channel.Subscribe(queue, future.Complete, message => message.LastActivity > DateTime.Now);

            var result = channel.Publish(update);
            Assert.IsTrue(result);

            Assert.IsFalse(future.IsAvailable(1.Seconds()));
        }
Esempio n. 5
0
        public void Should_schedule_events()
        {
            var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            Fiber fiber = new SynchronousFiber();

            var future = new Future<UserUpdate>();

            Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new Channel<UserUpdate>[] {future});

            var scheduler = new TimerFiberScheduler(fiber);

            scheduler.Schedule(1000, fiber, () => channel.Send(update));

            Thread.Sleep(500);

            Assert.IsFalse(future.WaitUntilCompleted(0.Seconds()));

            Assert.IsTrue(future.WaitUntilCompleted(1.Seconds()));
        }
Esempio n. 6
0
        public void Should_schedule_events()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            CommandQueue queue = new SynchronousCommandQueue();

            var scheduler = new ThreadPoolScheduler();

            var future = new Future<UserUpdate>();

            channel.Subscribe(queue, future.Complete);

            scheduler.Schedule(1000, () => channel.Publish(update));

            Thread.Sleep(500);

            Assert.IsFalse(future.IsAvailable(0.Seconds()));

            Assert.IsTrue(future.IsAvailable(1.Seconds()));
        }