예제 #1
0
        public async Task MultipleMessageReadTest()
        {
            SetupStream("+OK\r\n+Test\r\n:100\r\n*3\r\n:1\r\n:2\r\n:3\r\n$6\r\nfoobar\r\n-Error message\r\n");

            IRedisType result = await ReadAsync <RedisString>();

            Assert.Equal(new RedisString("OK"), result);

            result = await ReadAsync <RedisString>();

            Assert.Equal(new RedisString("Test"), result);

            result = await ReadAsync <RedisInteger>();

            Assert.Equal(new RedisInteger(100), result);

            result = await ReadAsync <RedisArray>();

            Assert.Equal(new RedisArray(new RedisInteger(1), new RedisInteger(2), new RedisInteger(3)), result);

            result = await ReadAsync <RedisBulkString>();

            Assert.Equal(RedisBulkString.FromString("foobar"), result);

            result = await ReadAsync <RedisErorr>();

            Assert.Equal(new RedisErorr("Error message"), result);
        }
예제 #2
0
        public void BulkStringsWithSameContentHaveSameHashCode()
        {
            var string1 = RedisBulkString.FromString("test");
            var string2 = RedisBulkString.FromString("test");

            Assert.Equal(string1.GetHashCode(), string2.GetHashCode());
        }
예제 #3
0
        public async Task ReadBulkStringArrayTest()
        {
            SetupStream("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n");

            var result = await ReadAsync <RedisArray>();

            Assert.Equal(new RedisArray(RedisBulkString.FromString("foo"), RedisBulkString.FromString("bar")), result);
        }
예제 #4
0
        public async Task ReadBulkStringTest()
        {
            SetupStream("$6\r\nfoobar\r\n");

            var result = await ReadAsync <RedisBulkString>();

            Assert.Equal(RedisBulkString.FromString("foobar"), result);
        }
예제 #5
0
        public async Task ReadEmptyBulkStringTest()
        {
            SetupStream("$0\r\n\r\n");

            var result = await ReadAsync <RedisBulkString>();

            Assert.Equal(RedisBulkString.FromString(""), result);
        }
예제 #6
0
        public async Task ReadArrayWithNullElementTest()
        {
            SetupStream("*3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n");

            var result = await ReadAsync <RedisArray>();

            Assert.Equal(new RedisArray(RedisBulkString.FromString("foo"), RedisBulkString.Null, RedisBulkString.FromString("bar")), result);
        }
예제 #7
0
        public void BulkStringsWithDifferentContentAreNotEqual()
        {
            var string1 = RedisBulkString.FromString("test1");
            var string2 = RedisBulkString.FromString("test2");

            Assert.False(string1.Equals(string2));
            Assert.False(string2.Equals(string1));

            Assert.True(string1 != string2);
            Assert.True(string2 != string1);
        }
예제 #8
0
        public void BulkStringsWithSameContentAreEqual()
        {
            var string1 = RedisBulkString.FromString("test");
            var string2 = RedisBulkString.FromString("test");

            Assert.True(string1.Equals(string2));
            Assert.True(string2.Equals(string1));

            Assert.True(string1 == string2);
            Assert.True(string2 == string1);
        }
예제 #9
0
            public WhenDisconnecting()
            {
                _clientFactory = new Mock <IClientFactory>();
                _client        = new Mock <IClient>();
                _client.Setup(s => s.SendAsync(new RedisArray(RedisBulkString.FromString("PING", Encoding.ASCII)), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new RedisString("PONG"));
                _client.Setup(s => s.SendAsync(new RedisArray(RedisBulkString.FromString("QUIT", Encoding.ASCII)), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new RedisString("OK"));

                _clientFactory.SetReturnsDefault(Task.FromResult(_client.Object));

                var connection = new BasicConnection(new IPEndPoint(IPAddress.Loopback, 6379), _clientFactory.Object);

                connection.OpenAsync(CancellationToken.None).Wait();

                _client.ResetCalls();

                connection.DisconnectAsync(CancellationToken.None).Wait();
            }
예제 #10
0
 public IRedisType Build()
 {
     return(new RedisArray(new[] { RedisBulkString.FromString(_command) }.Concat(_args).ToArray()));
 }
예제 #11
0
 public CommandBuilder WithArg(string arg)
 {
     _args.Add(RedisBulkString.FromString(arg));
     return(this);
 }
예제 #12
0
        public void BulkStringsAreNotEqualToNull()
        {
            var s = RedisBulkString.FromString("test");

            Assert.False(s.Equals(null));
        }
예제 #13
0
        public void BulkStringsAreEqualToItself()
        {
            var s = RedisBulkString.FromString("test");

            Assert.True(s.Equals(s));
        }
예제 #14
0
        public void ToStringIsCorrect()
        {
            var s = RedisBulkString.FromString("test");

            Assert.Equal("0x74657374", s.ToString());
        }
예제 #15
0
        public void NonEmptyBulkStringLegnthIsCorrect()
        {
            var s = RedisBulkString.FromString("test");

            Assert.Equal(4, s.Length);
        }
예제 #16
0
        public void ValueIsCorrect()
        {
            var s = RedisBulkString.FromString("test");

            Assert.Equal(new byte[] { 0x74, 0x65, 0x73, 0x74 }, s.Value);
        }
예제 #17
0
        public async Task WriteMixedArrayTest()
        {
            var result = await WriteAsync(new RedisArray(new RedisInteger(1), new RedisInteger(2), new RedisInteger(3), new RedisInteger(4), RedisBulkString.FromString("foobar")));

            Assert.Equal("*5\r\n:1\r\n:2\r\n:3\r\n:4\r\n$6\r\nfoobar\r\n", result);
        }
예제 #18
0
        public async Task WriteArrayWithNullElementTest()
        {
            var result = await WriteAsync(new RedisArray(RedisBulkString.FromString("foo"), RedisBulkString.Null, RedisBulkString.FromString("bar")));

            Assert.Equal("*3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n", result);
        }
예제 #19
0
        public async Task WriteBulkStringTest()
        {
            var result = await WriteAsync(RedisBulkString.FromString("foobar"));

            Assert.Equal("$6\r\nfoobar\r\n", result);
        }
예제 #20
0
        public async Task ReadMixedArrayTest()
        {
            SetupStream("*5\r\n:1\r\n:2\r\n:3\r\n:4\r\n$6\r\nfoobar\r\n");

            var result = await ReadAsync <RedisArray>();

            Assert.Equal(new RedisArray(new RedisInteger(1), new RedisInteger(2), new RedisInteger(3), new RedisInteger(4), RedisBulkString.FromString("foobar")), result);
        }
예제 #21
0
 public void ThenAQuitMessageIsSent()
 {
     _client.Verify(s => s.SendAsync(It.Is <IRedisType>(dt => dt.RedisType == RedisType.Array &&
                                                        (dt as RedisArray).Cast <RedisBulkString>().First() == RedisBulkString.FromString("QUIT", Encoding.ASCII)),
                                     CancellationToken.None));
 }
예제 #22
0
        public async Task WriteBulkStringArrayTest()
        {
            var result = await WriteAsync(new RedisArray(RedisBulkString.FromString("foo"), RedisBulkString.FromString("bar")));

            Assert.Equal("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n", result);
        }