public async Task RestoreAndUpdateAsyncTest() { await _restoreService.RestoreAndUpdateAsync(_backup); await AssertDatabaseMatchesBackupAsync(); var authenticators = await AuthenticatorRepository.GetAllAsync(); for (var i = 0; i < authenticators.Count; i++) { var authenticator = authenticators[i]; authenticator.Issuer = "test"; await AuthenticatorRepository.UpdateAsync(authenticator); } var categories = await CategoryRepository.GetAllAsync(); for (var i = 0; i < categories.Count; i++) { var category = categories[i]; category.Name = "test"; await CategoryRepository.UpdateAsync(category); } await _restoreService.RestoreAndUpdateAsync(_backup); authenticators = await AuthenticatorRepository.GetAllAsync(); Assert.True(authenticators.All(a => a.Issuer != "test")); categories = await CategoryRepository.GetAllAsync(); Assert.True(categories.All(a => a.Name != "test")); }
private async Task <RestoreResult> RestoreFromDir(Uri destUri) { if (!HasPersistablePermissionsAtUri(destUri)) { throw new InvalidOperationException("No permission at URI"); } var directory = DocumentFile.FromTreeUri(_context, destUri); var files = directory.ListFiles(); var mostRecentBackup = files .Where(f => f.IsFile && f.Type == Backup.MimeType && f.Name.EndsWith(Backup.FileExtension) && f.Length() > 0 && f.CanRead()) .OrderByDescending(f => f.LastModified()) .FirstOrDefault(); if (mostRecentBackup == null || mostRecentBackup.LastModified() <= _preferences.MostRecentBackupModifiedAt) { return(new RestoreResult()); } _preferences.MostRecentBackupModifiedAt = mostRecentBackup.LastModified(); var password = await GetBackupPassword(); if (password == null) { throw new InvalidOperationException("No password defined."); } var data = await FileUtil.ReadFile(_context, mostRecentBackup.Uri); var backup = Backup.FromBytes(data, password); return(await _restoreService.RestoreAndUpdateAsync(backup)); }