예제 #1
0
        public void CaptureRightOrder()
        {
            var ignoredLine = "This lines should not be captured";
            var logLines    = new[] { "first line", "second line", "thrid line" };

            File.WriteAllLines(_filePath, new[] { ignoredLine });

            using var captureLog = new CaptureLog(_capturePath, _filePath, false);

            captureLog.StartCapture();
            File.WriteAllLines(_filePath, logLines);
            captureLog.StopCapture();

            // get the stream and assert we do have the correct lines
            using var captureStream = captureLog.GetReader();
            string logLine;

            while ((logLine = captureStream.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(logLine))
                {
                    Assert.Contains(logLine, logLines);
                }
            }
        }
예제 #2
0
    public void CapturePieceByPiece()
    {
        var ignoredLine = "This line should not be captured";
        var logLines    = new[] { "first line", "second line", "third line" };

        File.WriteAllLines(_sourcePath, new[] { ignoredLine });

        using var captureLog = new CaptureLog(_destinationPath, _sourcePath, false);
        captureLog.StartCapture();

        File.AppendAllLines(_destinationPath, logLines.Take(1));
        captureLog.Flush();
        Assert.Contains(logLines.First(), File.ReadAllText(_destinationPath));

        File.AppendAllLines(_destinationPath, logLines.Skip(1));

        captureLog.StopCapture();

        // Get the stream and assert we do have the correct lines
        using var captureStream = captureLog.GetReader();
        string logLine;

        while ((logLine = captureStream.ReadLine()) != null)
        {
            Assert.NotEqual(ignoredLine, logLine);

            if (!string.IsNullOrEmpty(logLine))
            {
                Assert.Contains(logLine, logLines);
            }
        }
    }
예제 #3
0
        public void CaptureRightOrder()
        {
            var ignoredLine = "This lines should not be captured";
            var logLines    = new[] { "first line", "second line", "thrid line" };

            using (var stream = File.Create(_filePath))
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine(ignoredLine);
                }
            using (var captureLog = new CaptureLog(_capturePath, _filePath, false))
            {
                captureLog.StartCapture();
                using (var writer = new StreamWriter(_filePath))
                {
                    foreach (var line in logLines)
                    {
                        writer.WriteLine(line);
                    }
                }
                captureLog.StopCapture();
                // get the stream and assert we do have the correct lines
                using (var captureStream = captureLog.GetReader())
                {
                    string line;
                    while ((line = captureStream.ReadLine()) != null)
                    {
                        Assert.Contains(line, logLines);
                    }
                }
            }
        }
예제 #4
0
    public void CaptureEverythingAtOnce()
    {
        var logLines = new[] { "first line", "second line", "third line" };

        File.WriteAllText(_sourcePath, string.Empty);

        using var captureLog = new CaptureLog(_destinationPath, _sourcePath, false);

        captureLog.StartCapture();
        File.AppendAllLines(_sourcePath, logLines);
        captureLog.StopCapture();

        // get the stream and assert we do have the correct lines
        using var captureStream = captureLog.GetReader();
        string logLine;

        while ((logLine = captureStream.ReadLine()) != null)
        {
            if (!string.IsNullOrEmpty(logLine))
            {
                Assert.Contains(logLine, logLines);
            }
        }
    }