Added tests for TvRageMappingProvider

pull/4/head
Mark McDowall 12 years ago
parent 253426873c
commit 6a5b69ae5a

@ -139,6 +139,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
<Compile Include="ProviderTests\TvRageMappingProviderTests\ProcessResultsFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\GetSeriesFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\ParseDayOfWeekFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\GetUtcOffsetFixture.cs" />
<Compile Include="ProviderTests\TvRageProviderTests\SearchSeriesFixture.cs" />
@ -331,6 +334,12 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Files\TvRage\SeriesInfo_empty.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SeriesInfo_one.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\TvRage\SearchResults_one.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model.TvRage;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests
{
public class FindMatchingTvRageSeriesFixture : TestBase
{
private IList<TvRageSearchResult> _searchResults;
private Series _series;
private Episode _episode;
private TvRageSeries _tvRageSeries;
[SetUp]
public void Setup()
{
_searchResults = Builder<TvRageSearchResult>
.CreateListOfSize(5)
.Build();
_series = Builder<Series>
.CreateNew()
.With(s => s.TvRageId = 0)
.With(s => s.TvRageTitle = null)
.With(s => s.UtcOffset = 0)
.Build();
_episode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
_tvRageSeries = Builder<TvRageSeries>
.CreateNew()
.With(s => s.UtcOffset = -8)
.Build();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisode(_series.SeriesId, 1, 1))
.Returns(_episode);
Mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetCleanName(_series.SeriesId))
.Returns("");
Mocker.GetMock<TvRageProvider>()
.Setup(s => s.SearchSeries(_series.Title))
.Returns(_searchResults);
Mocker.GetMock<TvRageProvider>()
.Setup(s => s.GetSeries(_searchResults.First().ShowId))
.Returns(_tvRageSeries);
}
private void WithMatchingResult()
{
_series.CleanTitle = Parser.NormalizeTitle(_searchResults.First().Name);
}
[Test]
public void should_not_set_tvRage_info_when_result_is_null()
{
var result = Mocker.Resolve<TvRageMappingProvider>()
.FindMatchingTvRageSeries(_series);
result.TvRageId.Should().Be(0);
result.TvRageTitle.Should().Be(null);
result.UtcOffset.Should().Be(0);
}
[Test]
public void should_set_tvRage_info_when_result_is_returned()
{
WithMatchingResult();
var result = Mocker.Resolve<TvRageMappingProvider>()
.FindMatchingTvRageSeries(_series);
result.TvRageId.Should().Be(_searchResults.First().ShowId);
result.TvRageTitle.Should().Be(_searchResults.First().Name);
result.UtcOffset.Should().Be(_tvRageSeries.UtcOffset);
}
}
}

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model.TvRage;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests
{
public class ProcessResultsFixture : TestBase
{
private IList<TvRageSearchResult> _searchResults;
private Series _series;
private Episode _episode;
[SetUp]
public void Setup()
{
_searchResults = Builder<TvRageSearchResult>
.CreateListOfSize(5)
.Build();
_series = Builder<Series>.CreateNew().Build();
_episode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
}
[Test]
public void should_return_null_if_no_match_is_found()
{
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.BeNull();
}
[Test]
public void should_return_result_if_series_clean_name_matches()
{
_series.CleanTitle = Parser.NormalizeTitle(_searchResults.First().Name);
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.Be(_searchResults.First());
}
[Test]
public void should_return_result_if_scene_clean_name_matches()
{
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, Parser.NormalizeTitle(_searchResults.First().Name), _episode)
.Should()
.Be(_searchResults.First());
}
[Test]
public void should_return_result_if_firstAired_matches()
{
_episode.AirDate = _searchResults.Last().Started;
Mocker.Resolve<TvRageMappingProvider>()
.ProcessResults(_searchResults, _series, "nomatchhere", _episode)
.Should()
.Be(_searchResults.Last());
}
}
}
Loading…
Cancel
Save