From a16defc5f0dc8bbc102fd8e4ea544c2819d319ca Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 4 May 2012 09:26:25 -0700 Subject: [PATCH] Newznab won't blow up if more than one indexer with the same URL is found during initialization. --- .../ProviderTests/NewznabProviderTest.cs | 23 +++++++++++++++++++ NzbDrone.Core/Providers/NewznabProvider.cs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs index 94daaa82b..3d94e97b4 100644 --- a/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs @@ -272,5 +272,28 @@ namespace NzbDrone.Core.Test.ProviderTests result.Should().HaveCount(1); result.First().BuiltIn.Should().BeTrue(); } + + [Test] + public void InitializeNewznabIndexers_should_not_blow_up_if_more_than_one_indexer_with_the_same_url_is_found() + { + //Setup + var definition = Builder.CreateNew() + .With(d => d.Url = "http://www.nzbdrone2.com") + .With(d => d.BuiltIn = false) + .Build(); + + var db = TestDbHelper.GetEmptyDatabase(); + Mocker.SetConstant(db); + + db.Insert(definition); + db.Insert(definition); + + //Act + Mocker.Resolve().InitializeNewznabIndexers(new List { definition }); + + //Assert + var result = db.Fetch(); + result.Should().HaveCount(2); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/NewznabProvider.cs b/NzbDrone.Core/Providers/NewznabProvider.cs index 7f69b587c..efb1e89f5 100644 --- a/NzbDrone.Core/Providers/NewznabProvider.cs +++ b/NzbDrone.Core/Providers/NewznabProvider.cs @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Providers { NewznabDefinition indexerLocal = feedProvider; var currentIndexer = currentIndexers - .SingleOrDefault(c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host); + .FirstOrDefault(c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host); if (currentIndexer == null) {