public void ReadLine_OverflowsBuffer_ThrowsException()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("12345");
            socket.AddResponse("67890");
            socket.AddResponse("\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();
        }
        public void ReadLine_OverflowsBuffer_ThrowsException()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("12345");
            socket.AddResponse("67890");
            socket.AddResponse("\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();
        }
        public void ReadLine_FillBuffer()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("123456789\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();

            Assert.AreEqual("123456789\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_FillBuffer()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("123456789\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();

            Assert.AreEqual("123456789\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_OneLineInMultiplePieces()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("te");
            socket.AddResponse("st\n");
            var reader = new BufferedLineReader(socket.Receive, 20);

            string result = reader.ReadLine();

            Assert.AreEqual("test\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_OneLineInMultiplePieces()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("te");
            socket.AddResponse("st\n");
            var reader = new BufferedLineReader(socket.Receive, 20);

            string result = reader.ReadLine();

            Assert.AreEqual("test\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_ToTheEndOfTheBuffer()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("TEST\ntest");
            socket.AddResponse("\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();

            Assert.AreEqual("TEST\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_WrapAround()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("test\n1");
            socket.AddResponse("23");
            socket.AddResponse("45");
            socket.AddResponse("678\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();

            Assert.AreEqual("test\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("12345678\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_ReceiveMultipleLinesAtOnce()
        {
            MockSocket socket = new MockSocket();

            socket.AddResponse("test1\ntest2\ntest3\n");
            var reader = new BufferedLineReader(socket.Receive, 20);

            string result = reader.ReadLine();

            Assert.AreEqual("test1\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test2\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test3\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_WrapAround2()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("test\n1");
            socket.AddResponse("2\n34");
            socket.AddResponse("56\n");

            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();
            Assert.AreEqual("test\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("12\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("3456\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_ToTheEndOfTheBuffer()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("TEST\ntest");
            socket.AddResponse("\n");
            var reader = new BufferedLineReader(socket.Receive, 10);

            string result = reader.ReadLine();
            Assert.AreEqual("TEST\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }
        public void ReadLine_ReceiveMultipleLinesAtOnce()
        {
            MockSocket socket = new MockSocket();
            socket.AddResponse("test1\ntest2\ntest3\n");
            var reader = new BufferedLineReader(socket.Receive, 20);

            string result = reader.ReadLine();
            Assert.AreEqual("test1\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test2\n", result);
            Assert.IsFalse(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);

            result = reader.ReadLine();
            Assert.AreEqual("test3\n", result);
            Assert.IsTrue(reader.IsEmpty);
            Assert.IsFalse(reader.IsFull);
        }