public void ZipArchiveAddFiles() { // arrange MyZipArchive zipArchive = Factory.CreateZipArchive(Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip")); MyFolder folder = Factory.CreateFolder(Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()))); string content = "S);PFE_NWaf9fAk"; MyFile file1 = Factory.CreateFile(folder.FullPath + "\\document.doc"); file1.FileAppendAllText(content); MyFile file2 = Factory.CreateFile(folder.FullPath + "\\documentx.docx"); file2.FileAppendAllText(content); MyFile file3 = Factory.CreateFile(folder.FullPath + "\\document.html"); file3.FileAppendAllText(content); MyFile file4 = Factory.CreateFile(folder.FullPath + "\\document.dot"); file4.FileAppendAllText(content); MyFile file5 = Factory.CreateFile(folder.FullPath + "\\page.doc"); file5.FileAppendAllText(content); MyFile file6 = Factory.CreateFile(folder.FullPath + "\\image.jpg"); file6.FileAppendAllText(content); HashSet <string> paths = new HashSet <string>(); paths.Add(file1.Name); paths.Add(file2.Name); paths.Add(file3.Name); paths.Add(file4.Name); paths.Add(file5.Name); paths.Add(file6.Name); // act folder.CopyToDirectory(zipArchive); var dirs = zipArchive.DirectoryGetFolders; if (dirs.Count != 1) { Assert.Fail("There is " + dirs.Count + " folders. Expected 1."); } var files = dirs[0].DirectoryGetFiles; if (files.Count != 6) { Assert.Fail("There is " + files.Count + " files in " + dirs[0].FullPath + ". Expected 6."); } foreach (var file in files) { if (!paths.Contains(file.Name)) { Assert.Fail(dirs[0].FullPath + "does not contain " + file.Name + "."); } else { paths.Remove(file.Name); } } // удаляем используемые entry folder.Delete(); zipArchive.Delete(); // assert Assert.IsTrue(paths.Count == 0); }
public void FindingByName() { // arrange MyFolder folder = Factory.CreateFolder(Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()))); MyFile file1 = Factory.CreateFile(folder.FullPath + "\\document.doc"); MyFile file2 = Factory.CreateFile(folder.FullPath + "\\documentx.docx"); MyFile file3 = Factory.CreateFile(folder.FullPath + "\\document.html"); MyFile file4 = Factory.CreateFile(folder.FullPath + "\\document.dot"); MyFile file5 = Factory.CreateFile(folder.FullPath + "\\page.doc"); MyFile file6 = Factory.CreateFile(folder.FullPath + "\\image.jpg"); HashSet <Entry> expectedFiles = new HashSet <Entry>(); expectedFiles.Add(file1); expectedFiles.Add(file2); expectedFiles.Add(file4); expectedFiles.Add(file5); string mask = "*.do*"; //ищем .doc и .dot bool isDone = false; bool isError = false; FindResultsViewer find = new FindResultsViewer(folder, mask, (item) => { if (!expectedFiles.Contains(item)) { isError = true; } else { expectedFiles.Remove(item); } }, () => { }, () => { isDone = true; }); // act while (!isDone) { } folder.Delete(); // assert Assert.IsTrue(expectedFiles.Count == 0 && !isError); }