Ejemplo n.º 1
0
        public void SubscribeToOneChannel()
        {
            string channel = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel);

            Assert.AreEqual(1, this.Subscription.ActiveChannels.Count());
            Assert.IsTrue(this.Subscription.ActiveChannels.Contains(channel));
        }
Ejemplo n.º 2
0
        public void UnsubscribeFromOneChannel()
        {
            string channel = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel);

            Assert.IsTrue(this.Subscription.UnsubscribeFromChannels(this.subscribeTimeout, channel));

            Assert.IsFalse(this.Subscription.ActiveChannels.Contains(channel));
        }
Ejemplo n.º 3
0
        public void UnsubscribeFromTwoChannels()
        {
            string channel1 = RedisSubscriptionUnitTests.GetUniqueTestChannel();
            string channel2 = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel1, channel2);

            Assert.IsTrue(this.Subscription.UnsubscribeFromChannels(this.subscribeTimeout, channel1, channel2));

            Assert.AreEqual(0, this.Subscription.ActiveChannels.Count());
        }
Ejemplo n.º 4
0
        public void DoNotReceiveMessageIfNotSubscribedForChannel()
        {
            string channel1 = RedisSubscriptionUnitTests.GetUniqueTestChannel();
            string channel2 = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(TimeSpan.FromSeconds(1), channel1);

            Helpers.WaitForEvent <RedisMessageEventArgs>(
                TimeSpan.FromSeconds(1),
                handler => this.Subscription.MessageReceived += handler,
                () => this.PublishMessage(channel2, "Hello"));
        }
Ejemplo n.º 5
0
        public void DoNotReceiveMessageAfterUnsubscribeFromChannel()
        {
            string channel = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel);

            Assert.IsTrue(this.Subscription.UnsubscribeFromChannels(this.subscribeTimeout, channel));

            Helpers.WaitForEvent <RedisMessageEventArgs>(
                TimeSpan.FromSeconds(1),
                handler => this.Subscription.MessageReceived += handler,
                () => this.PublishMessage(channel, "Hello"));
        }
Ejemplo n.º 6
0
        public void ReceiveMessageForSubscribedChannel()
        {
            string channel1 = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel1);

            Assert.AreEqual(1, this.Subscription.ActiveChannels.Count());

            Assert.IsTrue(this.Subscription.ActiveChannels.Contains(channel1));

            RedisMessageEventArgs args = Helpers.WaitForEvent <RedisMessageEventArgs>(
                TimeSpan.FromSeconds(1),
                handler => this.Subscription.MessageReceived += handler,
                () => this.PublishMessage(channel1, "Hello"));

            Assert.AreEqual(channel1, args.Channel);
            Assert.AreEqual("Hello", args.Message);
        }
Ejemplo n.º 7
0
        public void SubscribeToChannelsTimeout()
        {
            string channel = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(TimeSpan.FromTicks(1), channel);
        }