示例#1
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));
                        }
        }
        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();
                    }
        }