Esempio 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));
        }
Esempio 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));
        }
Esempio 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());
        }
Esempio 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"));
        }
Esempio 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"));
        }
Esempio 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);
        }
Esempio n. 7
0
        public void SubscribeToChannelsTimeout()
        {
            string channel = RedisSubscriptionUnitTests.GetUniqueTestChannel();

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