示例#1
0
        public void TestCreateExtractor()
        {
            using (var tempDir = new TemporaryDirectory("0install-unit-tests"))
            {
                string path = Path.Combine(tempDir, "a.zip");

                using (var file = File.Create(path))
                    using (var zipStream = new ZipOutputStream(file)
                    {
                        IsStreamOwner = false
                    })
                    {
                        var entry = new ZipEntry("file");
                        zipStream.PutNextEntry(entry);
                        zipStream.CloseEntry();
                    }

                using (var extractor = Extractor.FromStream(File.OpenRead(path), tempDir, Model.Archive.MimeTypeZip))
                    Assert.IsInstanceOf(typeof(ZipExtractor), extractor);
            }
        }
示例#2
0
        public void TestExtractSubDir()
        {
            if (!WindowsUtils.IsWindows)
            {
                Assert.Ignore("7z extraction relies on a Win32 DLL and therefore will not work on non-Windows platforms");
            }

            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.7z"))
                using (var sandbox = new TemporaryDirectory("0install-unit-tests"))
                    using (var extractor = Extractor.FromStream(stream, sandbox, Archive.MimeType7Z))
                    {
                        extractor.SubDir = "folder1";
                        extractor.Run();

                        string filePath = Path.Combine(sandbox, "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));

                        CollectionAssert.IsEmpty(Directory.GetDirectories(sandbox));
                    }
        }
示例#3
0
 public void TestVerifySupport()
 {
     Assert.DoesNotThrow(() => Extractor.VerifySupport(Model.Archive.MimeTypeZip));
     Assert.Throws <NotSupportedException>(() => Extractor.VerifySupport("test/format"));
 }