Esempio n. 1
0
        public void PackAndUnpackFileTest()
        {
            // TODO: Pack file, unpack file, verify file is same.
            IPackage    ownerPackage = TempPackage;
            string      path         = TempFileRelative; // TODO: Initialize to an appropriate value
            PackageFile target       = new PackageFile(ownerPackage, path);

            target.PackFile();
            Assert.IsTrue(target.IsCompressed);
            Assert.IsNotNull(target.CompressedHash, "Compressed hash should have been computed");
            Assert.IsNotNull(target.Data, "Data should be valid by now.");
            Assert.AreNotEqual(Int64.MinValue, target.CompressedSize, "Compressed size should be valid, since the file has been compressed.");

            System.IO.File.Delete(TempFile + ".bak");
            System.IO.File.Copy(TempFile, TempFile + ".bak");
            try
            {
                System.IO.File.Delete(TempFile);
                Assert.IsFalse(System.IO.File.Exists(TempFile));
                target.Unpack();
                Assert.IsTrue(System.IO.File.Exists(TempFile));
                var backup   = System.IO.File.ReadAllBytes(TempFile + ".bak");
                var unpacked = System.IO.File.ReadAllBytes(TempFile);

                Assert.IsTrue(backup.SequenceEqual(unpacked));

                Assert.IsFalse(target.IsCompressed, "File has been unpacked.");
                Assert.IsNotNull(target.CompressedHash, "Compressed hash should have been computed");
                Assert.AreNotEqual(Int64.MinValue, target.CompressedSize, "Compressed size should be valid, since the file has been compressed at least once.");
                Assert.IsNull(target.Data, "Data is no longer valid - file has been dumped to disk.");
            }
            finally
            {
                System.IO.File.Delete(TempFile + ".bak");
            }
        }