public void FileFilterThrowsArgumentNull() { FileFilter filter = new FileFilter(); Assert.Throws <ArgumentNullException>(() => filter.AddUnencryptable(null)); Assert.Throws <ArgumentNullException>(() => filter.AddUnencryptableExtension(null)); Assert.Throws <ArgumentNullException>(() => filter.IsEncryptable(null)); }
public void FileFilterTestUnencryptablePatterns() { FileFilter filter = new FileFilter(); string s = $"\\{Path.DirectorySeparatorChar}"; filter.AddUnencryptable(new Regex(@"\\\.dropbox$".Replace(@"\\", s))); filter.AddUnencryptable(new Regex(@"\\desktop\.ini$".Replace(@"\\", s))); filter.AddUnencryptable(new Regex(@".*\.tmp$")); Assert.That(filter.IsEncryptable(new FakeDataStore(@"anywhere\.dropbox")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Somewhere\file.dropbox")), Is.True); Assert.That(filter.IsEncryptable(new FakeDataStore(@".dropboxx")), Is.True); Assert.That(filter.IsEncryptable(new FakeDataStore(@".dropbo")), Is.True); Assert.That(filter.IsEncryptable(new FakeDataStore(@"folder\desktop.ini")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"file-desktop.ini")), Is.True); Assert.That(filter.IsEncryptable(new FakeDataStore(@"anything.tmp")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\anywhere\anything.tmp.tmp")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\anywhere\anything.tmp.tmpx")), Is.True); }
public void FileFilterTestOfficeTemporaryFiles() { FileFilter filter = new FileFilter(); string s = $"\\{Path.DirectorySeparatorChar}"; filter.AddUnencryptable(new Regex(@"^.*\\~\$[^\\]*$".Replace(@"\\", s))); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$\")), Is.True); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$\~$")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$Temp")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$Temp.docx")), Is.False); Assert.That(filter.IsEncryptable(new FakeDataStore(@"C:\Folder\~$Temp.docx\The-file.txt")), Is.True); }