コード例 #1
0
        public async Task Test_MultipleSubscribe()
        {
            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);

            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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task Test_ConnectWithSubscriptionClient()
        {
            Exception thrownException = null;

            var dut = new AsyncRedisSubscriptionClient();

            try
            {
                await dut.Connect(LocalHostDefaultPort.AsConnectionSettings());
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }

            Assert.IsNull(thrownException);
        }
コード例 #4
0
        public async Task TestKnownHostBadPort_ConnectWithSubscriptionClientThrowsException()
        {
            Exception thrownException = null;

            var dut = new AsyncRedisSubscriptionClient();

            try
            {
                await dut.Connect(LocalHostPort7000.AsConnectionSettings());
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsInstanceOfType(thrownException, typeof(SocketException));
        }
コード例 #5
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));
        }
コード例 #6
0
        public async Task TestWrongDbIndex_SelectWithSubscriptionClientThrowsException()
        {
            Exception thrownException = null;
            var       dut             = new AsyncRedisSubscriptionClient();

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

                await dut.Select(int.MaxValue);
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsInstanceOfType(thrownException, typeof(RedisException));
        }
コード例 #7
0
        public async Task TestCallingAfterDispose_SubscriptionClientThrowsException()
        {
            Exception thrownException = null;

            var dut = new AsyncRedisSubscriptionClient();
            await dut.Connect(LocalHostDefaultPort.AsConnectionSettings());

            dut.Dispose();

            try
            {
                await dut.Select(1);
            }
            catch (Exception ex)
            {
                thrownException = ex;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsInstanceOfType(thrownException, typeof(InvalidOperationException));
        }