예제 #1
0
        public async Task Test_Unsubscribe()
        {
            var dutPublisher  = new AsyncRedisClient();
            var dutSubscriber = new AsyncRedisSubscriptionClient();

            await dutPublisher.Connect(LocalHostDefaultPort.AsConnectionSettings());

            await dutSubscriber.Connect(LocalHostDefaultPort.AsConnectionSettings());

            string receivedChannel = null;
            string receivedMessage = null;

            dutSubscriber.OnMessageReceived += (ch, msg) =>
            {
                receivedChannel = ch;
                receivedMessage = msg;
            };

            await dutSubscriber.Subscribe(Channel);

            await dutPublisher.Publish(Channel, Message);

            Thread.Sleep(100);

            await dutSubscriber.Unsubscribe(Channel);

            await dutPublisher.Publish(Channel, SecondMessage);

            Thread.Sleep(100);

            Assert.AreEqual(Channel, receivedChannel);
            Assert.AreEqual(Message, receivedMessage);
        }
예제 #2
0
        public async Task TestNotSubscribed_UnsubscribeThrowsException()
        {
            Exception thrownException = null;
            var       dut             = new AsyncRedisSubscriptionClient();

            try
            {
                await dut.Connect(LocalHostDefaultPort.AsConnectionSettings());

                await dut.Unsubscribe("channel");
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsInstanceOfType(thrownException, typeof(InvalidOperationException));
        }
예제 #3
0
        public async Task Test_MultipleUnsubscribe()
        {
            var dutPublisher  = new AsyncRedisClient();
            var dutSubscriber = new AsyncRedisSubscriptionClient();

            await dutPublisher.Connect(LocalHostDefaultPort.AsConnectionSettings());

            await dutSubscriber.Connect(LocalHostDefaultPort.AsConnectionSettings());

            var received = new List <Tuple <string, string> >();

            dutSubscriber.OnMessageReceived += (ch, msg) =>
            {
                received.Add(Tuple.Create(ch, msg));
            };

            await dutSubscriber.Subscribe(new[] { Channel, OtherChannel });

            await dutPublisher.Publish(Channel, Message);

            Thread.Sleep(100);

            await dutPublisher.Publish(OtherChannel, OtherMessage);

            Thread.Sleep(100);

            await dutSubscriber.Unsubscribe(new[] { Channel, OtherChannel });

            await dutPublisher.Publish(Channel, SecondMessage);

            Thread.Sleep(100);

            await dutPublisher.Publish(OtherChannel, SecondMessage);

            Thread.Sleep(100);

            Assert.AreEqual(2, received.Count);
            Assert.AreEqual(Channel, received[0].Item1);
            Assert.AreEqual(Message, received[0].Item2);
            Assert.AreEqual(OtherChannel, received[1].Item1);
            Assert.AreEqual(OtherMessage, received[1].Item2);
        }