public async Task TestAddRemoveKnownWatchedFolder() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { KnownFolder knownFolder = New <IKnownFoldersDiscovery>().Discover().First(); FakeDataStore.AddFolder(knownFolder.My.FullName); await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.RemoveAndDecryptWatchedFolder(knownFolder.My); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.RemoveAndDecryptWatchedFolder(knownFolder.My); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); } }
public async Task TestWatchedFolders() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state.WatchedFolders, Is.Not.Null, "There should be a Watched Folders instance."); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders."); FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still only be one Watched Folder."); await state.Save(); } using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); Assert.That(state.WatchedFolders.First().Matches(_rootPath), "The Watched Folder should be equal to this."); await state.RemoveAndDecryptWatchedFolder(Resolve.WorkFolder.FileInfo.FolderItemInfo("mystate.txt")); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still be one Watched folders."); await state.RemoveAndDecryptWatchedFolder(New <IDataContainer>(_rootPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders now."); } }
private async Task AddWatchedFoldersAction(IEnumerable <string> folders) { if (!folders.Any()) { return; } foreach (string folder in folders) { await _fileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder, Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag)); } await _fileSystemState.Save(); }
public async Task TestWatchedFolderRemoved() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); FakeDataStore.RemoveFileOrFolder(_rootPath); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); } }
private async Task AddWatchedFoldersActionAsync(IEnumerable <string> folders) { if (!folders.Any()) { return; } foreach (string folder in folders) { if (New <FileFilter>().IsForbiddenFolder(folder)) { await New <IPopup>().ShowAsync(PopupButtons.Ok, Texts.WarningTitle, Texts.SystemFolderForbiddenText.InvariantFormat(folder)); continue; } await _fileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder, Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag)); } await _fileSystemState.Save(); }
public async Task TestWatchedFolderChanged() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.ActiveFileCount, Is.EqualTo(0)); FakeDataStore.AddFile(_encryptedAxxPath, new MemoryStream(Resources.helloworld_key_a_txt)); Assert.That(state.ActiveFileCount, Is.EqualTo(0)); state.Add(new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId)); Assert.That(state.ActiveFileCount, Is.EqualTo(1)); New <IDataStore>(_encryptedAxxPath).Delete(); Assert.That(state.ActiveFileCount, Is.EqualTo(0), "When deleted, the active file count should be zero."); } }
private async Task EnsureKnownFoldersWatched(IEnumerable <KnownFolder> folders) { foreach (KnownFolder knownFolder in folders) { if (_fileSystemState.AllWatchedFolders.Any((wf) => wf.Path == knownFolder.My.FullName)) { continue; } if (knownFolder.My.IsFile) { continue; } if (!knownFolder.My.IsAvailable) { knownFolder.Folder.CreateFolder(knownFolder.My.Name); } await _fileSystemState.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, _knownIdentities.DefaultEncryptionIdentity.Tag)); } await _fileSystemState.Save(); }