Example #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);
        }
Example #2
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()));
        }
Example #3
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()));
        }