2013-03-07 03:45:36 +00:00
|
|
|
using System;
|
2013-01-13 08:24:48 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2013-03-07 03:45:36 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch;
|
2013-02-21 07:07:34 +00:00
|
|
|
using NzbDrone.Core.Indexers;
|
2013-01-13 08:24:48 +00:00
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2013-03-07 03:45:36 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
2013-03-07 03:45:36 +00:00
|
|
|
namespace NzbDrone.Core.Test.IndexerSearchTests
|
2013-01-13 08:24:48 +00:00
|
|
|
{
|
2013-03-07 03:45:36 +00:00
|
|
|
public abstract class IndexerSearchTestBase<TSearch> : CoreTest<TSearch>
|
|
|
|
where TSearch : SearchBase
|
2013-01-13 08:24:48 +00:00
|
|
|
{
|
|
|
|
protected Series _series;
|
|
|
|
protected Episode _episode;
|
|
|
|
protected ProgressNotification notification = new ProgressNotification("Testing");
|
|
|
|
|
|
|
|
protected Mock<IndexerBase> _indexer1;
|
|
|
|
protected Mock<IndexerBase> _indexer2;
|
|
|
|
protected List<IndexerBase> _indexers;
|
|
|
|
protected IList<EpisodeParseResult> _parseResults;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
_series = Builder<Series>
|
|
|
|
.CreateNew()
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
_episode = Builder<Episode>
|
|
|
|
.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
.With(e => e.SeriesId = _series.Id)
|
2013-01-13 08:24:48 +00:00
|
|
|
.With(e => e.Series = _series)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
_parseResults = Builder<EpisodeParseResult>
|
|
|
|
.CreateListOfSize(10)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
_indexer1 = new Mock<IndexerBase>();
|
|
|
|
_indexer2 = new Mock<IndexerBase>();
|
|
|
|
_indexers = new List<IndexerBase> { _indexer1.Object, _indexer2.Object };
|
|
|
|
|
2013-02-21 07:07:34 +00:00
|
|
|
Mocker.GetMock<IIndexerService>()
|
2013-01-13 08:24:48 +00:00
|
|
|
.Setup(c => c.GetEnabledIndexers())
|
|
|
|
.Returns(_indexers);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void WithValidIndexers()
|
|
|
|
{
|
|
|
|
_indexer1.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
_indexer1.Setup(c => c.FetchDailyEpisode(It.IsAny<string>(), It.IsAny<DateTime>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
_indexer1.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
|
|
|
|
_indexer2.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
_indexer2.Setup(c => c.FetchDailyEpisode(It.IsAny<string>(), It.IsAny<DateTime>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
_indexer2.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Returns(_parseResults);
|
|
|
|
}
|
|
|
|
|
2013-03-07 03:45:36 +00:00
|
|
|
protected void WithBrokenIndexers()
|
2013-01-13 08:24:48 +00:00
|
|
|
{
|
|
|
|
_indexer1.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
_indexer1.Setup(c => c.FetchDailyEpisode(It.IsAny<string>(), It.IsAny<DateTime>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
_indexer1.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
|
|
|
|
_indexer2.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
_indexer2.Setup(c => c.FetchDailyEpisode(It.IsAny<string>(), It.IsAny<DateTime>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
_indexer2.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
|
|
|
.Throws(new Exception());
|
|
|
|
|
|
|
|
_indexer1.SetupGet(c => c.Name).Returns("Indexer1");
|
|
|
|
_indexer1.SetupGet(c => c.Name).Returns("Indexer2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|