public void ArchiveUpdater_SimpleUpdateJar_Succeeds()
        {
            // Arrange - create an input archive file
            string rootTestDir     = TestUtils.CreateTestDirectory(this.TestContext);
            string originalZipFile = Path.Combine(rootTestDir, "original.zip");
            string updatedZipFile  = Path.Combine(rootTestDir, "updated.zip");

            string setupDir = TestUtils.CreateTestDirectory(this.TestContext, ".zip.setup");

            TestUtils.CreateTextFile("file1.txt", setupDir, "file 1 content");
            TestUtils.CreateTextFile("sub1\\sub2\\file2.txt", setupDir, "file 2 content");

            ZipFile.CreateFromDirectory(setupDir, originalZipFile);

            // Sanity check that the test archive was built correctly
            ZipFileChecker checker = new ZipFileChecker(this.TestContext, originalZipFile);

            checker.AssertZipContainsOnlyExpectedFiles(
                // Original files
                "file1.txt",
                "sub1\\sub2\\file2.txt");


            // Create some new dummy files to add
            string addFile1 = TestUtils.CreateTextFile("additional1.txt", rootTestDir, "a1");
            string addFile2 = TestUtils.CreateTextFile("additional2.txt", rootTestDir, "a2");

            string updaterRootDir = TestUtils.CreateTestDirectory(this.TestContext, "updater");

            ArchiveUpdater updater = new ArchiveUpdater(updaterRootDir, new TestLogger());

            // Act
            updater.SetInputArchive(originalZipFile)
            .SetOutputArchive(updatedZipFile)
            .AddFile(addFile1, "addFile1.txt")
            .AddFile(addFile2, "sub1\\sub2\\addFile2.txt")
            .AddFile(addFile1, "newSubDir\\addFile3.txt");
            updater.UpdateArchive();

            // Assert
            checker = new ZipFileChecker(this.TestContext, updatedZipFile);

            checker.AssertZipContainsOnlyExpectedFiles(
                // Original files
                "file1.txt",
                "sub1\\sub2\\file2.txt",

                // Added files
                "addFile1.txt",
                "sub1\\sub2\\addFile2.txt",
                "newSubDir\\addFile3.txt"
                );
        }
        public void ArchiveUpdater_SimpleUpdateJar_Succeeds()
        {
            // Arrange - create an input archive file
            string rootTestDir = TestUtils.CreateTestDirectory(this.TestContext);
            string originalZipFile = Path.Combine(rootTestDir, "original.zip");
            string updatedZipFile = Path.Combine(rootTestDir, "updated.zip");

            string setupDir = TestUtils.CreateTestDirectory(this.TestContext, ".zip.setup");
            TestUtils.CreateTextFile("file1.txt", setupDir, "file 1 content");
            TestUtils.CreateTextFile("sub1\\sub2\\file2.txt", setupDir, "file 2 content");

            ZipFile.CreateFromDirectory(setupDir, originalZipFile);

            // Sanity check that the test archive was built correctly
            ZipFileChecker checker = new ZipFileChecker(this.TestContext, originalZipFile);
            checker.AssertZipContainsOnlyExpectedFiles(
                // Original files
                "file1.txt",
                "sub1\\sub2\\file2.txt");


            // Create some new dummy files to add
            string addFile1 = TestUtils.CreateTextFile("additional1.txt", rootTestDir, "a1");
            string addFile2 = TestUtils.CreateTextFile("additional2.txt", rootTestDir, "a2");

            string updaterRootDir = TestUtils.CreateTestDirectory(this.TestContext, "updater");

            ArchiveUpdater updater = new ArchiveUpdater(updaterRootDir, new TestLogger());

            // Act
            updater.SetInputArchive(originalZipFile)
                .SetOutputArchive(updatedZipFile)
                .AddFile(addFile1, "addFile1.txt")
                .AddFile(addFile2, "sub1\\sub2\\addFile2.txt")
                .AddFile(addFile1, "newSubDir\\addFile3.txt");
            updater.UpdateArchive();

            // Assert
            checker = new ZipFileChecker(this.TestContext, updatedZipFile);

            checker.AssertZipContainsOnlyExpectedFiles(
                // Original files
                "file1.txt",
                "sub1\\sub2\\file2.txt",

                // Added files
                "addFile1.txt",
                "sub1\\sub2\\addFile2.txt",
                "newSubDir\\addFile3.txt"
                );
        }
Пример #3
0
        public void ExistingEntryUpdated_And_NewEntryAdded()
        {
            // Arrange - create an input archive file
            string rootTestDir     = TestUtils.CreateTestDirectory(this.TestContext);
            string originalZipFile = Path.Combine(rootTestDir, "original.zip");
            string updatedZipFile  = Path.Combine(rootTestDir, "updated.zip");

            using (var archive = new ZipArchive(File.Create(originalZipFile), ZipArchiveMode.Create))
            {
                AddEntry(archive, "sub/unchanged", "unchanged value");
                AddEntry(archive, "sub/changed", "original data in file that is going to be changed to something shorted");
            }

            File.Exists(originalZipFile).Should().BeTrue("Test setup error: original zip file not created");

            string changedFile = TestUtils.CreateTextFile("changed.txt", rootTestDir, "new data in changed file");
            string newFile     = TestUtils.CreateTextFile("newfile.txt", rootTestDir, "new file");


            // Act
            ArchiveUpdater updater = new ArchiveUpdater(new TestLogger());

            updater.SetInputArchive(originalZipFile)
            .SetOutputArchive(updatedZipFile)
            .AddFile(changedFile, "sub/changed")
            .AddFile(newFile, "newfile");
            updater.UpdateArchive();


            // Assert
            using (var updatedArchive = new ZipArchive(File.OpenRead(updatedZipFile), ZipArchiveMode.Read))
            {
                AssertEntryExists(updatedArchive, "sub/unchanged", "unchanged value");
                AssertEntryExists(updatedArchive, "sub/changed", "new data in changed file");
                AssertEntryExists(updatedArchive, "newfile", "new file");
            }
        }