From 55cbc5988741dc9cbecd2104e90e2a4feb361444 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 14 Apr 2012 15:33:58 -0700 Subject: [PATCH] Fixed: Search failure is more friendly. Womble's Index is enabled by default. --- .../ProviderTests/IndexerProviderTest.cs | 89 +++++++++++++++++++ .../Providers/Indexer/IndexerBase.cs | 8 +- NzbDrone.Core/Providers/Indexer/Wombles.cs | 5 ++ NzbDrone.Core/Providers/IndexerProvider.cs | 2 +- NzbDrone.Core/Providers/SearchProvider.cs | 2 +- 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs index edd955864..f8aed279b 100644 --- a/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs @@ -60,6 +60,38 @@ namespace NzbDrone.Core.Test.ProviderTests indexerProvider.All().Should().HaveCount(1); indexerProvider.GetEnabledIndexers().Should().BeEmpty(); } + + [Test] + public void Init_indexer_should_enable_indexer_that_is_enabled_by_default() + { + Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); + + //Act + var indexerProvider = Mocker.Resolve(); + indexerProvider.InitializeIndexers(new List { Mocker.Resolve() }); + + //Assert + indexerProvider.All(); + indexerProvider.All().Should().HaveCount(1); + indexerProvider.GetEnabledIndexers().Should().HaveCount(1); + indexerProvider.GetSettings(typeof(DefaultEnabledIndexer)).Enable.Should().BeTrue(); + } + + [Test] + public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default() + { + Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); + + //Act + var indexerProvider = Mocker.Resolve(); + indexerProvider.InitializeIndexers(new List { Mocker.Resolve() }); + + //Assert + indexerProvider.All(); + indexerProvider.All().Should().HaveCount(1); + indexerProvider.GetEnabledIndexers().Should().HaveCount(0); + indexerProvider.GetSettings(typeof(MockIndexer)).Enable.Should().BeFalse(); + } } public class MockIndexer : IndexerBase @@ -267,4 +299,61 @@ namespace NzbDrone.Core.Test.ProviderTests } } + public class DefaultEnabledIndexer : IndexerBase + { + public DefaultEnabledIndexer(HttpProvider httpProvider, ConfigProvider configProvider) + : base(httpProvider, configProvider) + { + } + + protected override string[] Urls + { + get { return new[] { "www.google.com" }; } + } + + public override bool IsConfigured + { + get { return true; } + } + + protected override NetworkCredential Credentials + { + get { return null; } + } + + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) + { + throw new NotImplementedException(); + } + + protected override IList GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date) + { + throw new NotImplementedException(); + } + + protected override IList GetSeasonSearchUrls(string seriesTitle, int seasonNumber) + { + throw new NotImplementedException(); + } + + protected override IList GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard) + { + throw new NotImplementedException(); + } + + public override string Name + { + get { return "Mocked Indexer"; } + } + + + protected override string NzbDownloadUrl(SyndicationItem item) + { + return item.Links[0].Uri.ToString(); + } + public override bool EnabledByDefault + { + get { return true; } + } + } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 73c7136cc..92f08a3b2 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -45,9 +45,15 @@ namespace NzbDrone.Core.Providers.Indexer /// protected abstract string[] Urls { get; } - public abstract bool IsConfigured { get; } + /// + /// Should the indexer be enabled by default? + /// + public virtual bool EnabledByDefault + { + get { return false; } + } /// /// Gets the credential. diff --git a/NzbDrone.Core/Providers/Indexer/Wombles.cs b/NzbDrone.Core/Providers/Indexer/Wombles.cs index a473ef064..efbb35e4f 100644 --- a/NzbDrone.Core/Providers/Indexer/Wombles.cs +++ b/NzbDrone.Core/Providers/Indexer/Wombles.cs @@ -75,5 +75,10 @@ namespace NzbDrone.Core.Providers.Indexer return currentResult; } + + public override bool EnabledByDefault + { + get { return true; } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/IndexerProvider.cs b/NzbDrone.Core/Providers/IndexerProvider.cs index ef6550ca2..3ff70d824 100644 --- a/NzbDrone.Core/Providers/IndexerProvider.cs +++ b/NzbDrone.Core/Providers/IndexerProvider.cs @@ -73,7 +73,7 @@ namespace NzbDrone.Core.Providers { var settings = new IndexerDefinition { - Enable = false, + Enable = indexerLocal.EnabledByDefault, IndexProviderType = indexerLocal.GetType().ToString(), Name = indexerLocal.Name }; diff --git a/NzbDrone.Core/Providers/SearchProvider.cs b/NzbDrone.Core/Providers/SearchProvider.cs index c978aa3f1..1e4ea8a5f 100644 --- a/NzbDrone.Core/Providers/SearchProvider.cs +++ b/NzbDrone.Core/Providers/SearchProvider.cs @@ -163,7 +163,7 @@ namespace NzbDrone.Core.Providers if (reports.Any()) { - notification.CurrentMessage = String.Format("Sorry, couldn't find {0} in a non-sucky quality. (by your standards)", episode); + notification.CurrentMessage = String.Format("Sorry, couldn't find {0}, that matches your preferences.", episode); } else {