Ejemplo n.º 1
0
        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.");
        }
Ejemplo n.º 2
0
        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.");
            }
        }