public void CountBadPath() { var fc = new LineCounter(); var model = new FileEvent(FileEventType.Create, new FileEntry("r:\\no way that this file is really there.txt")); LineCountProgress result = fc.Count(model); Assert.AreEqual(result.Status, LineCountStatus.FileNotFound); }
public void CountZeroLengthFile() { const string Test_0 = "Test_0.txt"; if (!File.Exists(Test_0)) { var ff = new FileFiller(); ff.FillFile(Test_0, 0, -2); } var fc = new LineCounter(); var model = new FileEvent(FileEventType.Create, new FileEntry(Test_0)); LineCountProgress result = fc.Count(model); Assert.AreEqual(result.Status, LineCountStatus.Success); Assert.AreEqual(0, result.Count); }
public void CountLockedFile() { const string Test_Locked = "Test_Locked.txt"; if (!File.Exists(Test_Locked)) { var ff = new FileFiller(); ff.FillFile(Test_Locked, 10, -2); } var x = Task.Run(() => LockFile(Test_Locked, seconds: 30)); Thread.Sleep(1000); // give it time to open and lock the file var fc = new LineCounter(); var model = new FileEvent(FileEventType.Create, new FileEntry(Test_Locked)); LineCountProgress result = fc.Count(model); Assert.AreEqual(result.Status, LineCountStatus.TimedOut); x.Wait(); }
/// <summary> /// Starts the task and writes the results to the standard output stream. /// </summary> public void Run() { if (parameters.ShowLogo) { WriteLogo(); } if (parameters.ShowHelp) { WriteHelp(); } else if (parameters.FileSet.FileCount == 0) // If there is no file to analyse { System.Console.Error.WriteLine("Error: No input files were specified.\n"); WriteHelp(); } else { int fileCount = parameters.FileSet.FileCount; if (fileCount == 1) { System.Console.WriteLine("1 file is being parsed.\n"); } else { System.Console.WriteLine("{0} files are being parsed.\n", fileCount); } try { LineCounter counter = new LineCounter(parameters.FileSet); counter.Count(); CreateXmlReportFile(); ShowResults(); } catch (InvalidFileException ex) { System.Console.Error.WriteLine("Error: " + ex.Message); } } }