From 1350e5143fcb390bd2cedcaa4a15236ca0a02357 Mon Sep 17 00:00:00 2001 From: "piedone@pyrocenter.hu" Date: Wed, 14 Dec 2011 23:45:49 +0100 Subject: [PATCH] IStorageProvider FileExists() and FolderExists() --HG-- branch : 1.x extra : rebase_source : 89792dec51c9419263c469998810cb95d6a2c050 --- .../Storage/FileSystemStorageProviderTests.cs | 20 +++++++++++++++++++ .../FileSystems/Media/IStorageProvider.cs | 14 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs b/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs index 6a5a46f2b..227322733 100644 --- a/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs +++ b/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs @@ -57,6 +57,16 @@ namespace Orchard.Tests.Storage { private string _folderPath; private IStorageProvider _storageProvider; + [Test] + public void ExistsShouldBeTrueForExtistingFile() { + Assert.That(_storageProvider.FileExists("testfile.txt"), Is.True); + } + + [Test] + public void ExistsShouldBeFalseForNonExtistingFile() { + Assert.That(_storageProvider.FileExists("notexisting"), Is.False); + } + [Test] [ExpectedException(typeof(ArgumentException))] public void GetFileThatDoesNotExistShouldThrow() { @@ -99,6 +109,16 @@ namespace Orchard.Tests.Storage { Assert.That(file2.GetPath(), Is.EqualTo("Subfolder1" + Path.DirectorySeparatorChar + "one.txt")); } + [Test] + public void ExistsShouldBeTrueForExtistingFolder() { + Assert.That(_storageProvider.FolderExists("Subfolder1"), Is.True); + } + + [Test] + public void ExistsShouldBeFalseForNonExtistingFolder() { + Assert.That(_storageProvider.FolderExists("notexisting"), Is.False); + } + [Test] public void ListFoldersReturnsItemsWithShortPathAndEnvironmentSlashes() { var folders = _storageProvider.ListFolders(@"Subfolder1"); diff --git a/src/Orchard/FileSystems/Media/IStorageProvider.cs b/src/Orchard/FileSystems/Media/IStorageProvider.cs index 793ab6f4f..ded0e27ac 100644 --- a/src/Orchard/FileSystems/Media/IStorageProvider.cs +++ b/src/Orchard/FileSystems/Media/IStorageProvider.cs @@ -4,6 +4,13 @@ using System.IO; namespace Orchard.FileSystems.Media { public interface IStorageProvider : IDependency { + /// + /// Checks if the given file exists within the storage provider. + /// + /// The relative path within the storage provider. + /// True if the file exists; False otherwise. + bool FileExists(string path); + /// /// Retrieves the public URL for a given file within the storage provider. /// @@ -26,6 +33,13 @@ namespace Orchard.FileSystems.Media { /// The list of files in the folder. IEnumerable ListFiles(string path); + /// + /// Checks if the given folder exists within the storage provider. + /// + /// The relative path within the storage provider. + /// True if the folder exists; False otherwise. + bool FolderExists(string path); + /// /// Lists the folders within a storage provider's path. ///