Fixes for blacklisting.

This commit is contained in:
Mark McDowall 2012-01-27 23:55:09 -08:00
parent f63fadfe35
commit 2da79128cf
4 changed files with 51 additions and 10 deletions

View File

@ -246,6 +246,24 @@ namespace NzbDrone.Core.Test.ProviderTests
result.Should().BeTrue();
}
[Test]
public void IsBlacklisted_should_return_true_if_nzbTitle_is_blacklisted_ignoring_case()
{
WithRealDb();
var history = Builder<History>.CreateNew()
.With(h => h.Blacklisted = true)
.Build();
Db.Insert(history);
//Act
var result = Mocker.Resolve<HistoryProvider>().IsBlacklisted(history.NzbTitle.ToLower());
//Assert
result.Should().BeTrue();
}
[Test]
public void IsBlacklisted_should_return_false_if_newzbinId_doesnt_exist()
{
@ -300,6 +318,14 @@ namespace NzbDrone.Core.Test.ProviderTests
result.Should().BeTrue();
}
[Test]
public void IsBlacklisted_should_throw_if_newzbinId_is_less_than_1()
{
Assert.Throws<ArgumentException>(() =>
Mocker.Resolve<HistoryProvider>().IsBlacklisted(0)
);
}
[Test]
public void SetBlacklist_should_set_to_true_when_true_is_passed_in()
{
@ -337,5 +363,13 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = Db.Single<History>(history.HistoryId);
result.Blacklisted.Should().BeFalse();
}
[Test]
public void SetBlacklist_should_throw_if_newzbinId_is_less_than_1()
{
Assert.Throws<ArgumentException>(() =>
Mocker.Resolve<HistoryProvider>().SetBlacklist(0, true)
);
}
}
}

View File

@ -29,6 +29,13 @@ namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
private QualityProfile sdProfile;
private Series series;
private void WithNoBlacklist()
{
Mocker.GetMock<HistoryProvider>()
.Setup(s => s.IsBlacklisted(It.IsAny<string>()))
.Returns(false);
}
[SetUp]
public void Setup()
{
@ -186,6 +193,7 @@ namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
public void IsQualityNeeded_lesser_file_in_history_should_be_downloaded()
{
WithStrictMocker();
WithNoBlacklist();
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
@ -206,10 +214,6 @@ namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
Mocker.GetMock<HistoryProvider>()
.Setup(s => s.IsBlacklisted(It.IsAny<string>()))
.Returns(false);
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act
@ -244,9 +248,7 @@ namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
Mocker.GetMock<HistoryProvider>()
.Setup(s => s.IsBlacklisted(It.IsAny<string>()))
.Returns(false);
WithNoBlacklist();
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act
@ -307,9 +309,7 @@ namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
Mocker.GetMock<HistoryProvider>()
.Setup(s => s.IsBlacklisted(It.IsAny<string>()))
.Returns(false);
WithNoBlacklist();
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act

View File

@ -10,6 +10,7 @@ namespace NzbDrone.Core.Datastore.Migrations
{
Database.AddColumn("History", "NewzbinId", DbType.Int32, ColumnProperty.Null);
Database.AddColumn("History", "Blacklisted", DbType.Boolean, ColumnProperty.Null);
Database.ExecuteNonQuery("UPDATE History SET Blacklisted = 0");
}
}
}

View File

@ -76,11 +76,17 @@ namespace NzbDrone.Core.Providers
public virtual bool IsBlacklisted(int newzbinId)
{
if (newzbinId <= 0)
throw new ArgumentException("Newzbin ID must be greater than 0");
return _database.Exists<History>("WHERE Blacklisted = 1 AND NewzbinId = @0", newzbinId);
}
public virtual void SetBlacklist(int historyId, bool toggle)
{
if (historyId <= 0)
throw new ArgumentException("HistoryId must be greater than 0");
_database.Execute("UPDATE History SET Blacklisted = @0 WHERE HistoryId = @1", toggle, historyId);
}
}