public void TestExtract() { if (!WindowsUtils.IsWindows) { Assert.Ignore("MSI extraction relies on a Win32 API and therefore will not work on non-Windows platforms"); } using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.msi")) using (var tempFile = Deploy(stream)) using (var sandbox = new TemporaryDirectory("0install-unit-tests")) using (var extractor = Extractor.FromFile(tempFile, sandbox, Archive.MimeTypeMsi)) { extractor.SubDir = "SourceDir"; extractor.Run(); string filePath = Path.Combine(sandbox, "file"); Assert.IsTrue(File.Exists(filePath), "Should extract file 'file'"); Assert.AreEqual(new DateTime(2000, 1, 1, 12, 0, 0), File.GetLastWriteTimeUtc(filePath), "Correct last write time should be set"); Assert.AreEqual("abc", File.ReadAllText(filePath)); filePath = Path.Combine(sandbox, Path.Combine("folder1", "file")); Assert.IsTrue(File.Exists(filePath), "Should extract file 'dir/file'"); Assert.AreEqual(new DateTime(2000, 1, 1, 12, 0, 0), File.GetLastWriteTimeUtc(filePath), "Correct last write time should be set"); Assert.AreEqual("def", File.ReadAllText(filePath)); } }
public void TestExtractInvalidData() { if (!WindowsUtils.IsWindows) { Assert.Ignore("MSI extraction relies on a Win32 API and therefore will not work on non-Windows platforms"); } using (var sandbox = new TemporaryDirectory("0install-unit-tests")) using (var tempFile = Deploy(new MemoryStream(_garbageData))) Assert.Throws <IOException>(() => Extractor.FromFile(tempFile, sandbox, Archive.MimeTypeMsi)); }