public void TestAutoArchiveNoDirectory() { if (Directory.Exists(archiveBasePath + "\\Archive")) Directory.Delete(archiveBasePath + "\\Archive", true); TradeFinderFactory.ArchiveOutOfDateLogs(archiveBasePath); Assert.IsTrue(Directory.Exists(archiveBasePath + "\\Archive"), "Didn't create the archive directory"); }
public void TestArchiveOutOfDateLogs() { // copy files from Old Logs to the temporary logs dir string[] oldLogs = Directory.GetFiles(testLogPath + "\\Old Logs\\", "*.txt", System.IO.SearchOption.TopDirectoryOnly); foreach (string file in oldLogs) { FileInfo info = new FileInfo(file); info.CopyTo(archiveBasePath + "\\" + info.Name); } // copy files from Special Logs to the temporary logs dir string[] specialLogs = Directory.GetFiles(testLogPath + "\\Special Logs\\", "*.txt", System.IO.SearchOption.TopDirectoryOnly); foreach (string file in specialLogs) { FileInfo info = new FileInfo(file); info.CopyTo(archiveBasePath + "\\" + info.Name); } // copy files from Logs to the temporary logs dir string[] newLogs = Directory.GetFiles(testLogPath, "*.txt", System.IO.SearchOption.TopDirectoryOnly); foreach (string file in newLogs) { FileInfo info = new FileInfo(file); info.CopyTo(archiveBasePath + "\\" + info.Name); } TradeFinderFactory.ArchiveOutOfDateLogs(archiveBasePath); Assert.IsTrue(Directory.Exists(archiveBasePath + "\\Archive"), "Archive directory went missing!"); string[] unarchivedLogs = Directory.GetFiles(archiveBasePath, "*.txt", System.IO.SearchOption.TopDirectoryOnly); // Note: we expect newLogs.Length + 2 because two new item types are in the Old Logs directory Assert.AreEqual(newLogs.Length + 2, unarchivedLogs.Length, "Some of the new logs have gone missing"); string[] archivedLogs = Directory.GetFiles(archiveBasePath + "\\Archive", "*.txt", System.IO.SearchOption.TopDirectoryOnly); for (int i = 0; i < archivedLogs.Length; i++) { archivedLogs[i] = (new FileInfo(archivedLogs[i])).Name; } // Note: we expect oldLogs.Length + 1 because one of the new item types is doubled Assert.AreEqual(oldLogs.Length + 1, archivedLogs.Length); foreach (string log in oldLogs) { Assert.Contains((new FileInfo(log)).Name, archivedLogs); } }