Ejemplo n.º 1
0
        private void ShouldZipAndUnzipWithoutLose(bool compress){

            string testfolder = Path.Combine(System.IO.Path.GetTempPath(), DateTime.Now.Ticks.ToString());
            Directory.CreateDirectory(testfolder);

            string path1 = Path.Combine(testfolder, "text1.txt");
            string path2 = Path.Combine(testfolder, "text2.txt");

            string text1 = "";
            string text2 = "START data\r\n ééúóáEN\u0247D";

            CreateTextFile(path1, text1);
            CreateTextFile(path2, text2);

            string zippath = Path.Combine(testfolder, "archive.zip");
            string extractdir = Path.Combine(testfolder, "extract");
            string path11 = Path.Combine(extractdir, "text1.txt");
            string path22 = Path.Combine(extractdir, "text2.txt");

            try {
                using (var zip = new ZipFile(compress)) {
                    zip.AddFile(path1);
                    zip.AddFile(path2);
                    zip.SaveAs(zippath);
                }

                ZipFile.ExtractAll(zippath, extractdir);

                A.True(Directory.Exists(extractdir));
                A.True(File.Exists(path11));
                A.True(File.Exists(path22));

                var text11 = File.ReadAllText(path11);
                A.AreEqual(text1, text11);

                var text22 = File.ReadAllText(path22);
                A.AreEqual(text2, text22);
            } finally {
                Directory.Delete(testfolder, true);
            }
        }
Ejemplo n.º 2
0
        public void TC_ShouldSerializeZipFile() {
            string testfolder = Path.Combine(System.IO.Path.GetTempPath(), DateTime.Now.Ticks.ToString());
            Directory.CreateDirectory(testfolder);

            string filepath = Path.Combine(testfolder, "text1.txt");
            string expectedText = "START data\r\n ééúóáEN\u0247D";
            using (StreamWriter sw = File.CreateText(filepath))
                sw.Write(expectedText);

            try {
                string output;
                using (var zip = new ZipFile()) {
                    zip.AddFile(filepath);
                    File.Delete(filepath);
                    output = (string)SerializeAndDeserialize(zip);
                }
                byte[] bytes = Convert.FromBase64String(output);


                //extract the text file
                using (var stream = new MemoryStream(bytes))
                    ZipFile.ExtractAll(stream, testfolder);

                //assert text content
                var textReaded = File.ReadAllText(filepath);
                A.AreEqual(expectedText, textReaded);
            } finally {
                Directory.Delete(testfolder, true);
            }
        }