public void CabInfoCompressExtract() { int fileCount = 10, fileSize = 1024; string dirA = String.Format("{0}-{1}-A", fileCount, fileSize); if (Directory.Exists(dirA)) Directory.Delete(dirA, true); Directory.CreateDirectory(dirA); Directory.CreateDirectory(Path.Combine(dirA, "sub")); string dirB = String.Format("{0}-{1}-B", fileCount, fileSize); if (Directory.Exists(dirB)) Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); string[] files = new string[fileCount]; for (int iFile = 0; iFile < fileCount; iFile++) { files[iFile] = "€" + iFile + ".txt"; CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize); } CompressionTestUtil.GenerateRandomFile(Path.Combine(Path.Combine(dirA, "sub"), "€-.txt"), fileCount + 1, fileSize); CabInfo cabInfo = new CabInfo("test.cab"); cabInfo.Pack(dirA); cabInfo.Unpack(dirB); bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsFalse(directoryMatch, "Testing whether cabinet output directory matches input directory."); Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); cabInfo.Pack(dirA, true, CompressionLevel.Normal, null); cabInfo.Unpack(dirB); directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsTrue(directoryMatch, "Testing whether cabinet output directory matches input directory."); Directory.Delete(dirB, true); Directory.Delete(Path.Combine(dirA, "sub"), true); Directory.CreateDirectory(dirB); cabInfo.Delete(); cabInfo.PackFiles(dirA, files, null); cabInfo.UnpackFiles(files, dirB, null); directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsTrue(directoryMatch, "Testing whether cabinet output directory matches input directory."); Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); cabInfo.Delete(); IDictionary<string, string> testMap = new Dictionary<string, string>(files.Length); for (int iFile = 0; iFile < fileCount; iFile++) { testMap[files[iFile] + ".key"] = files[iFile]; } cabInfo.PackFileSet(dirA, testMap); cabInfo.UnpackFileSet(testMap, dirB); directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsTrue(directoryMatch, "Testing whether cabinet output directory matches input directory."); Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); testMap.Remove(files[1] + ".key"); cabInfo.UnpackFileSet(testMap, dirB); directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); Assert.IsFalse(directoryMatch, "Testing whether cabinet output directory matches input directory."); Directory.Delete(dirB, true); Directory.CreateDirectory(dirB); cabInfo.Delete(); cabInfo.PackFiles(dirA, files, null); cabInfo.UnpackFile("€2.txt", Path.Combine(dirB, "test.txt")); Assert.IsTrue(File.Exists(Path.Combine(dirB, "test.txt"))); Assert.AreEqual<int>(1, Directory.GetFiles(dirB).Length); }
public void CabInfoProperties() { Exception caughtEx; CabInfo cabInfo = new CabInfo("test.cab"); int txtSize = 10240; CompressionTestUtil.GenerateRandomFile("test00.txt", 0, txtSize); CompressionTestUtil.GenerateRandomFile("test01.txt", 1, txtSize); cabInfo.PackFiles(null, new string[] { "test00.txt", "test01.txt" }, null); Assert.AreEqual<string>(new FileInfo("test.cab").Directory.FullName, cabInfo.Directory.FullName, "CabInfo.FullName"); Assert.AreEqual<string>(new FileInfo("test.cab").DirectoryName, cabInfo.DirectoryName, "CabInfo.DirectoryName"); Assert.AreEqual<long>(new FileInfo("test.cab").Length, cabInfo.Length, "CabInfo.Length"); Assert.AreEqual<string>("test.cab", cabInfo.Name, "CabInfo.Name"); Assert.AreEqual<string>(new FileInfo("test.cab").FullName, cabInfo.ToString(), "CabInfo.ToString()"); cabInfo.CopyTo("test3.cab"); caughtEx = null; try { cabInfo.CopyTo("test3.cab"); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(IOException), "CabInfo.CopyTo() caught exception: " + caughtEx); cabInfo.CopyTo("test3.cab", true); cabInfo.MoveTo("test4.cab"); Assert.AreEqual<string>("test4.cab", cabInfo.Name); Assert.IsTrue(cabInfo.Exists, "CabInfo.Exists()"); Assert.IsTrue(cabInfo.IsValid(), "CabInfo.IsValid"); cabInfo.Delete(); Assert.IsFalse(cabInfo.Exists, "!CabInfo.Exists()"); }