Example #1
0
        public void Parse_ErrorWithInvalidEnd_Throws()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("-foo"));

            var e = Assert.ThrowsException <ProtocolViolationException>(() => buffer.Parse());

            StringAssert.Contains(e.Message, "'1'");
        }
Example #2
0
        public void Parse_WithTwoResponsesInvalidEnd_Throws()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("+foo\r\n+bar\r\n+foo\r\n"));

            var e = Assert.ThrowsException <ProtocolViolationException>(() => buffer.Parse(2));

            StringAssert.Contains(e.Message, "'12'");
        }
Example #3
0
        public void Parse_InvalidStart_Throws()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("|3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n"));

            var e = Assert.ThrowsException <ProtocolViolationException>(() => buffer.Parse());

            StringAssert.Contains(e.Message, "'0'");
        }
Example #4
0
        public void Parse_Error_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("-foo\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(StringResponse));
            Assert.AreEqual(DataType.Error, response.DataType);
            Assert.AreEqual("foo", response.Value);
        }
Example #5
0
        public void Parse_EmptySimpleString_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("+\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(StringResponse));
            Assert.AreEqual(DataType.SimpleString, response.DataType);
            Assert.AreEqual(string.Empty, response.Value);
        }
Example #6
0
        public void Parse_NullArray_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*-1\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);
            Assert.IsNull(response.Value);
        }
Example #7
0
        public void Parse_EmptyArray_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*0\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);
            Assert.AreEqual(0, ((object[])response.Value).Length);
        }
Example #8
0
        public void Parse_MultilineBulkString_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("$8\r\nfoo\r\nbar\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(StringResponse));
            Assert.AreEqual(DataType.BulkString, response.DataType);
            Assert.AreEqual("foo\r\nbar", response.Value);
        }
Example #9
0
        public void Parse_Integer_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes(":34\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(IntegerResponse));
            Assert.AreEqual(DataType.Integer, response.DataType);
            Assert.AreEqual(34L, response.Value);
        }
Example #10
0
        public void Parse_SimpleStringArray_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*1\r\n+foo\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);
            var result = (object[])response.Value;

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("foo", result[0]);
        }
Example #11
0
        public void Parse_NullElementsInArray_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);
            var result = (object[])response.Value;

            Assert.AreEqual(3, result.Length);
            Assert.AreEqual("foo", result[0]);
            Assert.IsNull(result[1]);
            Assert.AreEqual("bar", result[2]);
            Assert.AreEqual(DataType.Array, response.DataType);
        }
Example #12
0
        public void Parse_MixedTypeArray_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*5\r\n:1\r\n:2\r\n:3\r\n:4\r\n$6\r\nfoobar\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);
            var result = (object[])response.Value;

            Assert.AreEqual(5, result.Length);
            Assert.AreEqual(1L, result[0]);
            Assert.AreEqual(2L, result[1]);
            Assert.AreEqual(3L, result[2]);
            Assert.AreEqual(4L, result[3]);
            Assert.AreEqual("foobar", result[4]);
        }
Example #13
0
        public void Parse_ArrayOfArrays_ReadValue()
        {
            var buffer   = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("*2\r\n*3\r\n:1\r\n:2\r\n:3\r\n*2\r\n+Foo\r\n-Bar\r\n"));
            var response = buffer.Parse();

            Assert.IsInstanceOfType(response, typeof(ArrayResponse));
            Assert.AreEqual(DataType.Array, response.DataType);

            var result = (object[])response.Value;

            Assert.AreEqual(2, result.Length);

            var innerResult = (object[])result[0];

            Assert.AreEqual(1L, innerResult[0]);
            Assert.AreEqual(2L, innerResult[1]);
            Assert.AreEqual(3L, innerResult[2]);

            innerResult = (object[])result[1];
            Assert.AreEqual("Foo", innerResult[0]);
            Assert.AreEqual("Bar", innerResult[1]);
        }
Example #14
0
        public void Parse_IncorrectNumberOfResponses_Throw()
        {
            var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes(":100\r\n"));

            Assert.ThrowsException <ProtocolViolationException>(() => buffer.Parse(2));
        }