// ReSharper disable RedundantUsingDirective using System; using System.Collections.Generic; using System.Net; using System.ServiceModel.Syndication; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Providers; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.Indexers { [TestFixture] // ReSharper disable InconsistentNaming public class IndexerServiceTest : CoreTest { [Test] public void should_insert_indexer_in_repository_when_it_doesnt_exist() { Mocker.SetConstant>(new List { Mocker.Resolve() }); Subject.Init(); Mocker.GetMock() .Verify(v => v.Insert(It.IsAny()), Times.Once()); } [Test] public void getEnabled_should_not_return_any_when_no_indexers_are_enabled() { Mocker.SetConstant>(new List { Mocker.Resolve() }); Mocker.GetMock() .Setup(s => s.All()) .Returns(new List {new Indexer {OID = 1, Type = "", Enable = false, Name = "Fake Indexer"}}); Subject.GetEnabledIndexers().Should().BeEmpty(); } [Test] public void Init_indexer_should_enable_indexer_that_is_enabled_by_default() { Mocker.SetConstant>(new List { Mocker.Resolve() }); Subject.Init(); Mocker.GetMock() .Verify(v => v.Insert(It.Is(indexer => indexer.Enable)), Times.Once()); Mocker.GetMock() .Verify(v => v.Insert(It.Is(indexer => !indexer.Enable)), Times.Never()); } [Test] public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default() { Mocker.SetConstant>(new List { Mocker.Resolve() }); Subject.Init(); Mocker.GetMock() .Verify(v => v.Insert(It.Is(indexer => indexer.Enable)), Times.Never()); Mocker.GetMock() .Verify(v => v.Insert(It.Is(indexer => !indexer.Enable)), Times.Once()); } } public class MockIndexer : IndexerBase { public MockIndexer(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(); } protected override string NzbInfoUrl(SyndicationItem item) { return item.Links[0].Uri.ToString(); } } public class TestUrlIndexer : IndexerBase { public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider) : base(httpProvider, configProvider) { } public override string Name { get { return "All Urls"; } } protected override string[] Urls { get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; } } public override bool IsConfigured { get { return true; } } 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(); } protected override string NzbDownloadUrl(SyndicationItem item) { return "http://google.com"; } protected override string NzbInfoUrl(SyndicationItem item) { return "http://google.com"; } } public class CustomParserIndexer : IndexerBase { public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider) : base(httpProvider, configProvider) { } public override string Name { get { return "Custom parser"; } } protected override string[] Urls { get { return new[] { "http://www.google.com" }; } } public override bool IsConfigured { get { return true; } } 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(); } protected override string NzbDownloadUrl(SyndicationItem item) { return "http://www.google.com"; } protected override string NzbInfoUrl(SyndicationItem item) { return "http://www.google.com"; } protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult) { if (currentResult == null) currentResult = new EpisodeParseResult(); currentResult.Language = LanguageType.Finnish; return currentResult; } } public class NotConfiguredIndexer : IndexerBase { public NotConfiguredIndexer(HttpProvider httpProvider, ConfigProvider configProvider) : base(httpProvider, configProvider) { } public override string Name { get { return "NotConfiguredIndexer"; } } protected override string[] Urls { get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; } } public override bool IsConfigured { get { return false; } } 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(); } protected override string NzbDownloadUrl(SyndicationItem item) { throw new NotImplementedException(); } protected override string NzbInfoUrl(SyndicationItem item) { throw new NotImplementedException(); } } 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(); } protected override string NzbInfoUrl(SyndicationItem item) { return item.Links[1].Uri.ToString(); } public override bool EnabledByDefault { get { return true; } } } }