5 // João Matos <joao.matos@xamarin.com>
7 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 using System.IO.Compression;
31 using System.Security.Cryptography;
32 using NUnit.Framework;
34 namespace MonoTests.System.IO.Compression.FileSystem
37 public class ZipArchiveTests
42 File.Delete ("foo.zip");
46 public void ZipCreateFromDirectory()
48 if (File.Exists ("foo.zip"))
49 File.Delete ("foo.zip");
51 ZipFile.CreateFromDirectory ("foo", "foo.zip");
52 Assert.IsTrue(File.Exists("foo.zip"));
54 using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
57 Assert.IsNotNull (archive.GetEntry ("foo.txt"));
58 Assert.IsNotNull (archive.GetEntry ("bar.txt"));
60 Assert.IsNotNull (archive.GetEntry ("foobar/foo.txt"));
61 Assert.IsNotNull (archive.GetEntry ("foobar/bar.txt"));
66 public void ZipCreateFromDirectoryIncludeBase()
68 if (File.Exists ("foo.zip"))
69 File.Delete ("foo.zip");
71 ZipFile.CreateFromDirectory ("foo", "foo.zip", CompressionLevel.Fastest,
72 includeBaseDirectory: true);
73 Assert.IsTrue (File.Exists ("foo.zip"));
75 using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
78 Assert.IsNotNull (archive.GetEntry ("foo/foo.txt"));
79 Assert.IsNotNull (archive.GetEntry ("foo/bar.txt"));
81 Assert.IsNotNull (archive.GetEntry ("foo/foobar/foo.txt"));
82 Assert.IsNotNull (archive.GetEntry ("foo/foobar/bar.txt"));
87 public void ZipExtractToDirectory()
89 if (Directory.Exists ("extract"))
90 Directory.Delete ("extract", true);
92 if (File.Exists ("foo.zip"))
93 File.Delete ("foo.zip");
95 ZipFile.CreateFromDirectory ("foo", "foo.zip");
97 ZipFile.ExtractToDirectory ("foo.zip", "extract");
98 Assert.IsTrue(Directory.Exists ("extract"));
100 Assert.IsTrue (File.Exists ("extract/foo.txt"));
101 Assert.IsTrue (File.Exists ("extract/bar.txt"));
102 Assert.IsTrue (Directory.Exists ("extract/foobar"));
103 Assert.IsTrue (File.Exists ("extract/foobar/foo.txt"));
104 Assert.IsTrue (File.Exists ("extract/foobar/bar.txt"));
106 Directory.Delete ("extract", true);