From 8686eb5d322ac9ae2d9f8965eb37df8e77177665 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 20:45:22 -0700 Subject: [PATCH 1/4] IISExpress is now attached to NZBDrone.exe earlier, which means it should almost have a garanteed termination as soon as the host is killed. Console logging starts earlier in the app. Moved Default profiles to QualityProvider. --- NzbDrone.Core/CentralDispatch.cs | 66 +++---------------- .../Instrumentation/LogConfiguration.cs | 10 +-- NzbDrone.Core/Providers/QualityProvider.cs | 34 ++++++++++ NzbDrone.Web/Global.asax.cs | 7 +- NzbDrone.Web/log.config | 2 + NzbDrone/IISController.cs | 11 +++- 6 files changed, 63 insertions(+), 67 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 50b96583c..c4a3c3dd5 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -54,11 +54,11 @@ private static void InitializeApp() { BindKernel(); - LogConfiguration.Setup(); + LogConfiguration.StartDbLogging(); Migrations.Run(Connection.MainConnectionString, true); - SetupDefaultQualityProfiles(_kernel.Get()); //Setup the default QualityProfiles on start-up + _kernel.Get().SetupDefaultProfiles(); BindIndexers(); BindJobs(); @@ -141,11 +141,11 @@ public static void DedicateToHost() { try { - Logger.Debug("Attaching to parent process for automatic termination."); - var pc = new PerformanceCounter("Process", "Creating Process ID", - Process.GetCurrentProcess().ProcessName); - var pid = (int)pc.NextValue(); - var hostProcess = Process.GetProcessById(pid); + var pid = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID")); + + Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid); + + var hostProcess = Process.GetProcessById(Convert.ToInt32(pid)); hostProcess.EnableRaisingEvents = true; hostProcess.Exited += (delegate @@ -154,7 +154,7 @@ public static void DedicateToHost() ShutDown(); }); - Logger.Debug("Successfully Attached to host. Process ID: {0}", pid); + Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName); } catch (Exception e) { @@ -167,55 +167,5 @@ private static void ShutDown() Logger.Info("Shutting down application."); Process.GetCurrentProcess().Kill(); } - - private static void SetupDefaultQualityProfiles(IRepository repository) - { - var sd = new QualityProfile - { - Name = "SD", - Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }, - Cutoff = QualityTypes.SDTV - }; - - var hd = new QualityProfile - { - Name = "HD", - Allowed = - new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, - Cutoff = QualityTypes.HDTV - }; - - //Add or Update SD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name)); - var sdDb = repository.Single(i => i.Name == sd.Name); - if (sdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name)); - repository.Add(sd); - } - - else - { - Logger.Debug(String.Format("Updating default QualityProfile: {0}", sd.Name)); - sd.QualityProfileId = sdDb.QualityProfileId; - repository.Update(sd); - } - - //Add or Update HD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name)); - var hdDb = repository.Single(i => i.Name == hd.Name); - if (hdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name)); - repository.Add(hd); - } - - else - { - Logger.Debug(String.Format("Updating default QualityProfile: {0}", hd.Name)); - hd.QualityProfileId = hdDb.QualityProfileId; - repository.Update(hd); - } - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/LogConfiguration.cs b/NzbDrone.Core/Instrumentation/LogConfiguration.cs index e57ddc52d..21b75225f 100644 --- a/NzbDrone.Core/Instrumentation/LogConfiguration.cs +++ b/NzbDrone.Core/Instrumentation/LogConfiguration.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.IO; using Ninject; +using Ninject.Activation; using NLog; using NLog.Config; @@ -17,12 +18,13 @@ public static void Setup() LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); - LogManager.ConfigurationReloaded += ((s, e) => BindCustomLoggers()); - BindCustomLoggers(); + + LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging()); } - private static void BindCustomLoggers() + public static void StartDbLogging() { + #if Release var exTarget = new ExceptioneerTarget(); LogManager.Configuration.AddTarget("Exceptioneer", exTarget); @@ -30,7 +32,7 @@ private static void BindCustomLoggers() #endif var sonicTarget = CentralDispatch.NinjectKernel.Get(); LogManager.Configuration.AddTarget("DbLogger", sonicTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Info, sonicTarget)); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget)); LogManager.Configuration.Reload(); } diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index 939c3832c..6a5ff341c 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -53,5 +53,39 @@ public virtual QualityProfile Find(int profileId) { return _repository.Single(q => q.QualityProfileId == profileId); } + + public virtual void SetupDefaultProfiles() + { + Logger.Info("Setting up default quality profiles"); + + var profiles = GetAllProfiles(); + + var sd = new QualityProfile { Name = "SD", Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV }; + + var hd = new QualityProfile + { + Name = "HD", + Allowed = new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, + Cutoff = QualityTypes.HDTV + }; + + //Add or Update SD + Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name)); + var sdDb = profiles.Where(p => p.Name == sd.Name).FirstOrDefault(); + if (sdDb == null) + { + Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name)); + Add(sd); + } + + //Add or Update HD + Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name)); + var hdDb = profiles.Where(p => p.Name == hd.Name).FirstOrDefault(); + if (hdDb == null) + { + Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name)); + Add(hd); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Global.asax.cs b/NzbDrone.Web/Global.asax.cs index d23b6085a..182f1d62a 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -36,9 +36,6 @@ protected override void OnApplicationStarted() { base.OnApplicationStarted(); - Logger.Info("NZBDrone Starting up."); - CentralDispatch.DedicateToHost(); - RegisterRoutes(RouteTable.Routes); //base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); @@ -48,6 +45,10 @@ protected override void OnApplicationStarted() protected override IKernel CreateKernel() { + LogConfiguration.Setup(); + Logger.Info("NZBDrone Starting up."); + CentralDispatch.DedicateToHost(); + var kernel = CentralDispatch.NinjectKernel; // kernel.Bind().ToConstant(kernel.Get("LogDb")); diff --git a/NzbDrone.Web/log.config b/NzbDrone.Web/log.config index 8abd77ebc..74a10037b 100644 --- a/NzbDrone.Web/log.config +++ b/NzbDrone.Web/log.config @@ -20,6 +20,8 @@ + + diff --git a/NzbDrone/IISController.cs b/NzbDrone/IISController.cs index 23b7c9e91..7721d5262 100644 --- a/NzbDrone/IISController.cs +++ b/NzbDrone/IISController.cs @@ -49,7 +49,8 @@ internal static Process StartServer() IISProcess.ErrorDataReceived += (OnErrorDataReceived); //Set Variables for the config file. - Environment.SetEnvironmentVariable("NZBDRONE_PATH", Config.ProjectRoot); + IISProcess.StartInfo.EnvironmentVariables.Add("NZBDRONE_PATH", Config.ProjectRoot); + IISProcess.StartInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString()); try { @@ -120,7 +121,7 @@ private static void PingServer(object sender, ElapsedEventArgs e) try { var response = new WebClient().DownloadString(AppUrl + "/health"); - + if (!response.Contains("OK")) { throw new ServerException("Health services responded with an invalid response."); @@ -148,6 +149,12 @@ private static void OnOutputDataReceived(object s, DataReceivedEventArgs e) e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called")) return; + if (e.Data.Contains(" NzbDrone.")) + { + Console.WriteLine(e.Data); + return; + } + IISLogger.Trace(e.Data); } From 87079dcb5293a39d8c8f3b6ade768ef08389a90e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 20:56:10 -0700 Subject: [PATCH 2/4] Added validation in RoodDirProvider to stop adding of invalid root folders. --- NzbDrone.Core.Test/RootDirProviderTest.cs | 38 +++++++++++++++++----- NzbDrone.Core/Providers/RootDirProvider.cs | 30 ++++++++++++----- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/NzbDrone.Core.Test/RootDirProviderTest.cs b/NzbDrone.Core.Test/RootDirProviderTest.cs index 1ddf58866..796709dc2 100644 --- a/NzbDrone.Core.Test/RootDirProviderTest.cs +++ b/NzbDrone.Core.Test/RootDirProviderTest.cs @@ -40,15 +40,14 @@ public void GetRootDirs() Assert.AreEqual(result.Count, 2); } - [Test] - public void AddRootDir() + [TestCase("D:\\TV Shows\\")] + [TestCase("//server//folder")] + public void AddRootDir(string path) { //Setup var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - const string path = @"C:\TV\"; - //Act var rootDirProvider = mocker.Resolve(); rootDirProvider.Add(new RootDir { Path = path }); @@ -62,25 +61,26 @@ public void AddRootDir() Assert.AreEqual(path, rootDirs.First().Path); } - [Test] - public void UpdateRootDir() + + [TestCase("D:\\TV Shows\\")] + [TestCase("//server//folder")] + public void UpdateRootDir(string newPath) { //Setup var mocker = new AutoMoqer(); mocker.SetConstant(MockLib.GetEmptyRepository()); - const string path = @"C:\TV2"; //Act var rootDirProvider = mocker.Resolve(); rootDirProvider.Add(new RootDir { Path = @"C:\TV" }); - rootDirProvider.Update(new RootDir { Id = 1, Path = path }); + rootDirProvider.Update(new RootDir { Id = 1, Path = newPath }); //Assert var rootDirs = rootDirProvider.GetAll(); Assert.IsNotEmpty(rootDirs); rootDirs.Should().HaveCount(1); - Assert.AreEqual(path, rootDirs.First().Path); + Assert.AreEqual(newPath, rootDirs.First().Path); } [Test] @@ -144,5 +144,25 @@ public void empty_folder_path_throws() var mocker = new AutoMoqer(); mocker.Resolve().GetUnmappedFolders(""); } + + [TestCase("")] + [TestCase(null)] + [TestCase("BAD PATH")] + [ExpectedException(typeof(ArgumentException))] + public void invalid_folder_path_throws_on_add(string path) + { + var mocker = new AutoMoqer(); + mocker.Resolve().Add(new RootDir { Id = 0, Path = path }); + } + + [TestCase("")] + [TestCase(null)] + [TestCase("BAD PATH")] + [ExpectedException(typeof(ArgumentException))] + public void invalid_folder_path_throws_on_update(string path) + { + var mocker = new AutoMoqer(); + mocker.Resolve().Update(new RootDir { Id = 2, Path = path }); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 9c1e1aee9..1bb341d20 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -11,15 +11,15 @@ namespace NzbDrone.Core.Providers { public class RootDirProvider { - private readonly IRepository _sonioRepo; + private readonly IRepository _repository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly DiskProvider _diskProvider; private readonly SeriesProvider _seriesProvider; - public RootDirProvider(IRepository sonicRepo, SeriesProvider seriesProvider, DiskProvider diskProvider) + public RootDirProvider(IRepository repository, SeriesProvider seriesProvider, DiskProvider diskProvider) { - _sonioRepo = sonicRepo; + _repository = repository; _diskProvider = diskProvider; _seriesProvider = seriesProvider; } @@ -28,27 +28,39 @@ public RootDirProvider(IRepository sonicRepo, SeriesProvider seriesProvider, Dis public virtual List GetAll() { - return _sonioRepo.All().ToList(); + return _repository.All().ToList(); } - public virtual int Add(RootDir rootDir) + public virtual void Add(RootDir rootDir) { - return Convert.ToInt32(_sonioRepo.Add(rootDir)); + ValidatePath(rootDir); + + _repository.Add(rootDir); } public virtual void Remove(int rootDirId) { - _sonioRepo.Delete(rootDirId); + _repository.Delete(rootDirId); } public virtual void Update(RootDir rootDir) { - _sonioRepo.Update(rootDir); + ValidatePath(rootDir); + + _repository.Update(rootDir); + } + + private static void ValidatePath(RootDir rootDir) + { + if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) + { + throw new ArgumentException("Invalid path"); + } } public virtual RootDir GetRootDir(int rootDirId) { - return _sonioRepo.Single(rootDirId); + return _repository.Single(rootDirId); } public List GetUnmappedFolders(string path) From c5c7e1eb76c7c5a05d33cc0d350250846a95b636 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 21:20:29 -0700 Subject: [PATCH 3/4] Fixed multi testcase tests. --- NzbDrone.Core.Test/EpisodeSearchJobTest.cs | 2 +- NzbDrone.Core.Test/EpisodeStatusTest.cs | 6 ++--- NzbDrone.Core.Test/IndexerTests.cs | 6 ++--- .../InventoryProvider_QualityNeededTest.cs | 23 +++++++++--------- NzbDrone.Core.Test/ParserTest.cs | 23 +++++++----------- NzbDrone.Core.Test/SabProviderTest.cs | 2 +- NzbDrone.Core.Test/SeriesProviderTest.cs | Bin 6332 -> 6325 bytes NzbDrone.Core/Providers/RootDirProvider.cs | 4 +-- 8 files changed, 29 insertions(+), 37 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs index 4c69d505c..1faab1de6 100644 --- a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs +++ b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs @@ -199,7 +199,7 @@ public void processResults_failed_download_should_not_check_the_rest() } - [Test] + [TestCase(0)] [TestCase(-1)] [TestCase(-100)] diff --git a/NzbDrone.Core.Test/EpisodeStatusTest.cs b/NzbDrone.Core.Test/EpisodeStatusTest.cs index 56bca1510..62ae0d2b1 100644 --- a/NzbDrone.Core.Test/EpisodeStatusTest.cs +++ b/NzbDrone.Core.Test/EpisodeStatusTest.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Core.Test // ReSharper disable InconsistentNaming public class EpisodeStatusTest : TestBase { - [Test] + [TestCase(1, false, false, EpisodeStatusType.NotAired)] [TestCase(-2, false, false, EpisodeStatusType.Missing)] [TestCase(1, true, false, EpisodeStatusType.Ready)] @@ -36,7 +36,6 @@ public void no_grab_date(int offsetDays, bool hasEpisodes, bool ignored, Episode } - [Test] [TestCase(1, false, false, EpisodeStatusType.Missing)] [TestCase(-2, false, false, EpisodeStatusType.Missing)] [TestCase(1, true, false, EpisodeStatusType.Ready)] @@ -59,7 +58,6 @@ public void old_grab_date(int offsetDays, bool hasEpisodes, bool ignored, } - [Test] [TestCase(1, false, false, EpisodeStatusType.Downloading)] [TestCase(-2, false, false, EpisodeStatusType.Downloading)] [TestCase(1, true, false, EpisodeStatusType.Downloading)] @@ -83,7 +81,7 @@ public void recent_grab_date(int offsetDays, bool hasEpisodes, bool ignored, Assert.AreEqual(status, episode.Status); } - [Test] + [TestCase(1, true, false, EpisodeStatusType.Ignored)] [TestCase(-2, true, false, EpisodeStatusType.Ignored)] [TestCase(1, true, true, EpisodeStatusType.Ready)] diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index 50ac36d16..fce620b40 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test // ReSharper disable InconsistentNaming public class IndexerTests : TestBase { - [Test] + [TestCase("nzbsorg.xml", 0)] [TestCase("nzbsrus.xml", 6)] [TestCase("newzbin.xml", 1)] @@ -90,7 +90,7 @@ public void newzbin_rss_fetch() ExceptionVerification.ExcpectedWarns(1); } - [Test] + [TestCase("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality) { @@ -117,7 +117,7 @@ public void custome_parser_partial_success(string title, int season, int episode Assert.AreEqual(quality, result.Quality.QualityType); } - [Test] + [TestCase("Adventure.Inc.DVDRip.XviD-OSiTV")] public void custome_parser_full_parse(string title) { diff --git a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs b/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs index bfb286f42..ca03ab27c 100644 --- a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs +++ b/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs @@ -205,18 +205,17 @@ public void IsQualityNeeded_file_not_in_history_should_be_downloaded() } //Should Download - [Test] - [TestCase(QualityTypes.SDTV, true, QualityTypes.HDTV, false, true)] - [TestCase(QualityTypes.DVD, true, QualityTypes.Bluray720p, true, true)] - [TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, true, true)] - [TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, false, false)] - [TestCase(QualityTypes.Bluray720p, true, QualityTypes.Bluray1080p, false, false)] - [TestCase(QualityTypes.HDTV, true, QualityTypes.Bluray720p, true, true)] - [TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, true, false)] - [TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, false, false)] - [TestCase(QualityTypes.Bluray1080p, false, QualityTypes.Bluray720p, true, false)] - [TestCase(QualityTypes.HDTV, false, QualityTypes.Bluray720p, true, true)] - [TestCase(QualityTypes.HDTV, true, QualityTypes.HDTV, false, false)] + [TestCase(QualityTypes.SDTV, true, QualityTypes.HDTV, false, true)] + [TestCase(QualityTypes.DVD, true, QualityTypes.Bluray720p, true, true)] + [TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, true, true)] + [TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, false, false)] + [TestCase(QualityTypes.Bluray720p, true, QualityTypes.Bluray1080p, false, false)] + [TestCase(QualityTypes.HDTV, true, QualityTypes.Bluray720p, true, true)] + [TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, true, false)] + [TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, false, false)] + [TestCase(QualityTypes.Bluray1080p, false, QualityTypes.Bluray720p, true, false)] + [TestCase(QualityTypes.HDTV, false, QualityTypes.Bluray720p, true, true)] + [TestCase(QualityTypes.HDTV, true, QualityTypes.HDTV, false, false)] public void Is_upgrade(QualityTypes fileQuality, bool isFileProper, QualityTypes reportQuality, bool isReportProper, bool excpected) { diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index eefe09956..62928349a 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -18,10 +18,6 @@ public class ParserTest : TestBase */ - - - - [Test] [TestCase("Sonny.With.a.Chance.S02E15", "Sonny.With.a.Chance", 2, 15)] [TestCase("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 3)] [TestCase("Two.and.a.Half.Me.113.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 13)] @@ -67,7 +63,6 @@ public void file_path_parse(string path, int season, int episode) } - [Test] [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD)] [TestCase("WEEDS.S03E01-06.DUAL.BDRip.X-viD.AC3.-HELLYWOOD", QualityTypes.DVD)] [TestCase("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.DVD)] @@ -127,7 +122,7 @@ public void parsing_our_own_quality_enum() } } - [Test] + [Timeout(1000)] [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, new[] { 1, 2, 3, 4, 5, 6 }, 6)] [TestCase("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Men", 1, new[] { 3, 4 }, 2)] @@ -135,7 +130,7 @@ public void parsing_our_own_quality_enum() [TestCase("The Borgias S01e01 e02 ShoHD On Demand 1080i DD5 1 ALANiS", "The Borgias", 1, new[] { 1, 2 }, 2)] [TestCase("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", "Big Time Rush", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 10)] [TestCase("White.Collar.2x04.2x05.720p.BluRay-FUTV", "White.Collar", 2, new[] { 4, 5 }, 2)] - [TestCase("Desperate.Housewives.S07E22E23.720p.HDTV.X264-DIMENSION", "Desperate.Housewives", 7, new[] { 22,23 }, 2)] + [TestCase("Desperate.Housewives.S07E22E23.720p.HDTV.X264-DIMENSION", "Desperate.Housewives", 7, new[] { 22, 23 }, 2)] //[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] { 1, 2 })] public void episode_multipart_parse(string postTitle, string title, int season, int[] episodes, int count) { @@ -147,7 +142,7 @@ public void episode_multipart_parse(string postTitle, string title, int season, Assert.AreEqual(count, result.EpisodeNumbers.Count); } - [Test] + [TestCase("Conan 2011 04 18 Emma Roberts HDTV XviD BFF", "Conan", 2011, 04, 18)] [TestCase("The Tonight Show With Jay Leno 2011 04 15 1080i HDTV DD5 1 MPEG2 TrollHD", "The Tonight Show With Jay Leno", 2011, 04, 15)] [TestCase("The.Daily.Show.2010.10.11.Johnny.Knoxville.iTouch-MW", "The.Daily.Show", 2010, 10, 11)] @@ -164,7 +159,7 @@ public void episode_daily_parse(string postTitle, string title, int year, int mo } - [Test] + [TestCase("30.Rock.Season.04.HDTV.XviD-DIMENSION", "30.Rock", 4)] [TestCase("Parks.and.Recreation.S02.720p.x264-DIMENSION", "Parks.and.Recreation", 2)] [TestCase("The.Office.US.S03.720p.x264-DIMENSION", "The.Office.US", 3)] @@ -176,7 +171,7 @@ public void full_season_release_parse(string postTitle, string title, int season Assert.AreEqual(0, result.EpisodeNumbers.Count); } - [Test] + [TestCase("Conan", "conan")] [TestCase("The Tonight Show With Jay Leno", "tonightshowwithjayleno")] [TestCase("The.Daily.Show", "dailyshow")] @@ -188,7 +183,7 @@ public void series_name_normalize(string parsedSeriesName, string seriesName) Assert.AreEqual(seriesName, result); } - [Test] + [TestCase(@"c:\test\", @"c:\test")] [TestCase(@"c:\\test\\", @"c:\test")] [TestCase(@"C:\\Test\\", @"C:\Test")] @@ -200,7 +195,7 @@ public void Normalize_Path(string dirty, string clean) Assert.AreEqual(clean, result); } - [Test] + [TestCase("CaPitAl", "capital")] [TestCase("peri.od", "period")] [TestCase("this.^&%^**$%@#$!That", "thisthat")] @@ -210,7 +205,7 @@ public void Normalize_Title(string dirty, string clean) Assert.AreEqual(clean, result); } - [Test] + [TestCase("the")] [TestCase("and")] [TestCase("or")] @@ -240,7 +235,7 @@ public void Normalize_removed_common_words(string word) } - [Test] + [TestCase("the")] [TestCase("and")] [TestCase("or")] diff --git a/NzbDrone.Core.Test/SabProviderTest.cs b/NzbDrone.Core.Test/SabProviderTest.cs index e0675fd89..0f7601ad0 100644 --- a/NzbDrone.Core.Test/SabProviderTest.cs +++ b/NzbDrone.Core.Test/SabProviderTest.cs @@ -259,7 +259,7 @@ public void IsInQueue_False_Error() mocker.Resolve().IsInQueue(String.Empty); } - [Test] + [TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title [DVD]")] [TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title [DVD] [Proper]")] [TestCase(1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x2 - [DVD] [Proper]")] diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index 48d7d8c1e967f701a6f083baa7e5b2703b443f0b..bd5086dd611b37e33b25d5f056ac2bb5f63a3dd9 100644 GIT binary patch delta 16 XcmdmExYclj0pH{}KC#WdeED1eG_(a? delta 16 XcmdmLxW{mV0pDa99)Zo4d^KDEGA;!T diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 1bb341d20..2e0baa4df 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -31,11 +31,11 @@ public virtual List GetAll() return _repository.All().ToList(); } - public virtual void Add(RootDir rootDir) + public virtual int Add(RootDir rootDir) { ValidatePath(rootDir); - _repository.Add(rootDir); + return (int)_repository.Add(rootDir); } public virtual void Remove(int rootDirId) From 5293d0e2042397cf00336c521b721c9a2fda7921 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 21:24:57 -0700 Subject: [PATCH 4/4] Fixed american dad's broken fix ;) --- NzbDrone.Core.Test/TvDbProviderTest.cs | 54 ++++++++++++++----------- NzbDrone.Core/Providers/TvDbProvider.cs | 2 +- 2 files changed, 31 insertions(+), 25 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 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 @@ public void successful_search(string title) result[0].SeriesName.Should().Be(title); } - [Test] [TestCase("The Simpsons")] [TestCase("Family Guy")] [TestCase("South Park")] @@ -37,7 +37,7 @@ public void successful_title_lookup(string title) } - [Test] + [TestCase(new object[] { "CAPITAL", "capital", true })] [TestCase(new object[] { "Something!!", "Something", true })] [TestCase(new object[] { "Simpsons 2000", "Simpsons", true })] @@ -94,18 +94,15 @@ public void American_dad_fix() //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 @@ public void American_dad_fix() } //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); + 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); + } + } - 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(); } } 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 @@ public virtual TvdbSeries GetSeries(int id, bool loadEpisodes) //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)