1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00

Cleaned up units tests.

This commit is contained in:
Mark McDowall 2011-11-17 19:25:16 -08:00
parent b36dc4ab86
commit 5522466497

View file

@ -50,37 +50,37 @@ private void BuildIndexers()
{ {
_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 @@ private void WithNullEpisodes()
_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 @@ public void PerformSearch_should_search_all_enabled_providers()
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 @@ public void PerformSearch_should_look_for_scene_name_to_search()
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 @@ public void PerformSearch_broken_indexer_should_not_break_job()
//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 @@ public void PerformSearch_for_episode_should_call_FetchEpisode()
//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 @@ public void PerformSearch_for_partial_season_should_call_FetchPartialSeason()
//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 @@ public void PerformSearch_for_season_should_call_FetchSeason()
//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]