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(); }
public static LoginResultCode Login(MapleClient c, string username, string password) { var state = LoginResultCode.Unfind; using (var db = new NeoMapleStoryDatabase()) { db.Configuration.LazyLoadingEnabled = false; var model = db.Accounts.Where(x => x.Username == username).Select(x => x).Include(x => x.Characters).FirstOrDefault(); if (model == null) { return(state); } c.Account = model; if (model.LoginState != LoginStateType.NotLogin) { state = LoginResultCode.IsLogged; } else if (model.Password != Sha256.Get(password, model.PasswordSalt)) { state = LoginResultCode.IncorrectPassword; } else if (model.IsPermanentBan || model.TempBanDate != null) { state = LoginResultCode.Banned; } else if (model.Gender == null) { state = LoginResultCode.GenderNeeded; } else { db.SaveChanges(); state = LoginResultCode.Success; } } return(state); }
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"))); }
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(); } }