Esempio n. 1
0
    public void Unarchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        unarchiver.Unarchive(CancellationToken.Empty);

        CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/zip"), _dirPath);
    }
Esempio n. 2
0
    public void UnarchiveWithPassword()
    {
        string password = "******" + "123==";

        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/password-zip.zip"), _dirPath, password);

        unarchiver.Unarchive(CancellationToken.Empty);

        CheckConsistency(TestFixtures.GetDirectoryPath("unarchiver-test/password-zip"), _dirPath);
    }
Esempio n. 3
0
    public void CancelUnarchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        CancellationTokenSource source = new CancellationTokenSource();

        source.Cancel();

        Assert.Catch <OperationCanceledException>(() => unarchiver.Unarchive(source));
    }
    public void ProgressReporting()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        int?lastAmount = null;
        int?lastEntry  = null;

        unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
        {
            if (!lastAmount.HasValue)
            {
                lastAmount = amount;
            }
            else
            {
                Assert.That(amount, Is.EqualTo(lastAmount.Value));
            }

            if (lastEntry.HasValue)
            {
                Assert.That(entry, Is.GreaterThanOrEqualTo(lastEntry.Value));
            }

            lastEntry = entry;

            Assert.That(entry, Is.GreaterThan(0));

            if (entryProgress == 1.0)
            {
                if (isFile)
                {
                    string filePath = Path.Combine(_dirPath, name);
                    Assert.That(File.Exists(filePath));
                }
                else
                {
                    string dirPath = Path.Combine(_dirPath, name);
                    Assert.That(Directory.Exists(dirPath));
                }
            }

            Assert.That(entryProgress, Is.GreaterThanOrEqualTo(0.0));
            Assert.That(entryProgress, Is.LessThanOrEqualTo(1.0));
        };

        unarchiver.Unarchive(CancellationToken.Empty);

        Assert.That(lastAmount, Is.Not.Null);
        Assert.That(lastEntry, Is.Not.Null);
        Assert.That(lastEntry.Value, Is.EqualTo(lastAmount.Value));
    }
    public void ProgressReporting()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);

        int?lastAmount = null;
        int?lastEntry  = null;

        unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
        {
            if (!lastAmount.HasValue)
            {
                lastAmount = amount;
            }
            Assert.AreEqual(lastAmount, amount, "Amount of extracted files cannot change during the operation.");

            if (lastEntry.HasValue)
            {
                Assert.AreEqual(lastEntry + 1, entry, "Entries are not following each other.");
            }

            lastEntry = entry;

            if (entry == 0)
            {
                Assert.IsNull(name);
                Assert.AreEqual(0.0, entryProgress);
            }
            else if (isFile)
            {
                string filePath = Path.Combine(_dirPath, name);
                Assert.IsTrue(File.Exists(filePath), string.Format("File doesn't exist - {0}", filePath));
            }
            else
            {
                string dirPath = Path.Combine(_dirPath, name);
                Assert.IsTrue(Directory.Exists(dirPath), string.Format("Directory doesn't exist - {0}", dirPath));
            }

            Assert.GreaterOrEqual(entryProgress, 0.0);
            Assert.LessOrEqual(entryProgress, 1.0);
        };

        unarchiver.Unarchive(CancellationToken.Empty);

        Assert.IsNotNull(lastAmount);
        Assert.IsNotNull(lastEntry);
        Assert.AreEqual(lastAmount, lastEntry, "Last entry must be equal to amount.");
    }
Esempio n. 6
0
    public void UnarchiveCorruptedArchive()
    {
        var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/corrupted-zip.zip"), _dirPath);

        Assert.Catch <Exception>(() => unarchiver.Unarchive(CancellationToken.Empty));
    }