diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs index 30bba6559..bed081666 100644 --- a/NzbDrone.Core.Test/FluentTest.cs +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -1,19 +1,7 @@ using System; using System.IO; -using System.Linq; -using System.Net; -using System.ServiceModel.Syndication; -using AutoMoq; -using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Providers.Indexer; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test diff --git a/NzbDrone.Core.Test/Framework/Fixtures.cs b/NzbDrone.Core.Test/Framework/Fixtures.cs index 30e514579..2a04a3717 100644 --- a/NzbDrone.Core.Test/Framework/Fixtures.cs +++ b/NzbDrone.Core.Test/Framework/Fixtures.cs @@ -3,48 +3,46 @@ using System.IO; using NLog; using NLog.Config; using NUnit.Framework; +using NzbDrone.Core; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +[SetUpFixture] +public class Fixtures { - [SetUpFixture] - public class Fixtures + [TearDown] + public void TearDown() { - [TearDown] - public void TearDown() + + } + + [SetUp] + public void SetUp() + { + try { + LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); + LogManager.ThrowExceptions = true; + var exceptionVerification = new ExceptionVerification(); + LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, exceptionVerification)); + LogManager.Configuration.Reload(); + } + catch (Exception e) + { + Console.WriteLine("Unable to configure logging. " + e); } - [SetUp] - public void SetUp() + var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories); + foreach (var file in filesToDelete) { try { - LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); - LogManager.ThrowExceptions = true; - - var exceptionVerification = new ExceptionVerification(); - LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, exceptionVerification)); - LogManager.Configuration.Reload(); - } - catch (Exception e) - { - Console.WriteLine("Unable to configure logging. " + e); + File.Delete(file); } - - var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories); - foreach (var file in filesToDelete) - { - try - { - File.Delete(file); - } - catch { } - } - - MockLib.CreateDataBaseTemplate(); + catch { } } + + MockLib.CreateDataBaseTemplate(); } -} \ No newline at end of file +} diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index 40ab07a1a..1d8ce1a7b 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -15,6 +15,7 @@ using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Test.ProviderTests; namespace NzbDrone.Core.Test { diff --git a/NzbDrone.Core.Test/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs similarity index 98% rename from NzbDrone.Core.Test/BacklogSearchJobTest.cs rename to NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index be5a9dd1a..ab29338af 100644 --- a/NzbDrone.Core.Test/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -1,18 +1,15 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; using AutoMoq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] public class BacklogSearchJobTest diff --git a/NzbDrone.Core.Test/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs similarity index 97% rename from NzbDrone.Core.Test/BannerDownloadJobTest.cs rename to NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index ec26d1ed8..57d157ec1 100644 --- a/NzbDrone.Core.Test/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -1,22 +1,16 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using AutoMoq; using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/DiskScanJobTest.cs b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs similarity index 99% rename from NzbDrone.Core.Test/DiskScanJobTest.cs rename to NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs index 2e372ee6d..2f840d651 100644 --- a/NzbDrone.Core.Test/DiskScanJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using AutoMoq; @@ -11,7 +12,7 @@ using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs similarity index 99% rename from NzbDrone.Core.Test/ImportNewSeriesJobTest.cs rename to NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index d64dc057c..72ba0f55d 100644 --- a/NzbDrone.Core.Test/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using AutoMoq; @@ -11,8 +12,8 @@ using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test -{ +namespace NzbDrone.Core.Test.JobTests +{ [TestFixture] // ReSharper disable InconsistentNaming public class ImportNewSeriesJobTest : TestBase diff --git a/NzbDrone.Core.Test/SearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs similarity index 88% rename from NzbDrone.Core.Test/SearchJobTest.cs rename to NzbDrone.Core.Test/JobTests/SearchJobTest.cs index 0e06c85f0..36bdcba25 100644 --- a/NzbDrone.Core.Test/SearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System; using AutoMoq; using Moq; using NUnit.Framework; using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Jobs; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] public class SearchJobTest diff --git a/NzbDrone.Core.Test/SeasonSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs similarity index 95% rename from NzbDrone.Core.Test/SeasonSearchJobTest.cs rename to NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs index 85b62c517..cf6edf385 100644 --- a/NzbDrone.Core.Test/SeasonSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs @@ -1,21 +1,16 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using AutoMoq; using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs similarity index 88% rename from NzbDrone.Core.Test/SeriesSearchJobTest.cs rename to NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs index 0f64beef3..ad9c148cc 100644 --- a/NzbDrone.Core.Test/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs @@ -1,20 +1,13 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using AutoMoq; -using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Jobs; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.JobTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 969874d1a..d151323cd 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -88,41 +88,41 @@ - - - + + + - + + - - - - - - - - - - + + + + + + + + + - - - - + + + + - - - + + + - - - + + + - - + + - + Code @@ -131,23 +131,23 @@ Code - + - - - - - - + + + + + + - + - - + + diff --git a/NzbDrone.Core.Test/ConfigFileProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ConfigFileProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/ConfigFileProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/ConfigFileProviderTest.cs index abbfb8e4c..704fc9857 100644 --- a/NzbDrone.Core.Test/ConfigFileProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ConfigFileProviderTest.cs @@ -4,10 +4,9 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/ConfigProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ConfigProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/ConfigProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/ConfigProviderTest.cs index 14c93ea98..3200202c4 100644 --- a/NzbDrone.Core.Test/ConfigProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ConfigProviderTest.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/DiskScanProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs similarity index 96% rename from NzbDrone.Core.Test/DiskScanProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs index efe556039..c00f22c39 100644 --- a/NzbDrone.Core.Test/DiskScanProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs @@ -2,18 +2,14 @@ using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { // ReSharper disable InconsistentNaming public class DiskScanProviderTest : TestBase diff --git a/NzbDrone.Core.Test/DiskScanProviderTest_ImportFile.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs similarity index 99% rename from NzbDrone.Core.Test/DiskScanProviderTest_ImportFile.cs rename to NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs index bf673758d..e8b58fabb 100644 --- a/NzbDrone.Core.Test/DiskScanProviderTest_ImportFile.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs @@ -11,9 +11,8 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { // ReSharper disable InconsistentNaming public class DiskScanProviderTest_ImportFile : TestBase diff --git a/NzbDrone.Core.Test/DownloadProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/DownloadProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/DownloadProviderTest.cs index 0dd86d5fc..14e5b2b5c 100644 --- a/NzbDrone.Core.Test/DownloadProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTest.cs @@ -11,7 +11,7 @@ using NzbDrone.Core.Test.Framework; // ReSharper disable InconsistentNaming -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] public class DownloadProviderTest : TestBase diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs similarity index 97% rename from NzbDrone.Core.Test/EpisodeProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs index 80d0ff895..f6b02895c 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs @@ -1,1543 +1,1543 @@ -// ReSharper disable RedundantUsingDirective -using System; -using System.Collections.Generic; -using System.Data.SqlServerCe; -using System.Linq; -using AutoMoq; -using FizzWare.NBuilder; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; -using NzbDrone.Core.Test.Framework; -using PetaPoco; -using TvdbLib.Data; - -namespace NzbDrone.Core.Test -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class EpisodeProviderTest : TestBase - { - [Test] - public void GetEpisodes_exists() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).With(e => e.EpisodeFileId = 0).Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - - //Act - var episode = mocker.Resolve().GetEpisode(1); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - } - - [Test] - public void GetEpisodes_by_season_episode_exists() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew() - .With(s => s.SeriesId = 1) - .Build(); - var fakeEpisodes = Builder.CreateNew() - .With(e => e.SeriesId = 1) - .With(e => e.EpisodeNumber = 1) - .And(e => e.SeasonNumber = 2) - .With(e => e.EpisodeFileId = 0).Build(); - - db.Insert(fakeSeries); - db.Insert(fakeEpisodes); - - //Act - var episode = mocker.Resolve().GetEpisode(fakeSeries.SeriesId, 2, 1); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - } - - [Test] - public void GetEpisodes_by_season_episode_doesnt_exists() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - - - //Act - var episode = mocker.Resolve().GetEpisode(1, 1, 1); - - //Assert - episode.Should().BeNull(); - } - - [Test] - public void GetEpisode_with_EpisodeFile() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - db.Insert(fakeFile); - - //Act - var episode = mocker.Resolve().GetEpisode(1); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - episode.EpisodeFile.Should().NotBeNull(); - } - - [Test] - [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] - public void GetEpisodes_invalid_series() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - mocker.Resolve(); - - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).Build(); - - - db.InsertMany(fakeEpisodes); - - - //Act - mocker.Resolve().GetEpisode(1); - } - - [Test] - public void AttachSeries_empty_list() - { - var mocker = new AutoMoqer(); - - - //Act - var result = mocker.Resolve().AttachSeries(new List()); - - //Assert - result.Should().HaveCount(0); - } - - [Test] - public void AttachSeries_list_success() - { - var mocker = new AutoMoqer(); - - var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 12).Build(); - - mocker.GetMock() - .Setup(c => c.GetSeries(12)) - .Returns(fakeSeries); - - //Act - - fakeEpisodes.Should().OnlyContain(e => e.Series == null); - var returnedSeries = mocker.Resolve().AttachSeries(fakeEpisodes); - - //Assert - fakeEpisodes.Should().OnlyContain(e => e.Series == fakeSeries); - returnedSeries.Should().BeEquivalentTo(fakeEpisodes); - } - - [Test] - public void AttachSeries_null_episode_should_return_null() - { - var mocker = new AutoMoqer(); - - Episode episode = null; - - //Act - var result = mocker.Resolve().AttachSeries(episode); - - //Assert - result.Should().BeNull(); - } - - [Test] - public void AttachSeries_single_success() - { - var mocker = new AutoMoqer(); - - var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); - var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); - - mocker.GetMock() - .Setup(c => c.GetSeries(12)) - .Returns(fakeSeries); - - //Act - var returnedEpisode = mocker.Resolve().AttachSeries(fakeEpisodes); - - //Assert - fakeEpisodes.Series.Should().Be(fakeSeries); - returnedEpisode.Should().Be(fakeEpisodes); - } - - [Test] - [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] - public void AttachSeries_single_invalid_series() - { - var mocker = new AutoMoqer(); - mocker.SetConstant(MockLib.GetEmptyDatabase()); - mocker.Resolve(); - var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); - - //Act - var returnedEpisode = mocker.Resolve().AttachSeries(fakeEpisodes); - } - - [Test] - public void GetEpisodesBySeason_success() - { - var fakeSeries = Builder.CreateNew() - .With(s => s.SeriesId = 12) - .Build(); - - var episodes = Builder.CreateListOfSize(10) - .All().With(c => c.SeriesId = 12).And(c => c.SeasonNumber = 2) - .TheFirst(5).With(c => c.SeasonNumber = 1) - .Build(); - - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - db.Insert(fakeSeries); - db.InsertMany(episodes); - - //Act - var seasonEposodes = mocker.Resolve().GetEpisodesBySeason(12, 2); - - //Assert - db.Fetch().Should().HaveCount(10); - seasonEposodes.Should().HaveCount(5); - } - - [Test] - public void RefreshEpisodeInfo_emptyRepo() - { - //Arrange - const int seriesId = 71663; - const int episodeCount = 10; - - var fakeEpisodes = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - - var mocker = new AutoMoqer(); - - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - db.Insert(fakeSeries); - - mocker.GetMock() - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(fakeEpisodes); - - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - var actualCount = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList().Count; - mocker.GetMock().VerifyAll(); - actualCount.Should().Be(episodeCount); - mocker.VerifyAllMocks(); - } - - [Test] - public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() - { - //Arrange - const int seriesId = 71663; - - var fakeEpisodes = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(10). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now) - .TheFirst(7).With(e => e.FirstAired = new DateTime(1800, 1, 1)) - .Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var mocker = new AutoMoqer(); - - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - db.Insert(fakeSeries); - - mocker.GetMock() - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(fakeEpisodes); - - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - var storedEpisodes = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); - storedEpisodes.Should().HaveCount(10); - storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(7); - storedEpisodes.Where(e => e.AirDate != null).Should().HaveCount(3); - - mocker.VerifyAllMocks(); - } - - [Test] - public void RefreshEpisodeInfo_ignore_episode_zero() - { - //Arrange - const int seriesId = 71663; - const int episodeCount = 10; - - var fakeEpisodes = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .TheFirst(1) - .Has(e => e.EpisodeNumber = 0) - .Has(e => e.SeasonNumber = 15) - .Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var mocker = new AutoMoqer(); - - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - db.Insert(fakeSeries); - - mocker.GetMock() - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(fakeEpisodes); - - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - var result = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); - mocker.GetMock().VerifyAll(); - result.Should().HaveCount(episodeCount); - mocker.VerifyAllMocks(); - result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); - } - - [Test] - public void new_episodes_only_calls_Insert() - { - const int seriesId = 71663; - var tvdbSeries = Builder.CreateNew() - .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var currentEpisodes = new List(); - - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - mocker.GetMock(MockBehavior.Strict) - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(tvdbSeries); - - mocker.GetMock() - .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) - .Returns(currentEpisodes); - - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 5)), Times.Once()); - mocker.GetMock().Verify(c => c.Update(It.IsAny>()), Times.Never()); - - mocker.VerifyAllMocks(); - } - - [Test] - public void existing_episodes_only_calls_Update() - { - const int seriesId = 71663; - var tvdbSeries = Builder.CreateNew() - .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var currentEpisodes = new List(); - foreach (var tvDbEpisode in tvdbSeries.Episodes) - { - currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, Series = fakeSeries }); - } - - var mocker = new AutoMoqer(); - - mocker.GetMock(MockBehavior.Strict) - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(tvdbSeries); - - mocker.GetMock() - .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) - .Returns(currentEpisodes); - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 0)), Times.Once()); - mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(l => l.Count() == 5)), Times.Once()); - mocker.VerifyAllMocks(); - } - - [Test] - public void should_try_to_get_existing_episode_using_tvdbid_first() - { - const int seriesId = 71663; - var fakeTvDbResult = Builder.CreateNew() - .With(c => c.Id = seriesId) - .With(c => c.Episodes = new List( - Builder.CreateListOfSize(1) - .All().With(g => g.Id = 99) - .Build()) - ) - .Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - var fakeEpisodeList = new List { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries } }; - - var mocker = new AutoMoqer(); - mocker.GetMock() - .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) - .Returns(fakeEpisodeList); - - mocker.GetMock() - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(fakeTvDbResult); - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.UpdateMany(fakeEpisodeList), Times.Once()); - } - - [Test] - public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_episode() - { - const int seriesId = 71663; - var tvdbSeries = Builder.CreateNew() - .With(c => c.Id = seriesId) - .With(c => c.Episodes = new List{ - Builder.CreateNew() - .With(g => g.Id = 99) - .With(g => g.SeasonNumber = 4) - .With(g => g.EpisodeNumber = 15) - .With(g=>g.SeriesId = seriesId) - .Build() - }) - .Build(); - - var localEpisode = Builder.CreateNew() - .With(c => c.SeriesId = seriesId) - .With(c => c.SeasonNumber = 4) - .With(c => c.EpisodeNumber = 15) - .Build(); - - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var mocker = new AutoMoqer(); - - mocker.GetMock(MockBehavior.Strict) - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(tvdbSeries); - - mocker.GetMock() - .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) - .Returns(new List { localEpisode }); - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.UpdateMany(new List { localEpisode }), Times.Once()); - } - - [Test] - public void existing_episodes_keep_their_episodeId_file_id() - { - const int seriesId = 71663; - var tvdbSeries = Builder.CreateNew() - .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - var currentEpisodes = new List(); - foreach (var tvDbEpisode in tvdbSeries.Episodes) - { - currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries }); - } - - var mocker = new AutoMoqer(); - - mocker.GetMock(MockBehavior.Strict) - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(tvdbSeries); - - var updatedEpisodes = new List(); - - mocker.GetMock() - .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) - .Returns(currentEpisodes); - - mocker.GetMock() - .Setup(c => c.UpdateMany(It.IsAny>())) - .Callback>(ep => updatedEpisodes = ep.ToList()); - - //Act - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - //Assert - updatedEpisodes.Should().HaveSameCount(tvdbSeries.Episodes); - updatedEpisodes.Should().OnlyContain(c => c.EpisodeId == 99); - updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 69); - updatedEpisodes.Should().OnlyContain(c => c.Ignored == true); - } - - [Test] - public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.Ignored = true) - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 2) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 2); - - //Assert - result.Should().BeTrue(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_none_of_episodes_are_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.Ignored = false) - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 2) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 2); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_some_of_episodes_are_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 2) - .With(c => c.Ignored = true) - .Build(); - - episodes[2].Ignored = false; - - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 2); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 3) - .With(c => c.Ignored = true) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 2); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsSeasonIgnored_should_return_true_if_zero_episodes_in_db_for_season_and_previous_is_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 3) - .With(c => c.Ignored = true) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 4); - - //Assert - result.Should().BeTrue(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season_and_previous_is_not_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 3) - .With(c => c.Ignored = false) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 4); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season_one() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - //Act - var result = mocker.Resolve().IsIgnored(10, 1); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsSeasonIgnored_should_return_true_if_zero_episodes_in_db_for_season_zero() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - //Act - var result = mocker.Resolve().IsIgnored(10, 0); - - //Assert - result.Should().BeTrue(); - } - - [Test] - public void IsSeasonIgnored_should_return_false_if_season_zero_is_not_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 0) - .With(c => c.Ignored = false) - .Build(); - - episodes.ToList().ForEach(c => db.Insert(c)); - - //Act - var result = mocker.Resolve().IsIgnored(10, 0); - - //Assert - result.Should().BeFalse(); - } - - [Test] - [Explicit] - public void Add_daily_show_episodes() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - mocker.Resolve(); - - mocker.GetMock() - .Setup(e => e.DefaultQualityProfile).Returns(1); - - db.Insert(Builder.CreateNew().Build()); - - - const int tvDbSeriesId = 71256; - //act - var seriesProvider = mocker.Resolve(); - - seriesProvider.AddSeries("c:\\test\\", tvDbSeriesId, 1); - - var episodeProvider = mocker.Resolve(); - episodeProvider.RefreshEpisodeInfo(seriesProvider.GetSeries(tvDbSeriesId)); - - //assert - var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId); - episodes.Should().NotBeEmpty(); - } - - [Test] - public void GetEpisode_by_Season_Episode_none_existing() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - - //Act - var episode = mocker.Resolve().GetEpisode(1, 1, 1); - - //Assert - episode.Should().BeNull(); - } - - [Test] - public void GetEpisode_by_Season_Episode_with_EpisodeFile() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - db.Insert(fakeFile); - - //Act - var episode = mocker.Resolve().GetEpisode(1, 1, 1); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - episode.EpisodeFile.Should().NotBeNull(); - } - - [Test] - public void GetEpisode_by_Season_Episode_without_EpisodeFile() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - - //Act - var episode = mocker.Resolve().GetEpisode(1, 1, 1); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - episode.EpisodeFile.Should().BeNull(); - } - - [Test] - public void GetEpisode_by_AirDate_with_EpisodeFile() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - db.Insert(fakeFile); - - //Act - var episode = mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - episode.EpisodeFile.Should().NotBeNull(); - } - - [Test] - public void GetEpisode_by_AirDate_without_EpisodeFile() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); - - db.InsertMany(fakeEpisodes); - db.Insert(fakeSeries); - - //Act - var episode = mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); - - //Assert - episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); - episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); - episode.EpisodeFile.Should().BeNull(); - } - - [Test] - public void MarkEpisodeAsFetched() - { - var mocker = new AutoMoqer(); - var db = MockLib.GetEmptyDatabase(); - mocker.SetConstant(db); - - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.GrabDate = null) - .Build(); - - db.InsertMany(fakeEpisodes); - - //Act - mocker.Resolve().MarkEpisodeAsFetched(2); - var episodes = db.Fetch(); - - //Assert - episodes.Where(e => e.EpisodeId == 2).Single().GrabDate.Should().BeWithin(TimeSpan.FromSeconds(5)).Before( - DateTime.Now); - - episodes.Where(e => e.GrabDate == null).Should().HaveCount(4); - } - - [Test] - public void AddEpisode_episode_is_ignored_when_full_season_is_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - var newEpisode = Builder.CreateNew() - .With(e => e.SeriesId = 10) - .With(e => e.SeasonNumber = 1) - .With(e => e.EpisodeNumber = 8) - .With(e => e.SeasonNumber = 1) - .With(e => e.Ignored = false) - .Build(); - - //Act - mocker.Resolve().AddEpisode(newEpisode); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(5); - episodesInDb.Should().OnlyContain(e => e.Ignored); - - mocker.VerifyAllMocks(); - } - - [Test] - public void AddEpisode_episode_is_not_ignored_when_full_season_is_not_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - var newEpisode = Builder.CreateNew() - .With(e => e.SeriesId = 10) - .With(e => e.SeasonNumber = 1) - .With(e => e.EpisodeNumber = 8) - .With(e => e.SeasonNumber = 1) - .With(e => e.Ignored = false) - .Build(); - - //Act - mocker.Resolve().AddEpisode(newEpisode); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(5); - episodesInDb.Should().OnlyContain(e => e.Ignored == false); - - mocker.VerifyAllMocks(); - } - - [Test] - public void AddEpisode_episode_is_not_ignored_when_not_full_season_is_not_ignored() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .And(c => c.SeasonNumber = 1) - .And(c => c.Ignored = true) - .TheFirst(2) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - var newEpisode = Builder.CreateNew() - .With(e => e.SeriesId = 10) - .With(e => e.SeasonNumber = 1) - .With(e => e.EpisodeNumber = 8) - .With(e => e.SeasonNumber = 1) - .With(e => e.Ignored = false) - .Build(); - - //Act - mocker.Resolve().AddEpisode(newEpisode); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(5); - episodesInDb.Where(e => e.EpisodeNumber == 8 && !e.Ignored).Should().HaveCount(1); - - mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreEpisode_Ignore() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - //Act - mocker.Resolve().SetEpisodeIgnore(1, true); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(1); - - mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreEpisode_RemoveIgnore() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - //Act - mocker.Resolve().SetEpisodeIgnore(1, false); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => !e.Ignored).Should().HaveCount(1); - - mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_Ignore() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - //Act - mocker.Resolve().SetSeasonIgnore(10, 1, true); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); - - mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_RemoveIgnore() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - //Act - mocker.Resolve().SetSeasonIgnore(10, 1, false); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => !e.Ignored).Should().HaveCount(4); - - mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_Ignore_Half() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .TheFirst(2) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => db.Insert(c)); - - //Act - mocker.Resolve().SetSeasonIgnore(10, 1, true); - - //Assert - var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); - - mocker.VerifyAllMocks(); - } - - [Test] - public void EpisodesWithoutFiles_no_specials() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.Ignored = true) - .TheFirst(2) - .With(c => c.EpisodeFileId = 0) - .WhereSection(1, 2) - .With(c => c.Ignored = false) - .Build().ToList(); - - var specials = Builder.CreateListOfSize(2) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 0) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.EpisodeFileId = 0) - .With(c => c.Ignored = false) - .TheFirst(1).With(c => c.Ignored = true) - .Build().ToList(); - - db.Insert(series); - db.InsertMany(episodes); - db.InsertMany(specials); - - //Act - var missingFiles = mocker.Resolve().EpisodesWithoutFiles(false); - - //Assert - missingFiles.Should().HaveCount(1); - missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(1); - - mocker.VerifyAllMocks(); - } - - [Test] - public void EpisodesWithoutFiles_with_specials() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.Ignored = true) - .TheFirst(2) - .With(c => c.EpisodeFileId = 0) - .WhereSection(1, 2) - .With(c => c.Ignored = false) - .Build().ToList(); - - var specials = Builder.CreateListOfSize(2) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 0) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.EpisodeFileId = 0) - .With(c => c.Ignored = false) - .TheFirst(1) - .With(c => c.Ignored = true) - .Build().ToList(); - - db.Insert(series); - db.InsertMany(episodes); - db.InsertMany(specials); - - //Act - var missingFiles = mocker.Resolve().EpisodesWithoutFiles(true); - - //Assert - missingFiles.Should().HaveCount(2); - missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(2); - - mocker.VerifyAllMocks(); - } - - [Test] - public void EpisodesWithFiles_success() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var episodeFile = Builder.CreateNew() - .With(c => c.EpisodeFileId = 1) - .Build(); - - var episodes = Builder.CreateListOfSize(2) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.Ignored = true) - .With(c => c.EpisodeFile = episodeFile) - .With(c => c.EpisodeFileId = episodeFile.EpisodeFileId) - .Build().ToList(); - - db.Insert(series); - db.Insert(episodeFile); - db.InsertMany(episodes); - - //Act - var withFiles = mocker.Resolve().EpisodesWithFiles(); - - //Assert - withFiles.Should().HaveCount(2); - withFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(0); - withFiles.Where(e => e.EpisodeFile == null).Should().HaveCount(0); - - foreach (var withFile in withFiles) - { - withFile.EpisodeFile.Should().NotBeNull(); - withFile.Series.Title.Should().NotBeNullOrEmpty(); - } - - mocker.VerifyAllMocks(); - } - - [Test] - public void EpisodesWithFiles_no_files() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var episodes = Builder.CreateListOfSize(2) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.Ignored = true) - .With(c => c.EpisodeFileId = 0) - .Build().ToList(); - - db.Insert(series); - db.InsertMany(episodes); - - //Act - var withFiles = mocker.Resolve().EpisodesWithFiles(); - - //Assert - withFiles.Should().HaveCount(0); - - mocker.VerifyAllMocks(); - } - - [Test] - public void GetEpisodesByFileId_multi_episodes() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var fakeEpisodes = Builder.CreateListOfSize(2) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFileId = 12345) - .Build(); - - db.Insert(series); - db.InsertMany(fakeEpisodes); - - //Act - var episodes = mocker.Resolve().GetEpisodesByFileId(12345); - - //Assert - episodes.Should().HaveCount(2); - mocker.VerifyAllMocks(); - } - - [Test] - public void GetEpisodesByFileId_single_episode() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var series = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .Build(); - - var fakeEpisode = Builder.CreateNew() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFileId = 12345) - .Build(); - - db.Insert(series); - db.Insert(fakeEpisode); - - //Act - var episodes = mocker.Resolve().GetEpisodesByFileId(12345); - - //Assert - episodes.Should().HaveCount(1); - episodes.First().ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisode); - mocker.VerifyAllMocks(); - } - - [Test] - public void IsFirstOrLastEpisodeInSeason_false() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var fakeEpisodes = Builder.CreateListOfSize(10) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .Build(); - - db.InsertMany(fakeEpisodes); - - //Act - var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 5); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsFirstOrLastEpisodeInSeason_true_first() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var fakeEpisodes = Builder.CreateListOfSize(10) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .Build(); - - db.InsertMany(fakeEpisodes); - - //Act - var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 1); - - //Assert - result.Should().BeFalse(); - } - - [Test] - public void IsFirstOrLastEpisodeInSeason_true_last() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var fakeEpisodes = Builder.CreateListOfSize(10) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .Build(); - - db.InsertMany(fakeEpisodes); - - //Act - var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 10); - - //Assert - result.Should().BeFalse(); - } - - [TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Unpacking, 1)] - [TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Failed, 1)] - [TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Unpacking, 2)] - [TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Failed, 2)] - [TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Unpacking, 10)] - [TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Failed, 10)] - public void SetPostDownloadStatus(string folderName, PostDownloadStatusType postDownloadStatus, int episodeCount) - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var fakeSeries = Builder.CreateNew() - .With(s => s.SeriesId = 12345) - .With(s => s.CleanTitle = "officeus") - .Build(); - - var fakeEpisodes = Builder.CreateListOfSize(episodeCount) - .All() - .With(c => c.SeriesId = 12345) - .With(c => c.SeasonNumber = 1) - .With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown) - .Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - - mocker.GetMock().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries); - - //Act - mocker.Resolve().SetPostDownloadStatus(fakeEpisodes.Select(e => e.EpisodeId).ToList(), postDownloadStatus); - - //Assert - var result = db.Fetch(); - result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(episodeCount); - } - - [Test] - public void SetPostDownloadStatus_Invalid_EpisodeId() - { - var db = MockLib.GetEmptyDatabase(); - var mocker = new AutoMoqer(); - mocker.SetConstant(db); - - var postDownloadStatus = PostDownloadStatusType.Failed; - - var fakeSeries = Builder.CreateNew() - .With(s => s.SeriesId = 12345) - .With(s => s.CleanTitle = "officeus") - .Build(); - - var fakeEpisodes = Builder.CreateListOfSize(1) - .All() - .With(c => c.SeriesId = 12345) - .With(c => c.SeasonNumber = 1) - .With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown) - .Build(); - - db.Insert(fakeSeries); - db.InsertMany(fakeEpisodes); - - mocker.GetMock().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries); - - //Act - mocker.Resolve().SetPostDownloadStatus(new List { 300 }, postDownloadStatus); - - //Assert - var result = db.Fetch(); - result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(0); - } - - [Test] - [ExpectedException(typeof(ArgumentException))] - public void SetPostDownloadStatus_should_throw_if_episode_list_is_empty() - { - var mocker = new AutoMoqer(); - mocker.Resolve().SetPostDownloadStatus(new List(), PostDownloadStatusType.Failed); - } - } -} +// ReSharper disable RedundantUsingDirective + +using System; +using System.Collections.Generic; +using System.Linq; +using AutoMoq; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; +using PetaPoco; +using TvdbLib.Data; + +namespace NzbDrone.Core.Test.ProviderTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class EpisodeProviderTest : TestBase + { + [Test] + public void GetEpisodes_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).With(e => e.EpisodeFileId = 0).Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + + //Act + var episode = mocker.Resolve().GetEpisode(1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + } + + [Test] + public void GetEpisodes_by_season_episode_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 1) + .Build(); + var fakeEpisodes = Builder.CreateNew() + .With(e => e.SeriesId = 1) + .With(e => e.EpisodeNumber = 1) + .And(e => e.SeasonNumber = 2) + .With(e => e.EpisodeFileId = 0).Build(); + + db.Insert(fakeSeries); + db.Insert(fakeEpisodes); + + //Act + var episode = mocker.Resolve().GetEpisode(fakeSeries.SeriesId, 2, 1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + } + + [Test] + public void GetEpisodes_by_season_episode_doesnt_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + + + //Act + var episode = mocker.Resolve().GetEpisode(1, 1, 1); + + //Assert + episode.Should().BeNull(); + } + + [Test] + public void GetEpisode_with_EpisodeFile() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + db.Insert(fakeFile); + + //Act + var episode = mocker.Resolve().GetEpisode(1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + episode.EpisodeFile.Should().NotBeNull(); + } + + [Test] + [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] + public void GetEpisodes_invalid_series() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + mocker.Resolve(); + + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).Build(); + + + db.InsertMany(fakeEpisodes); + + + //Act + mocker.Resolve().GetEpisode(1); + } + + [Test] + public void AttachSeries_empty_list() + { + var mocker = new AutoMoqer(); + + + //Act + var result = mocker.Resolve().AttachSeries(new List()); + + //Assert + result.Should().HaveCount(0); + } + + [Test] + public void AttachSeries_list_success() + { + var mocker = new AutoMoqer(); + + var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 12).Build(); + + mocker.GetMock() + .Setup(c => c.GetSeries(12)) + .Returns(fakeSeries); + + //Act + + fakeEpisodes.Should().OnlyContain(e => e.Series == null); + var returnedSeries = mocker.Resolve().AttachSeries(fakeEpisodes); + + //Assert + fakeEpisodes.Should().OnlyContain(e => e.Series == fakeSeries); + returnedSeries.Should().BeEquivalentTo(fakeEpisodes); + } + + [Test] + public void AttachSeries_null_episode_should_return_null() + { + var mocker = new AutoMoqer(); + + Episode episode = null; + + //Act + var result = mocker.Resolve().AttachSeries(episode); + + //Assert + result.Should().BeNull(); + } + + [Test] + public void AttachSeries_single_success() + { + var mocker = new AutoMoqer(); + + var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); + var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); + + mocker.GetMock() + .Setup(c => c.GetSeries(12)) + .Returns(fakeSeries); + + //Act + var returnedEpisode = mocker.Resolve().AttachSeries(fakeEpisodes); + + //Assert + fakeEpisodes.Series.Should().Be(fakeSeries); + returnedEpisode.Should().Be(fakeEpisodes); + } + + [Test] + [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] + public void AttachSeries_single_invalid_series() + { + var mocker = new AutoMoqer(); + mocker.SetConstant(MockLib.GetEmptyDatabase()); + mocker.Resolve(); + var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); + + //Act + var returnedEpisode = mocker.Resolve().AttachSeries(fakeEpisodes); + } + + [Test] + public void GetEpisodesBySeason_success() + { + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 12) + .Build(); + + var episodes = Builder.CreateListOfSize(10) + .All().With(c => c.SeriesId = 12).And(c => c.SeasonNumber = 2) + .TheFirst(5).With(c => c.SeasonNumber = 1) + .Build(); + + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + db.InsertMany(episodes); + + //Act + var seasonEposodes = mocker.Resolve().GetEpisodesBySeason(12, 2); + + //Assert + db.Fetch().Should().HaveCount(10); + seasonEposodes.Should().HaveCount(5); + } + + [Test] + public void RefreshEpisodeInfo_emptyRepo() + { + //Arrange + const int seriesId = 71663; + const int episodeCount = 10; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = + new List(Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + + var mocker = new AutoMoqer(); + + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var actualCount = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList().Count; + mocker.GetMock().VerifyAll(); + actualCount.Should().Be(episodeCount); + mocker.VerifyAllMocks(); + } + + [Test] + public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() + { + //Arrange + const int seriesId = 71663; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = + new List(Builder.CreateListOfSize(10). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now) + .TheFirst(7).With(e => e.FirstAired = new DateTime(1800, 1, 1)) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var mocker = new AutoMoqer(); + + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var storedEpisodes = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + storedEpisodes.Should().HaveCount(10); + storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(7); + storedEpisodes.Where(e => e.AirDate != null).Should().HaveCount(3); + + mocker.VerifyAllMocks(); + } + + [Test] + public void RefreshEpisodeInfo_ignore_episode_zero() + { + //Arrange + const int seriesId = 71663; + const int episodeCount = 10; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = + new List(Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .TheFirst(1) + .Has(e => e.EpisodeNumber = 0) + .Has(e => e.SeasonNumber = 15) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var mocker = new AutoMoqer(); + + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + mocker.GetMock().VerifyAll(); + result.Should().HaveCount(episodeCount); + mocker.VerifyAllMocks(); + result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); + } + + [Test] + public void new_episodes_only_calls_Insert() + { + const int seriesId = 71663; + var tvdbSeries = Builder.CreateNew() + .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var currentEpisodes = new List(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(tvdbSeries); + + mocker.GetMock() + .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) + .Returns(currentEpisodes); + + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 5)), Times.Once()); + mocker.GetMock().Verify(c => c.Update(It.IsAny>()), Times.Never()); + + mocker.VerifyAllMocks(); + } + + [Test] + public void existing_episodes_only_calls_Update() + { + const int seriesId = 71663; + var tvdbSeries = Builder.CreateNew() + .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var currentEpisodes = new List(); + foreach (var tvDbEpisode in tvdbSeries.Episodes) + { + currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, Series = fakeSeries }); + } + + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(tvdbSeries); + + mocker.GetMock() + .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) + .Returns(currentEpisodes); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 0)), Times.Once()); + mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(l => l.Count() == 5)), Times.Once()); + mocker.VerifyAllMocks(); + } + + [Test] + public void should_try_to_get_existing_episode_using_tvdbid_first() + { + const int seriesId = 71663; + var fakeTvDbResult = Builder.CreateNew() + .With(c => c.Id = seriesId) + .With(c => c.Episodes = new List( + Builder.CreateListOfSize(1) + .All().With(g => g.Id = 99) + .Build()) + ) + .Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + var fakeEpisodeList = new List { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries } }; + + var mocker = new AutoMoqer(); + mocker.GetMock() + .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) + .Returns(fakeEpisodeList); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeTvDbResult); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.VerifyAllMocks(); + mocker.GetMock().Verify(c => c.UpdateMany(fakeEpisodeList), Times.Once()); + } + + [Test] + public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_episode() + { + const int seriesId = 71663; + var tvdbSeries = Builder.CreateNew() + .With(c => c.Id = seriesId) + .With(c => c.Episodes = new List{ + Builder.CreateNew() + .With(g => g.Id = 99) + .With(g => g.SeasonNumber = 4) + .With(g => g.EpisodeNumber = 15) + .With(g=>g.SeriesId = seriesId) + .Build() + }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(c => c.SeriesId = seriesId) + .With(c => c.SeasonNumber = 4) + .With(c => c.EpisodeNumber = 15) + .Build(); + + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(tvdbSeries); + + mocker.GetMock() + .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) + .Returns(new List { localEpisode }); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.VerifyAllMocks(); + mocker.GetMock().Verify(c => c.UpdateMany(new List { localEpisode }), Times.Once()); + } + + [Test] + public void existing_episodes_keep_their_episodeId_file_id() + { + const int seriesId = 71663; + var tvdbSeries = Builder.CreateNew() + .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var currentEpisodes = new List(); + foreach (var tvDbEpisode in tvdbSeries.Episodes) + { + currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries }); + } + + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(tvdbSeries); + + var updatedEpisodes = new List(); + + mocker.GetMock() + .Setup(d => d.Fetch(It.IsAny(), It.IsAny())) + .Returns(currentEpisodes); + + mocker.GetMock() + .Setup(c => c.UpdateMany(It.IsAny>())) + .Callback>(ep => updatedEpisodes = ep.ToList()); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + updatedEpisodes.Should().HaveSameCount(tvdbSeries.Episodes); + updatedEpisodes.Should().OnlyContain(c => c.EpisodeId == 99); + updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 69); + updatedEpisodes.Should().OnlyContain(c => c.Ignored == true); + } + + [Test] + public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.Ignored = true) + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 2) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 2); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_none_of_episodes_are_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.Ignored = false) + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 2) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 2); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_some_of_episodes_are_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 2) + .With(c => c.Ignored = true) + .Build(); + + episodes[2].Ignored = false; + + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 2); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 3) + .With(c => c.Ignored = true) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 2); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsSeasonIgnored_should_return_true_if_zero_episodes_in_db_for_season_and_previous_is_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 3) + .With(c => c.Ignored = true) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 4); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season_and_previous_is_not_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 3) + .With(c => c.Ignored = false) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 4); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_zero_episodes_in_db_for_season_one() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + //Act + var result = mocker.Resolve().IsIgnored(10, 1); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsSeasonIgnored_should_return_true_if_zero_episodes_in_db_for_season_zero() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + //Act + var result = mocker.Resolve().IsIgnored(10, 0); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsSeasonIgnored_should_return_false_if_season_zero_is_not_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(MockBehavior.Strict); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 0) + .With(c => c.Ignored = false) + .Build(); + + episodes.ToList().ForEach(c => db.Insert(c)); + + //Act + var result = mocker.Resolve().IsIgnored(10, 0); + + //Assert + result.Should().BeFalse(); + } + + [Test] + [Explicit] + public void Add_daily_show_episodes() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + mocker.Resolve(); + + mocker.GetMock() + .Setup(e => e.DefaultQualityProfile).Returns(1); + + db.Insert(Builder.CreateNew().Build()); + + + const int tvDbSeriesId = 71256; + //act + var seriesProvider = mocker.Resolve(); + + seriesProvider.AddSeries("c:\\test\\", tvDbSeriesId, 1); + + var episodeProvider = mocker.Resolve(); + episodeProvider.RefreshEpisodeInfo(seriesProvider.GetSeries(tvDbSeriesId)); + + //assert + var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId); + episodes.Should().NotBeEmpty(); + } + + [Test] + public void GetEpisode_by_Season_Episode_none_existing() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + + //Act + var episode = mocker.Resolve().GetEpisode(1, 1, 1); + + //Assert + episode.Should().BeNull(); + } + + [Test] + public void GetEpisode_by_Season_Episode_with_EpisodeFile() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + db.Insert(fakeFile); + + //Act + var episode = mocker.Resolve().GetEpisode(1, 1, 1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + episode.EpisodeFile.Should().NotBeNull(); + } + + [Test] + public void GetEpisode_by_Season_Episode_without_EpisodeFile() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + + //Act + var episode = mocker.Resolve().GetEpisode(1, 1, 1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + episode.EpisodeFile.Should().BeNull(); + } + + [Test] + public void GetEpisode_by_AirDate_with_EpisodeFile() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + db.Insert(fakeFile); + + //Act + var episode = mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + episode.EpisodeFile.Should().NotBeNull(); + } + + [Test] + public void GetEpisode_by_AirDate_without_EpisodeFile() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); + + db.InsertMany(fakeEpisodes); + db.Insert(fakeSeries); + + //Act + var episode = mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); + episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries); + episode.EpisodeFile.Should().BeNull(); + } + + [Test] + public void MarkEpisodeAsFetched() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeEpisodes = Builder.CreateListOfSize(5) + .All().With(e => e.GrabDate = null) + .Build(); + + db.InsertMany(fakeEpisodes); + + //Act + mocker.Resolve().MarkEpisodeAsFetched(2); + var episodes = db.Fetch(); + + //Assert + episodes.Where(e => e.EpisodeId == 2).Single().GrabDate.Should().BeWithin(TimeSpan.FromSeconds(5)).Before( + DateTime.Now); + + episodes.Where(e => e.GrabDate == null).Should().HaveCount(4); + } + + [Test] + public void AddEpisode_episode_is_ignored_when_full_season_is_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = true) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + var newEpisode = Builder.CreateNew() + .With(e => e.SeriesId = 10) + .With(e => e.SeasonNumber = 1) + .With(e => e.EpisodeNumber = 8) + .With(e => e.SeasonNumber = 1) + .With(e => e.Ignored = false) + .Build(); + + //Act + mocker.Resolve().AddEpisode(newEpisode); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(5); + episodesInDb.Should().OnlyContain(e => e.Ignored); + + mocker.VerifyAllMocks(); + } + + [Test] + public void AddEpisode_episode_is_not_ignored_when_full_season_is_not_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + var newEpisode = Builder.CreateNew() + .With(e => e.SeriesId = 10) + .With(e => e.SeasonNumber = 1) + .With(e => e.EpisodeNumber = 8) + .With(e => e.SeasonNumber = 1) + .With(e => e.Ignored = false) + .Build(); + + //Act + mocker.Resolve().AddEpisode(newEpisode); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(5); + episodesInDb.Should().OnlyContain(e => e.Ignored == false); + + mocker.VerifyAllMocks(); + } + + [Test] + public void AddEpisode_episode_is_not_ignored_when_not_full_season_is_not_ignored() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .And(c => c.SeasonNumber = 1) + .And(c => c.Ignored = true) + .TheFirst(2) + .With(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + var newEpisode = Builder.CreateNew() + .With(e => e.SeriesId = 10) + .With(e => e.SeasonNumber = 1) + .With(e => e.EpisodeNumber = 8) + .With(e => e.SeasonNumber = 1) + .With(e => e.Ignored = false) + .Build(); + + //Act + mocker.Resolve().AddEpisode(newEpisode); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(5); + episodesInDb.Where(e => e.EpisodeNumber == 8 && !e.Ignored).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreEpisode_Ignore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetEpisodeIgnore(1, true); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => e.Ignored).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreEpisode_RemoveIgnore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = true) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetEpisodeIgnore(1, false); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => !e.Ignored).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreSeason_Ignore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetSeasonIgnore(10, 1, true); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreSeason_RemoveIgnore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = true) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetSeasonIgnore(10, 1, false); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => !e.Ignored).Should().HaveCount(4); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreSeason_Ignore_Half() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.Ignored = true) + .TheFirst(2) + .With(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetSeasonIgnore(10, 1, true); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); + + mocker.VerifyAllMocks(); + } + + [Test] + public void EpisodesWithoutFiles_no_specials() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.Ignored = true) + .TheFirst(2) + .With(c => c.EpisodeFileId = 0) + .WhereSection(1, 2) + .With(c => c.Ignored = false) + .Build().ToList(); + + var specials = Builder.CreateListOfSize(2) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 0) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.EpisodeFileId = 0) + .With(c => c.Ignored = false) + .TheFirst(1).With(c => c.Ignored = true) + .Build().ToList(); + + db.Insert(series); + db.InsertMany(episodes); + db.InsertMany(specials); + + //Act + var missingFiles = mocker.Resolve().EpisodesWithoutFiles(false); + + //Assert + missingFiles.Should().HaveCount(1); + missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void EpisodesWithoutFiles_with_specials() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.Ignored = true) + .TheFirst(2) + .With(c => c.EpisodeFileId = 0) + .WhereSection(1, 2) + .With(c => c.Ignored = false) + .Build().ToList(); + + var specials = Builder.CreateListOfSize(2) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 0) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.EpisodeFileId = 0) + .With(c => c.Ignored = false) + .TheFirst(1) + .With(c => c.Ignored = true) + .Build().ToList(); + + db.Insert(series); + db.InsertMany(episodes); + db.InsertMany(specials); + + //Act + var missingFiles = mocker.Resolve().EpisodesWithoutFiles(true); + + //Assert + missingFiles.Should().HaveCount(2); + missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(2); + + mocker.VerifyAllMocks(); + } + + [Test] + public void EpisodesWithFiles_success() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodeFile = Builder.CreateNew() + .With(c => c.EpisodeFileId = 1) + .Build(); + + var episodes = Builder.CreateListOfSize(2) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.Ignored = true) + .With(c => c.EpisodeFile = episodeFile) + .With(c => c.EpisodeFileId = episodeFile.EpisodeFileId) + .Build().ToList(); + + db.Insert(series); + db.Insert(episodeFile); + db.InsertMany(episodes); + + //Act + var withFiles = mocker.Resolve().EpisodesWithFiles(); + + //Assert + withFiles.Should().HaveCount(2); + withFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(0); + withFiles.Where(e => e.EpisodeFile == null).Should().HaveCount(0); + + foreach (var withFile in withFiles) + { + withFile.EpisodeFile.Should().NotBeNull(); + withFile.Series.Title.Should().NotBeNullOrEmpty(); + } + + mocker.VerifyAllMocks(); + } + + [Test] + public void EpisodesWithFiles_no_files() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodes = Builder.CreateListOfSize(2) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.AirDate = DateTime.Today.AddDays(-4)) + .With(c => c.Ignored = true) + .With(c => c.EpisodeFileId = 0) + .Build().ToList(); + + db.Insert(series); + db.InsertMany(episodes); + + //Act + var withFiles = mocker.Resolve().EpisodesWithFiles(); + + //Assert + withFiles.Should().HaveCount(0); + + mocker.VerifyAllMocks(); + } + + [Test] + public void GetEpisodesByFileId_multi_episodes() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var fakeEpisodes = Builder.CreateListOfSize(2) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.EpisodeFileId = 12345) + .Build(); + + db.Insert(series); + db.InsertMany(fakeEpisodes); + + //Act + var episodes = mocker.Resolve().GetEpisodesByFileId(12345); + + //Assert + episodes.Should().HaveCount(2); + mocker.VerifyAllMocks(); + } + + [Test] + public void GetEpisodesByFileId_single_episode() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var fakeEpisode = Builder.CreateNew() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .With(c => c.EpisodeFileId = 12345) + .Build(); + + db.Insert(series); + db.Insert(fakeEpisode); + + //Act + var episodes = mocker.Resolve().GetEpisodesByFileId(12345); + + //Assert + episodes.Should().HaveCount(1); + episodes.First().ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisode); + mocker.VerifyAllMocks(); + } + + [Test] + public void IsFirstOrLastEpisodeInSeason_false() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var fakeEpisodes = Builder.CreateListOfSize(10) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .Build(); + + db.InsertMany(fakeEpisodes); + + //Act + var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 5); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsFirstOrLastEpisodeInSeason_true_first() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var fakeEpisodes = Builder.CreateListOfSize(10) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .Build(); + + db.InsertMany(fakeEpisodes); + + //Act + var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 1); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsFirstOrLastEpisodeInSeason_true_last() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var fakeEpisodes = Builder.CreateListOfSize(10) + .All() + .With(c => c.SeriesId = 10) + .With(c => c.SeasonNumber = 1) + .Build(); + + db.InsertMany(fakeEpisodes); + + //Act + var result = mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 10); + + //Assert + result.Should().BeFalse(); + } + + [TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Unpacking, 1)] + [TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Failed, 1)] + [TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Unpacking, 2)] + [TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Failed, 2)] + [TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Unpacking, 10)] + [TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Failed, 10)] + public void SetPostDownloadStatus(string folderName, PostDownloadStatusType postDownloadStatus, int episodeCount) + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 12345) + .With(s => s.CleanTitle = "officeus") + .Build(); + + var fakeEpisodes = Builder.CreateListOfSize(episodeCount) + .All() + .With(c => c.SeriesId = 12345) + .With(c => c.SeasonNumber = 1) + .With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown) + .Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + + mocker.GetMock().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries); + + //Act + mocker.Resolve().SetPostDownloadStatus(fakeEpisodes.Select(e => e.EpisodeId).ToList(), postDownloadStatus); + + //Assert + var result = db.Fetch(); + result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(episodeCount); + } + + [Test] + public void SetPostDownloadStatus_Invalid_EpisodeId() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var postDownloadStatus = PostDownloadStatusType.Failed; + + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 12345) + .With(s => s.CleanTitle = "officeus") + .Build(); + + var fakeEpisodes = Builder.CreateListOfSize(1) + .All() + .With(c => c.SeriesId = 12345) + .With(c => c.SeasonNumber = 1) + .With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown) + .Build(); + + db.Insert(fakeSeries); + db.InsertMany(fakeEpisodes); + + mocker.GetMock().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries); + + //Act + mocker.Resolve().SetPostDownloadStatus(new List { 300 }, postDownloadStatus); + + //Assert + var result = db.Fetch(); + result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(0); + } + + [Test] + [ExpectedException(typeof(ArgumentException))] + public void SetPostDownloadStatus_should_throw_if_episode_list_is_empty() + { + var mocker = new AutoMoqer(); + mocker.Resolve().SetPostDownloadStatus(new List(), PostDownloadStatusType.Failed); + } + } +} diff --git a/NzbDrone.Core.Test/EpisodeProviderTest_DeleteInvalidEpisodes.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs similarity index 98% rename from NzbDrone.Core.Test/EpisodeProviderTest_DeleteInvalidEpisodes.cs rename to NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs index 670e8f3ff..70cdf960e 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest_DeleteInvalidEpisodes.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs @@ -1,21 +1,17 @@ // ReSharper disable RedundantUsingDirective -using System; + using System.Collections.Generic; using System.Linq; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; using TvdbLib.Data; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs similarity index 98% rename from NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs rename to NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs index 89b0903f1..1e588c6b9 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs @@ -1,22 +1,17 @@ // ReSharper disable RedundantUsingDirective -using System; + using System.Collections.Generic; using System.Linq; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; -using TvdbLib.Data; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/EventClientProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EventClientProviderTest.cs similarity index 94% rename from NzbDrone.Core.Test/EventClientProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/EventClientProviderTest.cs index 2f0ebfdc3..bc15cc152 100644 --- a/NzbDrone.Core.Test/EventClientProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EventClientProviderTest.cs @@ -1,20 +1,15 @@ // ReSharper disable RedundantUsingDirective using System; -using System.Collections.Generic; using AutoMoq; -using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Core.Model.Xbmc; -using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Xbmc; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/HistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/HistoryProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs index ae1ec0409..cf5185e52 100644 --- a/NzbDrone.Core.Test/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Linq; using AutoMoq; @@ -11,7 +12,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/IndexerProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs index b18d92a9c..9dde9b574 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using System.Net; @@ -13,7 +14,7 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsAcceptableSizeTest.cs similarity index 99% rename from NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs rename to NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsAcceptableSizeTest.cs index 574b58596..1c62eaef7 100644 --- a/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsAcceptableSizeTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using AutoMoq; @@ -12,7 +13,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs similarity index 99% rename from NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs rename to NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs index 589cf808f..f7b7d25cc 100644 --- a/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using AutoMoq; @@ -12,7 +13,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_QualityNeededTest.cs similarity index 99% rename from NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs rename to NzbDrone.Core.Test/ProviderTests/InventoryProvider_QualityNeededTest.cs index 59f42d8b2..cdff67b97 100644 --- a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_QualityNeededTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using AutoMoq; @@ -12,7 +13,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/JobProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/JobProviderTest.cs index e09a6dae3..5838f2ec3 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTest.cs @@ -1,18 +1,17 @@ // ReSharper disable RedundantUsingDirective + using System; -using System.Collections; using System.Collections.Generic; using System.Threading; using AutoMoq; using FluentAssertions; -using Moq; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/LogProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/LogProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/LogProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/LogProviderTest.cs index 64641d769..b35ea4a0d 100644 --- a/NzbDrone.Core.Test/LogProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/LogProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Linq; using AutoMoq; @@ -9,12 +10,10 @@ using NLog; using NLog.Config; using NUnit.Framework; using NzbDrone.Core.Instrumentation; -using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests.cs similarity index 96% rename from NzbDrone.Core.Test/MediaFileProviderTests.cs rename to NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests.cs index f964de872..91f12c5bc 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests.cs @@ -1,24 +1,17 @@ // ReSharper disable RedundantUsingDirective -using System; + using System.Collections.Generic; -using System.IO; -using System.Linq.Expressions; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model; -using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/MediaFileProvider_GetNewFilenameTest.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProvider_GetNewFilenameTest.cs similarity index 99% rename from NzbDrone.Core.Test/MediaFileProvider_GetNewFilenameTest.cs rename to NzbDrone.Core.Test/ProviderTests/MediaFileProvider_GetNewFilenameTest.cs index 037e32ea5..3435c70a2 100644 --- a/NzbDrone.Core.Test/MediaFileProvider_GetNewFilenameTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MediaFileProvider_GetNewFilenameTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; @@ -9,7 +10,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs similarity index 97% rename from NzbDrone.Core.Test/MisnamedProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index 3d36ae5a7..eafc762d5 100644 --- a/NzbDrone.Core.Test/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -1,19 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; -using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] public class MisnamedProviderTest diff --git a/NzbDrone.Core.Test/PostDownloadProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/PostDownloadProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTest.cs index 68bff35f9..01d7ff6a6 100644 --- a/NzbDrone.Core.Test/PostDownloadProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using System.IO; @@ -12,12 +13,9 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; -using TvdbLib.Data; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/QualityTypeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/QualityTypeProviderTest.cs similarity index 97% rename from NzbDrone.Core.Test/QualityTypeProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/QualityTypeProviderTest.cs index ab7771da6..a31cd4031 100644 --- a/NzbDrone.Core.Test/QualityTypeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/QualityTypeProviderTest.cs @@ -1,17 +1,15 @@ // ReSharper disable RedundantUsingDirective -using System; + using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; using NzbDrone.Core.Providers; -using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/RootDirProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/RootDirProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs index 9d2efce7a..9c52f8fa8 100644 --- a/NzbDrone.Core.Test/RootDirProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Linq; using AutoMoq; @@ -10,7 +11,7 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SabProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/SabProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs index 44be00914..833c015f3 100644 --- a/NzbDrone.Core.Test/SabProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs @@ -1,6 +1,6 @@ // ReSharper disable RedundantUsingDirective + using System; -using System.Collections.Generic; using System.IO; using System.Linq; using AutoMoq; @@ -15,7 +15,7 @@ using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SearchProviderTest_Episode.cs b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Episode.cs similarity index 99% rename from NzbDrone.Core.Test/SearchProviderTest_Episode.cs rename to NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Episode.cs index 1e7ef64d1..127de307d 100644 --- a/NzbDrone.Core.Test/SearchProviderTest_Episode.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Episode.cs @@ -10,12 +10,11 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Indexer; -using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SearchProviderTest_PartialSeason.cs b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_PartialSeason.cs similarity index 98% rename from NzbDrone.Core.Test/SearchProviderTest_PartialSeason.cs rename to NzbDrone.Core.Test/ProviderTests/SearchProviderTest_PartialSeason.cs index 63fff0f3a..58021367c 100644 --- a/NzbDrone.Core.Test/SearchProviderTest_PartialSeason.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_PartialSeason.cs @@ -10,12 +10,10 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Indexer; -using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SearchProviderTest_Season.cs b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Season.cs similarity index 98% rename from NzbDrone.Core.Test/SearchProviderTest_Season.cs rename to NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Season.cs index 9c3518433..2fdcbb302 100644 --- a/NzbDrone.Core.Test/SearchProviderTest_Season.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Season.cs @@ -10,12 +10,10 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Indexer; -using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs similarity index 97% rename from NzbDrone.Core.Test/SeriesProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs index 2fd802745..517e56ab2 100644 --- a/NzbDrone.Core.Test/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs @@ -10,10 +10,9 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -using PetaPoco; // ReSharper disable InconsistentNaming -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] public class SeriesProviderTest : TestBase diff --git a/NzbDrone.Core.Test/TvDbProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs similarity index 98% rename from NzbDrone.Core.Test/TvDbProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs index 67e4972fa..c0ec373ce 100644 --- a/NzbDrone.Core.Test/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using System.Linq; @@ -8,7 +9,7 @@ using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using TvdbLib.Data; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/UpcomingEpisodesProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/UpcomingEpisodesProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs index 202832e7b..f8f3aac5e 100644 --- a/NzbDrone.Core.Test/UpcomingEpisodesProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective + using System; using System.Collections.Generic; using System.Linq; @@ -10,7 +11,7 @@ using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming diff --git a/NzbDrone.Core.Test/XbmcProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs similarity index 99% rename from NzbDrone.Core.Test/XbmcProviderTest.cs rename to NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs index 8e17ac008..eebaacf01 100644 --- a/NzbDrone.Core.Test/XbmcProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs @@ -1,7 +1,6 @@ // ReSharper disable RedundantUsingDirective using System; -using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; @@ -12,10 +11,9 @@ using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Xbmc; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.ProviderTests { [TestFixture] // ReSharper disable InconsistentNaming