From f99573e3342e713ad24afd4c997efc014592eee7 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 24 Oct 2013 08:34:39 -0700 Subject: [PATCH] Added some blacklist tests --- .../BlacklistRepositoryFixture.cs | 57 +++++++++++++++++++ .../Blacklisting/BlacklistServiceFixture.cs | 52 +++++++++++++++++ .../NzbDrone.Core.Test.csproj | 2 + 3 files changed, 111 insertions(+) create mode 100644 src/NzbDrone.Core.Test/Blacklisting/BlacklistRepositoryFixture.cs create mode 100644 src/NzbDrone.Core.Test/Blacklisting/BlacklistServiceFixture.cs diff --git a/src/NzbDrone.Core.Test/Blacklisting/BlacklistRepositoryFixture.cs b/src/NzbDrone.Core.Test/Blacklisting/BlacklistRepositoryFixture.cs new file mode 100644 index 000000000..39ff23c96 --- /dev/null +++ b/src/NzbDrone.Core.Test/Blacklisting/BlacklistRepositoryFixture.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Blacklisting; +using NzbDrone.Core.Download; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Test.Blacklisting +{ + [TestFixture] + public class BlacklistRepositoryFixture : DbTest + { + private Blacklist _blacklist; + + [SetUp] + public void Setup() + { + _blacklist = new Blacklist + { + SeriesId = 12345, + EpisodeIds = new List {1}, + Quality = new QualityModel(Quality.Bluray720p), + SourceTitle = "series.title.s01e01", + Date = DateTime.UtcNow + }; + } + + [Test] + public void should_be_able_to_write_to_database() + { + Subject.Insert(_blacklist); + Subject.All().Should().HaveCount(1); + } + + [Test] + public void should_should_have_episode_ids() + { + Subject.Insert(_blacklist); + + Subject.All().First().EpisodeIds.Should().Contain(_blacklist.EpisodeIds); + } + + [Test] + public void should_check_for_blacklisted_title_case_insensative() + { + Subject.Insert(_blacklist); + + Subject.Blacklisted(_blacklist.SourceTitle.ToUpperInvariant()).Should().BeTrue(); + } + } +} diff --git a/src/NzbDrone.Core.Test/Blacklisting/BlacklistServiceFixture.cs b/src/NzbDrone.Core.Test/Blacklisting/BlacklistServiceFixture.cs new file mode 100644 index 000000000..85d19db97 --- /dev/null +++ b/src/NzbDrone.Core.Test/Blacklisting/BlacklistServiceFixture.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Blacklisting; +using NzbDrone.Core.Download; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Test.Blacklisting +{ + [TestFixture] + public class BlacklistServiceFixture : CoreTest + { + private DownloadFailedEvent _event; + + [SetUp] + public void Setup() + { + _event = new DownloadFailedEvent + { + SeriesId = 12345, + EpisodeIds = new List {1}, + Quality = new QualityModel(Quality.Bluray720p), + SourceTitle = "series.title.s01e01", + DownloadClient = "SabnzbdClient", + DownloadClientId = "Sabnzbd_nzo_2dfh73k" + }; + } + + [Test] + public void should_trigger_redownload() + { + Subject.Handle(_event); + + Mocker.GetMock() + .Verify(v => v.Redownload(_event.SeriesId, _event.EpisodeIds), Times.Once()); + } + + [Test] + public void should_add_to_repository() + { + Subject.Handle(_event); + + Mocker.GetMock() + .Verify(v => v.Insert(It.Is(b => b.EpisodeIds == _event.EpisodeIds)), Times.Once()); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 08aff02d2..2cee27fdc 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -99,6 +99,8 @@ + +