Cleaned up units tests.

pull/4/head
Mark McDowall 13 years ago
parent b36dc4ab86
commit 5522466497

@ -50,37 +50,37 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
{ {
_episodeIndexer1 = new Mock<IndexerBase>(); _episodeIndexer1 = new Mock<IndexerBase>();
_episodeIndexer1.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _episodeIndexer1.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_episodeIndexer2 = new Mock<IndexerBase>(); _episodeIndexer2 = new Mock<IndexerBase>();
_episodeIndexer2.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _episodeIndexer2.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_seasonIndexer1 = new Mock<IndexerBase>(); _seasonIndexer1 = new Mock<IndexerBase>();
_seasonIndexer1.Setup(c => c.FetchSeason(It.IsAny<string>(), It.IsAny<int>())) _seasonIndexer1.Setup(c => c.FetchSeason(It.IsAny<string>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_seasonIndexer2 = new Mock<IndexerBase>(); _seasonIndexer2 = new Mock<IndexerBase>();
_seasonIndexer2.Setup(c => c.FetchSeason(It.IsAny<string>(), It.IsAny<int>())) _seasonIndexer2.Setup(c => c.FetchSeason(It.IsAny<string>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_partialSeasonIndexer1 = new Mock<IndexerBase>(); _partialSeasonIndexer1 = new Mock<IndexerBase>();
_partialSeasonIndexer1.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _partialSeasonIndexer1.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_partialSeasonIndexer2 = new Mock<IndexerBase>(); _partialSeasonIndexer2 = new Mock<IndexerBase>();
_partialSeasonIndexer2.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _partialSeasonIndexer2.Setup(c => c.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(_parseResults).Verifiable(); .Returns(_parseResults);
_brokenIndexer = new Mock<IndexerBase>(); _brokenIndexer = new Mock<IndexerBase>();
_brokenIndexer.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _brokenIndexer.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Throws(new Exception()).Verifiable(); .Throws(new Exception());
List<EpisodeParseResult> nullResult = null; List<EpisodeParseResult> nullResult = null;
_nullIndexer = new Mock<IndexerBase>(); _nullIndexer = new Mock<IndexerBase>();
_nullIndexer.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) _nullIndexer.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(nullResult).Verifiable(); .Returns(nullResult);
} }
private void WithEpisodeIndexers() private void WithEpisodeIndexers()
@ -151,6 +151,39 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
_episodes = null; _episodes = null;
} }
private void VerifyFetchEpisode(Times times)
{
_episodeIndexer1.Verify(v => v.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, times);
_episodeIndexer2.Verify(v => v.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, times);
}
private void VerifyFetchEpisodeBrokenIndexer(Times times)
{
_brokenIndexer.Verify(v => v.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, times);
}
private void VerifyFetchPartialSeason(Times times)
{
_partialSeasonIndexer1.Verify(v => v.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, times);
_partialSeasonIndexer2.Verify(v => v.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, times);
}
private void VerifyFetchSeason(Times times)
{
_seasonIndexer1.Verify(v => v.FetchSeason(It.IsAny<string>(), It.IsAny<int>())
, times);
_seasonIndexer1.Verify(v => v.FetchSeason(It.IsAny<string>(), It.IsAny<int>())
, times);
}
[Test] [Test]
public void PerformSearch_should_search_all_enabled_providers() public void PerformSearch_should_search_all_enabled_providers()
{ {
@ -162,9 +195,8 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
var result = Mocker.Resolve<SearchProvider>().PerformSearch(new ProgressNotification("Test"), _series, 1, _episodes); var result = Mocker.Resolve<SearchProvider>().PerformSearch(new ProgressNotification("Test"), _series, 1, _episodes);
//Assert //Assert
VerifyFetchEpisode(Times.Once());
result.Should().HaveCount(20); result.Should().HaveCount(20);
_episodeIndexer1.VerifyAll();
_episodeIndexer1.VerifyAll();
} }
[Test] [Test]
@ -179,10 +211,6 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
var result = Mocker.Resolve<SearchProvider>().PerformSearch(new ProgressNotification("Test"), _series, 1, _episodes); var result = Mocker.Resolve<SearchProvider>().PerformSearch(new ProgressNotification("Test"), _series, 1, _episodes);
//Assert //Assert
result.Should().HaveCount(20);
_episodeIndexer1.VerifyAll();
_episodeIndexer2.VerifyAll();
Mocker.GetMock<SceneMappingProvider>().Verify(c => c.GetSceneName(It.IsAny<int>()), Mocker.GetMock<SceneMappingProvider>().Verify(c => c.GetSceneName(It.IsAny<int>()),
Times.Once()); Times.Once());
} }
@ -200,9 +228,8 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert //Assert
result.Should().HaveCount(20); result.Should().HaveCount(20);
ExceptionVerification.ExcpectedErrors(1); ExceptionVerification.ExcpectedErrors(1);
_episodeIndexer1.VerifyAll(); VerifyFetchEpisode(Times.Once());
_episodeIndexer2.VerifyAll(); VerifyFetchEpisodeBrokenIndexer(Times.Once());
_brokenIndexer.VerifyAll();
Mocker.GetMock<SceneMappingProvider>().Verify(c => c.GetSceneName(It.IsAny<int>()), Mocker.GetMock<SceneMappingProvider>().Verify(c => c.GetSceneName(It.IsAny<int>()),
Times.Once()); Times.Once());
@ -221,11 +248,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert //Assert
result.Should().HaveCount(20); result.Should().HaveCount(20);
_episodeIndexer1.Verify(v => v.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()) VerifyFetchEpisode(Times.Once());
, Times.Once());
_episodeIndexer2.Verify(v => v.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, Times.Once());
} }
[Test] [Test]
@ -240,12 +263,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert //Assert
result.Should().HaveCount(80); result.Should().HaveCount(80);
VerifyFetchPartialSeason(Times.Exactly(4));
_partialSeasonIndexer1.Verify(v => v.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, Times.Exactly(4));
_partialSeasonIndexer2.Verify(v => v.FetchPartialSeason(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())
, Times.Exactly(4));
} }
[Test] [Test]
@ -260,12 +278,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert //Assert
result.Should().HaveCount(20); result.Should().HaveCount(20);
VerifyFetchSeason(Times.Once());
_seasonIndexer1.Verify(v => v.FetchSeason(It.IsAny<string>(), It.IsAny<int>())
, Times.Once());
_seasonIndexer1.Verify(v => v.FetchSeason(It.IsAny<string>(), It.IsAny<int>())
, Times.Once());
} }
[Test] [Test]

Loading…
Cancel
Save