コード例 #1
0
        public async Task TestApplyPatchRemoveNew()
        {
            var instructions = new FilePatchInstruction[] {
                new FilePatchInstruction()
                {
                    Path             = "file",
                    OldHash          = SHA256.Get(Encoding.UTF8.GetBytes("old")),
                    NewHash          = null,
                    OldLastWriteTime = _dummyLastWriteTime,
                    NewLastWriteTime = _dummyLastWriteTime,
                    HasDelta         = false,
                }
            };

            await ApplyPatchWithInstructions(instructions);

            CollectionAssert.AreEquivalent(new string[] { }, DirectoryPathIterator.GetChildPathsRecursive(_targetDir.Path).ToArray());
            CollectionAssert.AreEquivalent(new string[] { }, DirectoryPathIterator.GetChildPathsRecursive(_backupDir.Path).ToArray());
            TestInvariants();
        }
コード例 #2
0
        public async Task TestApplyPatchWithDeltaRemoved()
        {
            var instructions = new FilePatchInstruction[] {
                new FilePatchInstruction()
                {
                    Path             = "file",
                    OldHash          = SHA256.Get(Encoding.UTF8.GetBytes("old")),
                    NewHash          = SHA256.Get(Encoding.UTF8.GetBytes("new_full")),
                    OldLastWriteTime = _dummyLastWriteTime,
                    NewLastWriteTime = _dummyLastWriteTime,
                    HasDelta         = true,
                }
            };

            await ApplyPatchWithInstructions(instructions);

            CollectionAssert.AreEquivalent(new string[] { "file" }, DirectoryPathIterator.GetChildPathsRecursive(_targetDir.Path).ToArray());
            CollectionAssert.AreEquivalent(new string[] { }, DirectoryPathIterator.GetChildPathsRecursive(_backupDir.Path).ToArray());
            TestInvariants();
            Assert.AreEqual("new_full", File.ReadAllText(Path.Combine(_targetDir.Path, "file")));
        }
コード例 #3
0
        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();
                    }
        }