Esempio n. 1
0
 public static void RemoveRecentFiles(this FileSystemState fileSystemState, IEnumerable <string> encryptedPaths, ProgressContext progress)
 {
     progress.NotifyLevelStart();
     progress.AddTotal(encryptedPaths.Count());
     foreach (string encryptedPath in encryptedPaths)
     {
         ActiveFile activeFile = fileSystemState.FindEncryptedPath(encryptedPath);
         if (activeFile != null)
         {
             fileSystemState.Remove(activeFile);
         }
         progress.AddCount(1);
     }
     fileSystemState.Save();
     progress.NotifyLevelFinished();
 }
        public static void TestArgumentNull()
        {
            using (FileSystemState state = new FileSystemState())
            {
                ActiveFile nullActiveFile = null;
                string nullPath = null;
                Func<ActiveFile, ActiveFile> nullAction = null;
                IRuntimeFileInfo nullFileInfo = null;

                Assert.Throws<ArgumentNullException>(() => { state.Remove(nullActiveFile); });
                Assert.Throws<ArgumentNullException>(() => { state.Add(nullActiveFile); });
                Assert.Throws<ArgumentNullException>(() => { state.FindEncryptedPath(nullPath); });
                Assert.Throws<ArgumentNullException>(() => { state.FindDecryptedPath(nullPath); });
                Assert.Throws<ArgumentNullException>(() => { state.ForEach(ChangedEventMode.RaiseAlways, nullAction); });
                Assert.Throws<ArgumentNullException>(() => { state.Load(nullFileInfo); });
            }
        }
        public static void TestFindEncryptedAndDecryptedPath()
        {
            using (FileSystemState state = new FileSystemState())
            {
                state.Load(OS.Current.FileInfo(_mystateXmlPath));
                ActiveFile activeFile = new ActiveFile(OS.Current.FileInfo(_encryptedAxxPath), OS.Current.FileInfo(_decryptedTxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, null);
                state.Add(activeFile);

                ActiveFile byDecryptedPath = state.FindDecryptedPath(_decryptedTxtPath);
                Assert.That(byDecryptedPath, Is.EqualTo(activeFile), "The search should return the same instance.");

                ActiveFile byEncryptedPath = state.FindEncryptedPath(_encryptedAxxPath);
                Assert.That(byEncryptedPath, Is.EqualTo(byDecryptedPath), "The search should return the same instance.");

                ActiveFile notFoundEncrypted = state.FindEncryptedPath(Path.Combine(_rootPath, "notfoundfile.txt"));
                Assert.That(notFoundEncrypted, Is.Null, "A search that does not succeed should return null.");

                ActiveFile notFoundDecrypted = state.FindDecryptedPath(Path.Combine(_rootPath, "notfoundfile.txt"));
                Assert.That(notFoundDecrypted, Is.Null, "A search that does not succeed should return null.");
            }
        }