Exemple #1
0
        public async Task TestWithEmptyFiles()
        {
            var patchSystem  = XdeltaPatchSystemFactory.Preferred;
            var patchBuilder = new XdeltaPatchBuilder(patchSystem);

            using (var oldFile = new TemporaryFile())
                using (var newFile = new TemporaryFile())
                    using (var patchFile = new TemporaryFile())
                    {
                        await patchBuilder.CreatePatchAsync(oldFile.Path, newFile.Path, patchFile.Path);

                        Assert.AreNotEqual(0, new FileInfo(patchFile.Path).Length);
                    }
        }
Exemple #2
0
        public async Task CompressedContentsDoNotDependOnInputPath()
        {
            var patchBuilder = new XdeltaPatchBuilder(XdeltaPatchSystemFactory.Preferred);

            using (var newFile1 = new TemporaryFile())
                using (var newFile2 = new TemporaryFile())
                    using (var patchFile1 = new TemporaryFile())
                        using (var patchFile2 = new TemporaryFile())
                        {
                            File.WriteAllText(newFile1.Path, "b");
                            File.WriteAllText(newFile2.Path, "b");
                            await patchBuilder.CompressAsync(newFile1.Path, patchFile1.Path);

                            await patchBuilder.CompressAsync(newFile2.Path, patchFile2.Path);

                            CollectionAssert.AreEquivalent(File.ReadAllBytes(patchFile1.Path), File.ReadAllBytes(patchFile2.Path));
                        }
        }
Exemple #3
0
        public async Task TestRoundtrip()
        {
            var patchSystem  = XdeltaPatchSystemFactory.Preferred;
            var patchBuilder = new XdeltaPatchBuilder(patchSystem);
            var patcher      = new XdeltaPatcher(patchSystem);

            using (var oldFile = new TemporaryFile())
                using (var newFile = new TemporaryFile())
                    using (var patchFile = new TemporaryFile())
                        using (var patchedFile = new TemporaryFile())
                        {
                            File.WriteAllText(oldFile.Path, "old");
                            File.WriteAllText(newFile.Path, "new");
                            await patchBuilder.CreatePatchAsync(oldFile.Path, newFile.Path, patchFile.Path);

                            await patcher.ApplyPatchAsync(oldFile.Path, patchedFile.Path, patchFile.Path);

                            Assert.AreEqual("new", File.ReadAllText(patchedFile.Path));
                        }
        }
        public static void ClassInitialize(TestContext context)
        {
            _patchDir = new TemporaryDirectory();

            using (var oldFile = new TemporaryFile())
                using (var newDeltaFile = new TemporaryFile())
                    using (var newFullFile = new TemporaryFile())
                    {
                        File.WriteAllText(oldFile.Path, "old");
                        File.WriteAllText(newDeltaFile.Path, "new_delta");
                        File.WriteAllText(newFullFile.Path, "new_full");
                        string oldHash      = SHA256.Get(Encoding.UTF8.GetBytes("old"));
                        string newDeltaHash = SHA256.Get(Encoding.UTF8.GetBytes("new_delta"));
                        string newFullHash  = SHA256.Get(Encoding.UTF8.GetBytes("new_full"));

                        Directory.CreateDirectory(Path.Combine(_patchDir.Path, "delta"));
                        Directory.CreateDirectory(Path.Combine(_patchDir.Path, "full"));
                        var patchBuilder = new XdeltaPatchBuilder(XdeltaPatchSystemFactory.Preferred);
                        patchBuilder.CreatePatchAsync(oldFile.Path, newDeltaFile.Path, Path.Combine(_patchDir.Path, "delta/" + newDeltaHash + "_from_" + oldHash)).Wait();
                        patchBuilder.CompressAsync(newFullFile.Path, Path.Combine(_patchDir.Path, "full/" + newFullHash)).Wait();
                        _patchDirFiles = DirectoryPathIterator.GetChildPathsRecursive(_patchDir.Path).ToArray();
                    }
        }