public void Unarchive() { var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath); unarchiver.Unarchive(CancellationToken.Empty); CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/zip"), _dirPath); }
public void UnarchiveWithPassword() { string password = "******" + "123=="; var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/password-zip.zip"), _dirPath, password); unarchiver.Unarchive(CancellationToken.Empty); CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/password-zip"), _dirPath); }
public void CancelUnarchive() { var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath); CancellationTokenSource source = new CancellationTokenSource(); source.Cancel(); Assert.Catch <OperationCanceledException>(() => unarchiver.Unarchive(source)); }
public void ProgressReporting() { var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath); int?lastAmount = null; int?lastEntry = null; unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) => { if (!lastAmount.HasValue) { lastAmount = amount; } else { Assert.That(amount, Is.EqualTo(lastAmount.Value)); } if (lastEntry.HasValue) { Assert.That(entry, Is.GreaterThanOrEqualTo(lastEntry.Value)); } lastEntry = entry; Assert.That(entry, Is.GreaterThan(0)); if (entryProgress == 1.0) { if (isFile) { string filePath = Path.Combine(_dirPath, name); Assert.That(File.Exists(filePath)); } else { string dirPath = Path.Combine(_dirPath, name); Assert.That(Directory.Exists(dirPath)); } } Assert.That(entryProgress, Is.GreaterThanOrEqualTo(0.0)); Assert.That(entryProgress, Is.LessThanOrEqualTo(1.0)); }; unarchiver.Unarchive(CancellationToken.Empty); Assert.That(lastAmount, Is.Not.Null); Assert.That(lastEntry, Is.Not.Null); Assert.That(lastEntry.Value, Is.EqualTo(lastAmount.Value)); }
public void ProgressReporting() { var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath); int?lastAmount = null; int?lastEntry = null; unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) => { if (!lastAmount.HasValue) { lastAmount = amount; } Assert.AreEqual(lastAmount, amount, "Amount of extracted files cannot change during the operation."); if (lastEntry.HasValue) { Assert.AreEqual(lastEntry + 1, entry, "Entries are not following each other."); } lastEntry = entry; if (entry == 0) { Assert.IsNull(name); Assert.AreEqual(0.0, entryProgress); } else if (isFile) { string filePath = Path.Combine(_dirPath, name); Assert.IsTrue(File.Exists(filePath), string.Format("File doesn't exist - {0}", filePath)); } else { string dirPath = Path.Combine(_dirPath, name); Assert.IsTrue(Directory.Exists(dirPath), string.Format("Directory doesn't exist - {0}", dirPath)); } Assert.GreaterOrEqual(entryProgress, 0.0); Assert.LessOrEqual(entryProgress, 1.0); }; unarchiver.Unarchive(CancellationToken.Empty); Assert.IsNotNull(lastAmount); Assert.IsNotNull(lastEntry); Assert.AreEqual(lastAmount, lastEntry, "Last entry must be equal to amount."); }
public void FindLinuxApp() { var platformResolver = Substitute.For <PlatformResolver>(); platformResolver.GetRuntimePlatform().Returns(RuntimePlatform.LinuxPlayer); // empty directory should be ignored Directory.CreateDirectory(Path.Combine(_tempDir, "directory")); // copy linux app string source = TestFixtures.GetFilePath("magicbytes-test/linux_app"); string dest = Path.Combine(_tempDir, "executable"); File.Copy(source, dest); var appFinder = new AppFinder(); string executable = appFinder.FindLinuxExecutable(_tempDir); Assert.AreEqual(dest, executable); }
public void Unpack() { string archivePath = TestFixtures.GetFilePath("pack1/test.pack1"); string metaPath = TestFixtures.GetFilePath("pack1/test.pack1.meta"); string metaString = File.ReadAllText(metaPath); Pack1Meta meta = Pack1Meta.Parse(metaString); var pack1Unarchiver = new Pack1Unarchiver(archivePath, meta, _tempDir, Key); pack1Unarchiver.Unarchive(new CancellationToken()); Assert.True(Directory.Exists(Path.Combine(_tempDir, "dir"))); var rakefile = Path.Combine(_tempDir, "dir/Rakefile"); Assert.True(File.Exists(rakefile)); Assert.AreEqual("d2974b45f816b3ddaca7a984a9101707", Md5File(rakefile)); var rubocopFile = Path.Combine(_tempDir, ".rubocop.yml"); Assert.True(File.Exists(rubocopFile)); Assert.AreEqual("379cc2261c048e4763969cca74974237", Md5File(rubocopFile)); }
public void SetUp() { _macApp = TestFixtures.GetFilePath("magicbytes-test/mac_app"); _windowsApp = TestFixtures.GetFilePath("magicbytes-test/windows_app"); _linuxApp = TestFixtures.GetFilePath("magicbytes-test/linux_app"); }
public void UnarchiveCorruptedArchive() { var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/corrupted-zip.zip"), _dirPath); Assert.Catch <Exception>(() => unarchiver.Unarchive(CancellationToken.Empty)); }