diff --git a/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs index a8ae8a867..433155a40 100644 --- a/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs @@ -92,7 +92,6 @@ namespace NzbDrone.Core.Test.ProviderTests } - [Test] public void None_existing_folder_returns_empty_list() { @@ -123,5 +122,16 @@ namespace NzbDrone.Core.Test.ProviderTests ); } + [Test] + public void adding_duplicated_root_folder_should_throw() + { + WithRealDb(); + + //Act + var rootDirProvider = Mocker.Resolve(); + rootDirProvider.Add(new RootDir { Path = @"C:\TV" }); + Assert.Throws(() => rootDirProvider.Add(new RootDir { Path = @"C:\TV" })); + } + } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 2b07f459b..ee30580b3 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -34,7 +34,15 @@ namespace NzbDrone.Core.Providers public virtual void Add(RootDir rootDir) { - ValidatePath(rootDir); + if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) + throw new ArgumentException("Invalid path"); + + if (!_diskProvider.FolderExists(rootDir.Path)) + throw new DirectoryNotFoundException("Can't add root directory that doesn't exist."); + + if (GetAll().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path))) + throw new InvalidOperationException("Root directory already exist."); + _database.Insert(rootDir); } @@ -43,19 +51,6 @@ namespace NzbDrone.Core.Providers _database.Delete(rootDirId); } - private void ValidatePath(RootDir rootDir) - { - if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) - { - throw new ArgumentException("Invalid path"); - } - - if (!_diskProvider.FolderExists(rootDir.Path)) - { - throw new DirectoryNotFoundException("Can't add root directory that doesn't exist."); - } - } - public List GetUnmappedFolders(string path) { Logger.Debug("Generating list of unmapped folders"); diff --git a/NzbDrone.Core/Providers/SmtpProvider.cs b/NzbDrone.Core/Providers/SmtpProvider.cs index 2ff2eb26b..c22f13b9c 100644 --- a/NzbDrone.Core/Providers/SmtpProvider.cs +++ b/NzbDrone.Core/Providers/SmtpProvider.cs @@ -93,6 +93,7 @@ namespace NzbDrone.Core.Providers return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials); } + //TODO: make this throw instead of return false. public virtual bool Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials) { try