From 2008b54f5deb2bf61eca5626d71c95154daeb3f2 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 27 Mar 2013 23:49:38 -0700 Subject: [PATCH] fixed few more broken tests. --- .../IndexerTests/IndexerFixture.cs | 3 - .../DatabaseTargetFixture.cs | 1 + .../ProviderTests/SceneMappingProviderTest.cs | 4 +- .../TvTests/SeasonProviderTest.cs | 109 +++--------------- .../TvTests/SeriesProviderTest.cs | Bin 3385 -> 3389 bytes NzbDrone.Core/Instrumentation/Log.cs | 1 - NzbDrone.Core/Tv/SeasonRepository.cs | 2 +- NzbDrone.Core/Tv/SeriesService.cs | 13 ++- NzbDrone.Test.Common/NBuilderExtensions.cs | 26 +++++ .../NzbDrone.Test.Common.csproj | 8 ++ NzbDrone.Test.Common/packages.config | 1 + NzbDrone.ncrunchsolution | 1 + 12 files changed, 64 insertions(+), 105 deletions(-) create mode 100644 NzbDrone.Test.Common/NBuilderExtensions.cs diff --git a/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs b/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs index 1fbde8c7b..2e558e540 100644 --- a/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs +++ b/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.IO; using System.Linq; using System.Net; using System.ServiceModel.Syndication; @@ -13,12 +12,10 @@ using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Indexers; -using NzbDrone.Core.Test.ProviderTests; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.IndexerTests diff --git a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs index 91624f0ec..e12cbf2e2 100644 --- a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs +++ b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentAssertions; using NLog; using NUnit.Framework; +using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Instrumentation; diff --git a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs index d62941ce5..316d2c4ae 100644 --- a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs @@ -9,6 +9,8 @@ using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.ReferenceData; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Test.TvTests; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.ProviderTests { @@ -50,7 +52,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(f => f.TvdbId = 12345) .With(f => f.SceneName = "Law and Order") .With(f => f.SeasonNumber = -1) - .Build(); + .BuildNew(); Db.Insert(fakeMap); diff --git a/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs b/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs index e241ffb76..4668b8a78 100644 --- a/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs +++ b/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs @@ -1,138 +1,61 @@ // ReSharper disable RedundantUsingDirective using System; -using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Tv; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.TvTests { - [TestFixture] - // ReSharper disable InconsistentNaming - public class SeasonProviderTest : DbTest + public class SeasonProviderTest : DbTest { - [SetUp] - public void Setup() - { - - } - [TestCase(true)] [TestCase(false)] public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag) { - //Setup var fakeSeason = Builder.CreateNew() - .With(s => s.Ignored = ignoreFlag) - .Build(); + .With(s => s.Ignored = ignoreFlag) + .BuildNew(); Db.Insert(fakeSeason); - //Act - var result = Mocker.Resolve().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber); + var result = Subject.IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber); - //Assert result.Should().Be(ignoreFlag); } [Test] - public void IsIgnored_should_throw_an_exception_if_not_in_db() - { - Assert.Throws(() => Mocker.Resolve().IsIgnored(10, 0)); - } - - [Test] - public void All_should_return_seasons_with_episodes() - { - const int seriesId = 10; - - var season = Builder.CreateNew() - .With(s => s.SeriesId = seriesId) - .With(s => s.SeasonNumber = 4) - .With(s => s.Ignored = true) - .Build(); - - var episodes = Builder.CreateListOfSize(10) - .All() - .With(e => e.SeriesId = seriesId) - .With(e => e.SeasonNumber = season.SeasonNumber) - .Build(); - - Db.Insert(season); - Db.InsertMany(episodes); - - //Act - var result = Mocker.Resolve().GetSeasonBySeries(seriesId); - - //Assert - result.Should().HaveCount(1); - result.First().Episodes.Should().HaveCount(episodes.Count); - } - - [Test] - public void All_should_return_all_seasons_with_episodes() + public void IsIgnored_should_return_false_if_not_in_db() { - const int seriesId = 10; - - //Setup - - - var seasons = Builder.CreateListOfSize(5) - .All() - .With(s => s.SeriesId = seriesId) - .Build(); - - var episodes = new List(); - - for (int i = 0; i < seasons.Count; i++) - { - var newEps = Builder.CreateListOfSize(2) - .All() - .With(e => e.SeriesId = seriesId) - .With(e => e.SeasonNumber = i + 1) - .Build(); - - episodes.AddRange(newEps); - } - - Db.InsertMany(seasons); - Db.InsertMany(episodes); - - //Act - var result = Mocker.Resolve().GetSeasonBySeries(seriesId); - - //Assert - result.Should().HaveCount(5); - - foreach (var season in result) - { - season.Episodes.Count.Should().Be(2); - season.Episodes.Should().OnlyContain(c => c.SeasonNumber == season.SeasonNumber); - } + Subject.IsIgnored(10, 0).Should().BeFalse(); } - - [Test] public void GetSeason_should_return_seasons_for_specified_series_only() { var seriesA = new[] { 1, 2, 3 }; var seriesB = new[] { 4, 5, 6 }; - Mocker.Resolve().GetSeasonNumbers(1).Should().Equal(seriesA); - Mocker.Resolve().GetSeasonNumbers(2).Should().Equal(seriesB); + var seasonsA = seriesA.Select(c => new Season {SeasonNumber = c, SeriesId = 1}).ToList(); + var seasonsB = seriesB.Select(c => new Season {SeasonNumber = c, SeriesId = 2}).ToList(); + + Subject.InsertMany(seasonsA); + Subject.InsertMany(seasonsB); + + Subject.GetSeasonNumbers(1).Should().Equal(seriesA); + Subject.GetSeasonNumbers(2).Should().Equal(seriesB); } [Test] public void GetSeason_should_return_emptylist_if_series_doesnt_exist() { - Mocker.Resolve().GetSeasonNumbers(1).Should().BeEmpty(); + Subject.GetSeasonNumbers(1).Should().BeEmpty(); } } diff --git a/NzbDrone.Core.Test/TvTests/SeriesProviderTest.cs b/NzbDrone.Core.Test/TvTests/SeriesProviderTest.cs index a5c59588266fc66f3da4b496abbc2e6f3b0893c1..fe936251ca27b3c12818782e65de8a8af40896b4 100644 GIT binary patch delta 17 YcmdlfwO4AxB^H*DGMA*ymsrv{06+=`od5s; delta 12 TcmdlhwNq-tC6>+CSkgHFB{>Bx diff --git a/NzbDrone.Core/Instrumentation/Log.cs b/NzbDrone.Core/Instrumentation/Log.cs index 3a6dd6bf7..58119c84c 100644 --- a/NzbDrone.Core/Instrumentation/Log.cs +++ b/NzbDrone.Core/Instrumentation/Log.cs @@ -15,7 +15,6 @@ namespace NzbDrone.Core.Instrumentation public string Method { get; set; } - public string Exception { get; set; } public string ExceptionType { get; set; } diff --git a/NzbDrone.Core/Tv/SeasonRepository.cs b/NzbDrone.Core/Tv/SeasonRepository.cs index 3b1b8f437..6c88e60c6 100644 --- a/NzbDrone.Core/Tv/SeasonRepository.cs +++ b/NzbDrone.Core/Tv/SeasonRepository.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Tv public IList GetSeasonNumbers(int seriesId) { - return Query.Where(c => c.SeriesId == seriesId).Select(c => c.SeriesId).ToList(); + return Query.Where(c => c.SeriesId == seriesId).Select(c => c.SeasonNumber).ToList(); } public Season Get(int seriesId, int seasonNumber) diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 32f3737dd..a7fe248ff 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -34,14 +34,14 @@ namespace NzbDrone.Core.Tv private readonly TvRageMappingProvider _tvRageMappingProvider; private readonly IEventAggregator _eventAggregator; private readonly IQualityProfileService _qualityProfileService; + private readonly Logger _logger; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - private readonly SceneMappingService _sceneNameMappingService; + private readonly ISceneMappingService _sceneNameMappingService; public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, - TvDbProxy tvDbProxyProxy, SceneMappingService sceneNameMappingService, - TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator, IQualityProfileService qualityProfileService) + TvDbProxy tvDbProxyProxy, ISceneMappingService sceneNameMappingService, + TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator, IQualityProfileService qualityProfileService, Logger logger) { _seriesRepository = seriesRepository; _configService = configServiceService; @@ -50,6 +50,7 @@ namespace NzbDrone.Core.Tv _tvRageMappingProvider = tvRageMappingProvider; _eventAggregator = eventAggregator; _qualityProfileService = qualityProfileService; + _logger = logger; } @@ -84,7 +85,7 @@ namespace NzbDrone.Core.Tv catch (Exception ex) { - logger.ErrorException("Error getting TvRage information for series: " + series.Title, ex); + _logger.ErrorException("Error getting TvRage information for series: " + series.Title, ex); } _seriesRepository.Update(series); @@ -110,7 +111,7 @@ namespace NzbDrone.Core.Tv public void AddSeries(string title, string path, int tvDbSeriesId, int qualityProfileId, DateTime? airedAfter) { - logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path); + _logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path); Ensure.That(() => tvDbSeriesId).IsGreaterThan(0); Ensure.That(() => title).IsNotNullOrWhiteSpace(); diff --git a/NzbDrone.Test.Common/NBuilderExtensions.cs b/NzbDrone.Test.Common/NBuilderExtensions.cs new file mode 100644 index 000000000..62b3b2cd4 --- /dev/null +++ b/NzbDrone.Test.Common/NBuilderExtensions.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Linq; +using FizzWare.NBuilder; +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Test.Common +{ + public static class NBuilderExtensions + { + public static T BuildNew(this ISingleObjectBuilder builder) where T : ModelBase, new() + { + return builder.With(c => c.Id = 0).Build(); + } + + public static List BuildList(this IOperable builder) where T : ModelBase, new() + { + return builder.Build().ToList(); + } + + public static List BuildListOfNew(this IOperable builder) where T : ModelBase, new() + { + return BuildList(builder.All().With(c => c.Id = 0)); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index ef526fd4d..4ab5faeb1 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -53,6 +53,9 @@ MinimumRecommendedRules.ruleset + + ..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll + ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll @@ -89,6 +92,7 @@ + @@ -104,6 +108,10 @@ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} NzbDrone.Common + + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} + NzbDrone.Core + diff --git a/NzbDrone.Test.Common/packages.config b/NzbDrone.Test.Common/packages.config index e4abed86a..32ed27f91 100644 --- a/NzbDrone.Test.Common/packages.config +++ b/NzbDrone.Test.Common/packages.config @@ -2,6 +2,7 @@ + diff --git a/NzbDrone.ncrunchsolution b/NzbDrone.ncrunchsolution index c725a019c..969da6dd4 100644 --- a/NzbDrone.ncrunchsolution +++ b/NzbDrone.ncrunchsolution @@ -2,6 +2,7 @@ 1 True true + true UseDynamicAnalysis Disabled Disabled