示例#1
0
        public void ReadLastNBytes_GetMoreThanPossible()
        {
            var mockedFileStream = new MockedFileStream(new byte[] { 1, 2, 3, 4, 5 });
            var reader = new FileReader(DummyFileName) { myFileStream = mockedFileStream, File = new MockedFile() };

            var last7Bytes = reader.ReadLastNBytes(7);
            Assert.AreEqual(5, last7Bytes.Count(), "Wrong number of returned bytes.");
            Assert.AreEqual(1, last7Bytes[0], "Unexpected result.");
            Assert.AreEqual(5, last7Bytes[4], "Unexpected result.");
        }
示例#2
0
文件: Tail.cs 项目: klapantius/lit
        public void GetNewLines()
        {
            var source = new MockedFileStream(FIRSTLINE);
            var reader = new FileReader("dummyFileName") { myFileStream = source, File = new MockedFile() };

            var tail = new Tail("dummyFileName", Encoding.Default, reader);

            Assert.AreEqual(Encoding.ASCII, tail.myFileType, "Encoding detected wrong.");
            var lines = tail.GetNewLines();
            Assert.AreEqual(1, lines.Count, "Unexpected count of lines read.");
            StringAssert.Matches(lines.First(), firstLineRegex, "Wrong content.");
        }
示例#3
0
        public void ReadNewBytes_ContinuousReadingAfterNewItemsAdded()
        {
            var mockedFileStream = new MockedFileStream(new byte[] { 1, 2, 3, 4, 5 });
            var reader = new FileReader(DummyFileName) { myFileStream = mockedFileStream, File = new MockedFile() };

            var bytes = reader.ReadNewBytes();
            Assert.AreEqual(5, bytes.Length, "Wrong number of returned bytes in the 1st round.");
            Assert.AreEqual(1, bytes[0], "Unexpected result in the 1st round.");
            Assert.AreEqual(5, bytes[4], "Unexpected result in the 1st round.");

            mockedFileStream.AddItems(new byte[] { 7, 8, 9 });
            bytes = reader.ReadNewBytes();
            Assert.AreEqual(3, bytes.Length, "Wrong number of returned bytes in the 2nd round.");
            Assert.AreEqual(7, bytes[0], "Unexpected result in the 2nd round.");
            Assert.AreEqual(8, bytes[1], "Unexpected result in the 2nd round.");
            Assert.AreEqual(9, bytes[2], "Unexpected result in the 2nd round.");
        }
示例#4
0
        public void ReadNewBytes_ReadThrough5ItemsBy2()
        {
            var mockedFileStream = new MockedFileStream(new byte[] { 1, 2, 3, 4, 5 });
            var reader = new FileReader(DummyFileName) { myFileStream = mockedFileStream, File = new MockedFile() };

            var twoBytes = reader.ReadNewBytes(2);
            Assert.AreEqual(2, twoBytes.Count(), "Wrong number of returned bytes.");
            Assert.AreEqual(1, twoBytes[0], "Unexpected result after 1st 2 bytes read.");
            Assert.AreEqual(2, twoBytes[1], "Unexpected result after 1st 2 bytes read.");

            twoBytes = reader.ReadNewBytes(2);
            Assert.AreEqual(2, twoBytes.Count(), "Wrong number of returned bytes.");
            Assert.AreEqual(3, twoBytes[0], "Unexpected result after 2nd 2 bytes read.");
            Assert.AreEqual(4, twoBytes[1], "Unexpected result after 2nd 2 bytes read.");

            twoBytes = reader.ReadNewBytes(2);
            Assert.AreEqual(1, twoBytes.Count(), "Wrong number of returned bytes.");
            Assert.AreEqual(5, twoBytes[0], "Unexpected result after 3rd 2 bytes read.");
        }
示例#5
0
文件: Tail.cs 项目: klapantius/lit
        public void GetNewLines_ContinuousReading()
        {
            var input = new List<string>
            {
                "first line",
                "second line",
                "third line"
            };
            var additionalLines = new List<string>
            {
                "fourth line",
                "fifth line",
                "sixth line",
                "7th line"
            };
            var source = new MockedFileStream(input);
            var reader = new FileReader("dummyFileName") { myFileStream = source, File = new MockedFile() };
            var tail = new Tail("dummyFileName", Encoding.Default, reader);

            var output = tail.GetNewLines();
            Assert.AreEqual(input.Count, output.Count, "Unexpected count of lines at start");
            for (var i = 0; i < input.Count; i++)
            {
                StringAssert.Matches(output[i], new Regex(input[i]), "Unmatching line in the 1st round.");
            }

            source.AddNewLines(additionalLines, Encoding.Default);
            output = tail.GetNewLines();
            Assert.AreEqual(additionalLines.Count, output.Count, "Unexpected count of lines after new lines added.");
            for (var i = 0; i < additionalLines.Count; i++)
            {
                StringAssert.Matches(output[i], new Regex(additionalLines[i]), "Unmatching line in the 2nd round.");
            }
        }