From 5293d0e2042397cf00336c521b721c9a2fda7921 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 21:24:57 -0700 Subject: [PATCH] Fixed american dad's broken fix ;) --- NzbDrone.Core.Test/TvDbProviderTest.cs | 56 ++++++++++++++----------- NzbDrone.Core/Providers/TvDbProvider.cs | 2 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/NzbDrone.Core.Test/TvDbProviderTest.cs b/NzbDrone.Core.Test/TvDbProviderTest.cs index be085c294..5dba84448 100644 --- a/NzbDrone.Core.Test/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/TvDbProviderTest.cs @@ -5,6 +5,8 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; +using TvdbLib.Data; +using System.Collections.Generic; namespace NzbDrone.Core.Test { @@ -12,7 +14,6 @@ namespace NzbDrone.Core.Test // ReSharper disable InconsistentNaming public class TvDbProviderTest : TestBase { - [Test] [TestCase("The Simpsons")] [TestCase("Family Guy")] [TestCase("South Park")] @@ -24,7 +25,6 @@ namespace NzbDrone.Core.Test result[0].SeriesName.Should().Be(title); } - [Test] [TestCase("The Simpsons")] [TestCase("Family Guy")] [TestCase("South Park")] @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test } - [Test] + [TestCase(new object[] { "CAPITAL", "capital", true })] [TestCase(new object[] { "Something!!", "Something", true })] [TestCase(new object[] { "Simpsons 2000", "Simpsons", true })] @@ -94,18 +94,15 @@ namespace NzbDrone.Core.Test //act var result = tvdbProvider.GetSeries(73141, true); - var seasons = result.Episodes.Select(e => e.SeasonNumber) + var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber) .Distinct().ToList(); + var seasons = new List>(seasonsNumbers.Count); - - var seasons1 = result.Episodes.Where(e => e.SeasonNumber == 1).ToList(); - var seasons2 = result.Episodes.Where(e => e.SeasonNumber == 2).ToList(); - var seasons3 = result.Episodes.Where(e => e.SeasonNumber == 3).ToList(); - var seasons4 = result.Episodes.Where(e => e.SeasonNumber == 4).ToList(); - var seasons5 = result.Episodes.Where(e => e.SeasonNumber == 5).ToList(); - var seasons6 = result.Episodes.Where(e => e.SeasonNumber == 6).ToList(); - + foreach (var season in seasonsNumbers) + { + seasons.Insert(season, result.Episodes.Where(e => e.SeasonNumber == season).ToList()); + } foreach (var episode in result.Episodes) { @@ -113,19 +110,28 @@ namespace NzbDrone.Core.Test } //assert - seasons.Should().HaveCount(7); - seasons1.Should().HaveCount(23); - seasons2.Should().HaveCount(19); - seasons3.Should().HaveCount(16); - seasons4.Should().HaveCount(20); - seasons5.Should().HaveCount(18); - - seasons1.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); - seasons2.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); - seasons3.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); - seasons4.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); - seasons5.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); - seasons6.Select(s => s.EpisodeNumber).Should().OnlyHaveUniqueItems(); + seasonsNumbers.Should().HaveCount(7); + seasons[1].Should().HaveCount(23); + seasons[2].Should().HaveCount(19); + seasons[3].Should().HaveCount(16); + seasons[4].Should().HaveCount(20); + seasons[5].Should().HaveCount(18); + + foreach (var season in seasons) + { + season.Should().OnlyHaveUniqueItems(); + } + + //Make sure no episode number is skipped + foreach (var season in seasons) + { + for (int i = 1; i < season.Count; i++) + { + season.Should().Contain(c => c.EpisodeNumber == i, "Can't find Episode S{0:00}E{1:00}", + season[0].SeasonNumber, i); + } + } + } } diff --git a/NzbDrone.Core/Providers/TvDbProvider.cs b/NzbDrone.Core/Providers/TvDbProvider.cs index 7916f3b02..f965e2801 100644 --- a/NzbDrone.Core/Providers/TvDbProvider.cs +++ b/NzbDrone.Core/Providers/TvDbProvider.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Providers //Fix American Dad's scene gongshow if (result != null && result.Id == 73141) { - var seasonOneEpisodeCount = result.Episodes.Where(e => e.SeasonNumber == 0).Count(); + var seasonOneEpisodeCount = result.Episodes.Where(e => e.SeasonNumber == 1).Count(); var seasonOneId = result.Episodes.Where(e => e.SeasonNumber == 1).First().SeasonId; foreach (var episode in result.Episodes)