Esempio n. 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);
        }
Esempio n. 2
0
        public void BulkStringsWithSameContentHaveSameHashCode()
        {
            var string1 = RedisBulkString.FromString("test");
            var string2 = RedisBulkString.FromString("test");

            Assert.Equal(string1.GetHashCode(), string2.GetHashCode());
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public async Task ReadBulkStringTest()
        {
            SetupStream("$6\r\nfoobar\r\n");

            var result = await ReadAsync <RedisBulkString>();

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

            var result = await ReadAsync <RedisBulkString>();

            Assert.Equal(RedisBulkString.FromString(""), result);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
            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();
            }
Esempio n. 10
0
 public IRedisType Build()
 {
     return(new RedisArray(new[] { RedisBulkString.FromString(_command) }.Concat(_args).ToArray()));
 }
Esempio n. 11
0
 public CommandBuilder WithArg(string arg)
 {
     _args.Add(RedisBulkString.FromString(arg));
     return(this);
 }
Esempio n. 12
0
        public void BulkStringsAreNotEqualToNull()
        {
            var s = RedisBulkString.FromString("test");

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

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

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

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

            Assert.Equal(new byte[] { 0x74, 0x65, 0x73, 0x74 }, s.Value);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 19
0
        public async Task WriteBulkStringTest()
        {
            var result = await WriteAsync(RedisBulkString.FromString("foobar"));

            Assert.Equal("$6\r\nfoobar\r\n", result);
        }
Esempio n. 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);
        }
 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));
 }
Esempio n. 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);
        }