示例#1
0
        public void ZipPakuStrategyTestError()
        {
            // create some files
            DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());

            List <FileInfo> files = new List <FileInfo>();

            files.Add(CreateTestFile("ZipPakuStrategyTest1.txt", "test1"));
            files.Add(CreateTestFile("ZipPakuStrategyTest2.txt", "test2"));

            List <VirtualFileInfo> virtualFiles = files.Select(x => new VirtualFileInfo(x)).ToList();

            // insert a non-existent file in the middle
            virtualFiles.Insert(1, new VirtualFileInfo(@"C:\ZipPakuStrategyTestError.notreal"));

            IPakuStrategy strategy = new ZipPakuStrategy();
            PakuResult    result   = strategy.Eat(dir, virtualFiles, null);

            // result should be marked as failure; only one file should be deleted
            Assert.IsFalse(result.Success);
            Assert.AreEqual(1, result.RemovedFiles.Count);

            // zip file should still have been created
            Assert.AreEqual(1, result.CreatedFiles.Count);
            FileInfo zipFile = result.CreatedFiles[0].ToFileInfo();

            Assert.IsTrue(zipFile.Exists);

            // clean up
            zipFile.Delete();
        }
示例#2
0
        public void ZipPakuStrategyTest()
        {
            // create some files
            DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());

            List <FileInfo> files = new List <FileInfo>();

            files.Add(CreateTestFile("ZipPakuStrategyTest1.txt", "test1"));
            files.Add(CreateTestFile("ZipPakuStrategyTest2.txt", "test2"));

            List <VirtualFileInfo> virtualFiles = files.Select(x => new VirtualFileInfo(x)).ToList();

            IPakuStrategy strategy = new ZipPakuStrategy();
            PakuResult    result   = strategy.Eat(dir, virtualFiles, "foo");

            // all of the files should have been deleted successfully
            Assert.IsTrue(result.Success);
            Assert.AreEqual(virtualFiles.Count, result.RemovedFiles.Count);

            // and a zip file should have been created
            Assert.AreEqual(1, result.CreatedFiles.Count);
            FileInfo zipFile = result.CreatedFiles[0].ToFileInfo();

            Assert.IsTrue(zipFile.Exists);
            Assert.AreEqual("foo", zipFile.Name.Substring(0, 3));

            // verify that zip file contains all removed files
            using (ZipArchive archive = ZipFile.Open(zipFile.FullName, ZipArchiveMode.Read))
            {
                Assert.AreEqual(result.RemovedFiles.Count, archive.Entries.Count);

                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    Assert.IsTrue(result.RemovedFiles.Any(x => x.Name == entry.Name));
                }
            }

            // clean up
            zipFile.Delete();
        }