From b45b8f2e4749d45a9ccb0195adbfbfed9b9b52df Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 27 Jan 2012 10:08:33 -0800 Subject: [PATCH] Added NewzbinId and Blacklisted to History. HistoryProvider can check for blacklist via NzbTitle or NewzbinId. --- .../ProviderTests/HistoryProviderTest.cs | 108 ++++++++++++++++++ .../Datastore/Migrations/Migration20120127.cs | 15 +++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + NzbDrone.Core/Providers/HistoryProvider.cs | 10 ++ NzbDrone.Core/Repository/History.cs | 2 + 5 files changed, 136 insertions(+) create mode 100644 NzbDrone.Core/Datastore/Migrations/Migration20120127.cs diff --git a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs index 8e3b6921c..777f425b0 100644 --- a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs @@ -191,5 +191,113 @@ namespace NzbDrone.Core.Test.ProviderTests history.Quality.Should().Be(storedHistory.First().Quality); history.IsProper.Should().Be(storedHistory.First().IsProper); } + + [Test] + public void IsBlacklisted_should_return_false_if_nzbTitle_doesnt_exist() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = false) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted("Not a Real NZB Title"); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsBlacklisted_should_return_false_if_nzbTitle_is_not_blacklisted() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = false) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted(history.NzbTitle); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsBlacklisted_should_return_true_if_nzbTitle_is_blacklisted() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = true) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted(history.NzbTitle); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsBlacklisted_should_return_false_if_newzbinId_doesnt_exist() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = false) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted(555); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsBlacklisted_should_return_false_if_newzbinId_is_not_blacklisted() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = false) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted(history.NewzbinId); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsBlacklisted_should_return_true_if_newzbinId_is_blacklisted() + { + WithRealDb(); + + var history = Builder.CreateNew() + .With(h => h.Blacklisted = true) + .Build(); + + Db.Insert(history); + + //Act + var result = Mocker.Resolve().IsBlacklisted(history.NewzbinId); + + //Assert + result.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20120127.cs b/NzbDrone.Core/Datastore/Migrations/Migration20120127.cs new file mode 100644 index 000000000..a608e1cff --- /dev/null +++ b/NzbDrone.Core/Datastore/Migrations/Migration20120127.cs @@ -0,0 +1,15 @@ +using System.Data; +using Migrator.Framework; + +namespace NzbDrone.Core.Datastore.Migrations +{ + [Migration(20120127)] + public class Migration20120127 : NzbDroneMigration + { + protected override void MainDbUpgrade() + { + Database.AddColumn("History", "NewzbinId", DbType.Int32, ColumnProperty.Null); + Database.AddColumn("History", "Blacklisted", DbType.Boolean, ColumnProperty.Null); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 4a66dff38..c8f8f6058 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -212,6 +212,7 @@ + diff --git a/NzbDrone.Core/Providers/HistoryProvider.cs b/NzbDrone.Core/Providers/HistoryProvider.cs index 14e17231e..667ad35ac 100644 --- a/NzbDrone.Core/Providers/HistoryProvider.cs +++ b/NzbDrone.Core/Providers/HistoryProvider.cs @@ -68,5 +68,15 @@ namespace NzbDrone.Core.Providers { _database.Delete(historyId); } + + public virtual bool IsBlacklisted(string nzbTitle) + { + return _database.Exists("WHERE Blacklisted = 1 AND NzbTitle = @0", nzbTitle); + } + + public virtual bool IsBlacklisted(int newzbinId) + { + return _database.Exists("WHERE Blacklisted = 1 AND NewzbinId = @0", newzbinId); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/History.cs b/NzbDrone.Core/Repository/History.cs index d34d6c2b2..9295c4955 100644 --- a/NzbDrone.Core/Repository/History.cs +++ b/NzbDrone.Core/Repository/History.cs @@ -16,6 +16,8 @@ namespace NzbDrone.Core.Repository public DateTime Date { get; set; } public bool IsProper { get; set; } public string Indexer { get; set; } + public int NewzbinId { get; set; } + public bool Blacklisted { get; set; } [ResultColumn] public Episode Episode { get; set; }