Ejemplo n.º 1
0
        public void ShouldParseTheNextLineAsNumberOfBytesToRead()
        {
            var redisRequest = new ClientRequest(null);

            redisRequest.AddData("*4\r\n");
            redisRequest.AddData("$36\r");
            redisRequest.AddData("\nPIN");

            Assert.That(redisRequest.NumberOfCommands, Is.EqualTo(4));
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(35));
            Assert.That(redisRequest.IsComplete(), Is.False);
        }
Ejemplo n.º 2
0
        public void ShouldCompleteWhenAllCommandsAreRead()
        {
            var redisRequest = new ClientRequest(null);
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("*4\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("$6\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(8));

            redisRequest.AddData("LRANGE\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("$10\r");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("\nABC");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(9));

            redisRequest.AddData("DEFGHIJ\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("$1\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(3));

            redisRequest.AddData("0\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("$2\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));

            redisRequest.AddData("20\r\n");
            Assert.That(redisRequest.IsComplete(), Is.True);
            Assert.That(redisRequest.Command, Is.EqualTo("LRANGE"));
            Assert.That(redisRequest.Args.Count, Is.EqualTo(3));
            Assert.That(redisRequest.Args[0], Is.EqualTo("ABCDEFGHIJ"));
            Assert.That(redisRequest.Args[1], Is.EqualTo("0"));
            Assert.That(redisRequest.Args[2], Is.EqualTo("20"));
        }
Ejemplo n.º 3
0
        public void ShouldReadCommandTextLineAndSetupToReadNextCommandLength()
        {
            var redisRequest = new ClientRequest(null);

            redisRequest.AddData("*4\r\n");
            redisRequest.AddData("$5\r\n");
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(7));

            redisRequest.AddData("LPUSH\r\n");
            Assert.That(redisRequest.IsComplete(), Is.False);
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));
            Assert.That(redisRequest.Command, Is.EqualTo("LPUSH"));
            Assert.That(redisRequest.Args, Is.Empty);
        }
Ejemplo n.º 4
0
        public void ShouldReadFirstRequestLineTillCrLfAsNumberOfLinesInTheCommand()
        {
            var redisRequest = new ClientRequest(null);

            redisRequest.AddData("*42\r");
            Assert.That(redisRequest.NumberOfCommands, Is.EqualTo(0));
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));
            Assert.That(redisRequest.IsComplete(), Is.False);

            redisRequest.AddData("\n$36");
            Assert.That(redisRequest.NumberOfCommands, Is.EqualTo(42));
            Assert.That(redisRequest.NumberOfBytesToRead, Is.EqualTo(4));
            Assert.That(redisRequest.IsComplete(), Is.False);
        }