Duplicated root folders are now blocked.

pull/2/head
kay.one 13 years ago
parent 3cb61e4c34
commit d967d4198c

@ -92,7 +92,6 @@ namespace NzbDrone.Core.Test.ProviderTests
} }
[Test] [Test]
public void None_existing_folder_returns_empty_list() 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>();
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
Assert.Throws<InvalidOperationException>(() => rootDirProvider.Add(new RootDir { Path = @"C:\TV" }));
}
} }
} }

@ -33,27 +33,22 @@ namespace NzbDrone.Core.Providers
} }
public virtual void Add(RootDir rootDir) public virtual void Add(RootDir rootDir)
{
ValidatePath(rootDir);
_database.Insert(rootDir);
}
public virtual void Remove(int rootDirId)
{
_database.Delete<RootDir>(rootDirId);
}
private void ValidatePath(RootDir rootDir)
{ {
if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path))
{
throw new ArgumentException("Invalid path"); throw new ArgumentException("Invalid path");
}
if (!_diskProvider.FolderExists(rootDir.Path)) if (!_diskProvider.FolderExists(rootDir.Path))
{
throw new DirectoryNotFoundException("Can't add root directory that doesn't exist."); 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);
} }
public virtual void Remove(int rootDirId)
{
_database.Delete<RootDir>(rootDirId);
} }
public List<String> GetUnmappedFolders(string path) public List<String> GetUnmappedFolders(string path)

@ -93,6 +93,7 @@ namespace NzbDrone.Core.Providers
return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials); 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) public virtual bool Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
{ {
try try

Loading…
Cancel
Save