using System; using System.Collections.Generic; using System.Linq; using System.Text; using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.ProviderTests.SearchTests { public class PerformSearchTestBase : TestBase { protected Series _series; protected Episode _episode; protected List _episodes; protected ProgressNotification notification = new ProgressNotification("Testing"); protected Mock _indexer1; protected Mock _indexer2; protected List _indexers; protected IList _parseResults; [SetUp] public void Setup() { _series = Builder .CreateNew() .Build(); _episode = Builder .CreateNew() .With(e => e.SeriesId = _series.SeriesId) .With(e => e.Series = _series) .Build(); _episodes = Builder .CreateListOfSize(10) .All() .With(e => e.SeriesId = _series.SeriesId) .With(e => e.Series = _series) .Build() .ToList(); _parseResults = Builder .CreateListOfSize(10) .Build(); _indexer1 = new Mock(); _indexer2 = new Mock(); _indexers = new List { _indexer1.Object, _indexer2.Object }; Mocker.GetMock() .Setup(c => c.GetEnabledIndexers()) .Returns(_indexers); } protected void WithValidIndexers() { _indexer1.Setup(c => c.FetchEpisode(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_parseResults); _indexer1.Setup(c => c.FetchDailyEpisode(It.IsAny(), It.IsAny())) .Returns(_parseResults); _indexer1.Setup(c => c.FetchPartialSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_parseResults); _indexer2.Setup(c => c.FetchEpisode(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_parseResults); _indexer2.Setup(c => c.FetchDailyEpisode(It.IsAny(), It.IsAny())) .Returns(_parseResults); _indexer2.Setup(c => c.FetchPartialSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_parseResults); } protected void WithInvalidIndexers() { _indexer1.Setup(c => c.FetchEpisode(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer1.Setup(c => c.FetchDailyEpisode(It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer1.Setup(c => c.FetchPartialSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer2.Setup(c => c.FetchEpisode(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer2.Setup(c => c.FetchDailyEpisode(It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer2.Setup(c => c.FetchPartialSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(new Exception()); _indexer1.SetupGet(c => c.Name).Returns("Indexer1"); _indexer1.SetupGet(c => c.Name).Returns("Indexer2"); } } }