コード例 #1
0
        public void ReadTwice()
        {
            SystemPath          filename = tempDir.CreateEmptyFile("Twice.Log");
            ServerLogFileReader reader   = new ServerLogFileReader(filename.ToString(), 10);
            String first  = reader.Read();
            String second = reader.Read();

            Assert.AreEqual(first, second, "Error reading file twice with same reader");
        }
コード例 #2
0
        public void ReadOutputFromSpecifiedProject()
        {
            string     content  = @"2006-11-24 20:09:52,000 [CCNet Server:INFO] Starting CruiseControl.NET Server
2006-11-24 20:09:53,000 [foo:INFO] Starting integrator for project: foo
2006-11-24 20:09:54,000 [bar:INFO] Starting integrator for project: bar
2006-11-24 20:09:55,000 [foo:INFO] No modifications detected
2006-11-24 20:09:56,000 [bar:INFO] No modifications detected.";
            SystemPath tempFile = tempDir.CreateTextFile("MultiProject.log", content);

            ServerLogFileReader reader = new ServerLogFileReader(tempFile.ToString(), 10);

            Assert.AreEqual(@"2006-11-24 20:09:53,000 [foo:INFO] Starting integrator for project: foo
2006-11-24 20:09:55,000 [foo:INFO] No modifications detected", reader.Read("foo"));
            Assert.AreEqual(@"2006-11-24 20:09:54,000 [bar:INFO] Starting integrator for project: bar
2006-11-24 20:09:56,000 [bar:INFO] No modifications detected.", reader.Read("bar"));
        }
コード例 #3
0
        public void ReadUnknownFile()
        {
            ServerLogFileReader reader = new ServerLogFileReader("BogusFileName", 10);

            Assert.That(delegate { reader.Read(); },
                        Throws.TypeOf <FileNotFoundException>());
        }
コード例 #4
0
        public void ReadEmptyFile()
        {
            SystemPath          filename = tempDir.CreateEmptyFile("ReadEmptyFile.log");
            ServerLogFileReader reader   = new ServerLogFileReader(filename.ToString(), 10);

            Assert.AreEqual("", reader.Read(), "Error reading empty log file");
        }
コード例 #5
0
        public void ReadSingleLineFromLogFile()
        {
            string              content  = @"SampleLine";
            SystemPath          filename = tempDir.CreateTextFile("ReadSingleLineFromLogFile.log", content);
            ServerLogFileReader reader   = new ServerLogFileReader(filename.ToString(), 10);

            Assert.AreEqual(content, reader.Read());
        }
コード例 #6
0
        public void ReadFromLockedLogFile()
        {
            SystemPath tempFile = tempDir.CreateEmptyFile("LockedFilename.log");

            using (StreamWriter stream = File.CreateText(tempFile.ToString()))
            {
                stream.Write("foo");
                stream.Write("bar");
                stream.Flush();

                ServerLogFileReader reader = new ServerLogFileReader(tempFile.ToString(), 10);
                Assert.AreEqual("foobar", reader.Read());
            }
        }
コード例 #7
0
        public void ReadExactInFile()
        {
            const int numLines = 10;

            string[]   contentLines = GenerateContentLines(numLines);
            SystemPath filename     = tempDir.CreateTextFile("ReadExactInFile.log", LinesToString(contentLines));

            ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), numLines);

            String[] readLines = StringToLines(reader.Read());

            // All of file should be read
            Assert.AreEqual(numLines, readLines.Length);
            for (int i = 0; i < readLines.Length; i++)
            {
                Assert.AreEqual(contentLines[i], readLines[i]);
            }
        }
コード例 #8
0
        public void ReadLessThanInFile()
        {
            const int numFileLines = 15;

            string[]   contentLines = GenerateContentLines(numFileLines);
            SystemPath filename     = tempDir.CreateTextFile("ReadLessThanInFile.log", LinesToString(contentLines));

            const int           numReadLines = 10;
            ServerLogFileReader reader       = new ServerLogFileReader(filename.ToString(), numReadLines);

            String[] readLines = StringToLines(reader.Read());

            Assert.AreEqual(numReadLines, readLines.Length);
            for (int i = 0; i < readLines.Length; i++)
            {
                Assert.AreEqual(contentLines[numFileLines - numReadLines + i], readLines[i]);
            }
        }