1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-29 11:05:44 +00:00
Lidarr/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs

278 lines
9.1 KiB
C#
Raw Normal View History

2013-03-02 18:25:39 +00:00
/*
2013-03-28 22:07:09 +00:00
using System;
2011-06-22 01:12:20 +00:00
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Tv;
2011-06-22 01:12:20 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
2011-06-22 01:12:20 +00:00
namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests
2011-06-22 01:12:20 +00:00
{
[TestFixture]
2013-03-28 22:07:09 +00:00
2013-03-02 18:25:39 +00:00
public class EpisodeProviderTest_GetEpisodesByParseResult : ObjectDbTest
2011-06-22 01:12:20 +00:00
{
private IEpisodeService episodeService;
2011-06-22 01:12:20 +00:00
private Series fakeSeries;
private Series fakeDailySeries;
2011-06-22 01:12:20 +00:00
private Episode fakeEpisode;
private Episode fakeDailyEpisode;
private Episode fakeEpisode2;
2011-06-22 01:12:20 +00:00
[SetUp]
public void Setup()
2011-06-22 01:12:20 +00:00
{
fakeSeries = Builder<Series>.CreateNew().Build();
2011-06-22 01:12:20 +00:00
fakeDailySeries = Builder<Series>.CreateNew()
.With(c => c.SeriesType = SeriesType.Daily)
.Build();
2011-06-22 01:12:20 +00:00
fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = fakeSeries.Id)
.With(e => e.Title = "Episode (1)")
.Build();
2011-06-22 01:12:20 +00:00
fakeEpisode2 = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = fakeSeries.Id)
.With(e => e.SeasonNumber = fakeEpisode.SeasonNumber)
.With(e => e.EpisodeNumber = fakeEpisode.EpisodeNumber + 1)
.With(e => e.Title = "Episode (2)")
.Build();
2011-06-22 01:12:20 +00:00
fakeDailyEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = fakeSeries.Id)
.With(e => e.AirDate = DateTime.Now.Date)
.With(e => e.Title = "Daily Episode 1")
.Build();
2011-06-22 01:12:20 +00:00
2013-03-02 18:25:39 +00:00
episodeService = Mocker.Resolve<EpisodeService>();
2011-06-22 01:12:20 +00:00
}
[Test]
public void existing_single_episode_should_return_single_existing_episode()
2011-06-22 01:12:20 +00:00
{
Db.Insert(fakeEpisode);
Db.Insert(fakeSeries);
2011-06-22 01:12:20 +00:00
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
2011-12-01 19:05:17 +00:00
};
2011-06-22 01:12:20 +00:00
var ep = episodeService.GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(1);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
VerifyEpisode(ep[0], fakeEpisode);
2013-03-02 18:25:39 +00:00
Db<Episode>().Should().HaveCount(1);
2011-06-22 01:12:20 +00:00
}
[Test]
public void single_none_existing_episode_should_return_nothing_and_add_nothing()
2011-06-22 01:12:20 +00:00
{
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { 10 }
2011-12-01 19:05:17 +00:00
};
2011-06-22 01:12:20 +00:00
var episode = episodeService.GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
episode.Should().BeEmpty();
Db.Fetch<Episode>().Should().HaveCount(0);
2011-06-22 01:12:20 +00:00
}
[Test]
public void single_none_existing_series_should_return_nothing_and_add_nothing()
2011-06-22 01:12:20 +00:00
{
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 10,
EpisodeNumbers = new List<int> { 10 }
};
2011-06-22 01:12:20 +00:00
var episode = episodeService.GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
episode.Should().BeEmpty();
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(0);
2011-06-22 01:12:20 +00:00
}
[Test]
public void existing_multi_episode_should_return_all_episodes()
2011-06-22 01:12:20 +00:00
{
Db.Insert(fakeSeries);
Db.Insert(fakeEpisode);
Db.Insert(fakeEpisode2);
2011-06-22 01:12:20 +00:00
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
2011-12-01 19:05:17 +00:00
};
2011-06-22 01:12:20 +00:00
var ep = episodeService.GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(2);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(2);
VerifyEpisode(ep[0], fakeEpisode);
VerifyEpisode(ep[1], fakeEpisode2);
parseResult.EpisodeTitle.Should().Be("Episode");
}
[Test]
public void none_existing_multi_episode_should_not_return_or_add_anything()
{
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
};
var ep = episodeService.GetEpisodesByParseResult(parseResult);
ep.Should().BeEmpty();
Db.Fetch<Episode>().Should().BeEmpty();
}
[Test]
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_null()
{
2013-03-28 22:07:09 +00:00
var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult());
2013-03-28 22:07:09 +00:00
episodes.Should().NotBeNull();
episodes.Should().BeEmpty();
}
[Test]
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_empty()
{
2013-03-28 22:07:09 +00:00
var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { EpisodeNumbers = new List<int>() });
2013-03-28 22:07:09 +00:00
episodes.Should().NotBeNull();
episodes.Should().BeEmpty();
}
[Test]
public void should_return_single_episode_when_air_date_is_provided()
{
2011-12-01 01:10:36 +00:00
Db.Insert(fakeSeries);
Db.Insert(fakeDailyEpisode);
2013-03-28 22:07:09 +00:00
var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries });
2013-03-28 22:07:09 +00:00
episodes.Should().HaveCount(1);
VerifyEpisode(episodes[0], fakeDailyEpisode);
2011-12-01 01:10:36 +00:00
Db.Fetch<Episode>().Should().HaveCount(1);
}
2011-12-01 19:05:17 +00:00
[Test]
public void should_not_add_episode_when_episode_doesnt_exist()
2011-12-01 19:05:17 +00:00
{
var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries });
2011-12-01 19:05:17 +00:00
2013-03-28 22:07:09 +00:00
episodes.Should().HaveCount(0);
Db.Fetch<Episode>().Should().HaveCount(0);
2011-12-01 19:05:17 +00:00
}
[Test]
public void GetEpisodeParseResult_should_return_single_title_for_multiple_episodes()
{
Db.Insert(fakeSeries);
Db.Insert(fakeEpisode);
Db.Insert(fakeEpisode2);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
};
var ep = episodeService.GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(2);
Db.Fetch<Episode>().Should().HaveCount(2);
VerifyEpisode(ep[0], fakeEpisode);
VerifyEpisode(ep[1], fakeEpisode2);
parseResult.EpisodeTitle.Should().Be("Episode");
}
[Test]
public void GetEpisodeParseResult_should_return_single_title_for_single_episode()
{
Db.Insert(fakeEpisode);
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = fakeEpisode.SeasonNumber,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
};
var ep = episodeService.GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(1);
Db.Fetch<Episode>().Should().HaveCount(1);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
}
[Test]
public void GetEpisodeParseResult_should_return_nothing_when_series_is_not_daily_but_parsed_daily()
{
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
AirDate = DateTime.Today
};
var ep = episodeService.GetEpisodesByParseResult(parseResult);
ep.Should().BeEmpty();
ExceptionVerification.ExpectedWarns(1);
}
private void VerifyEpisode(Episode actual, Episode excpected)
{
actual.ShouldHave().AllProperties().But(e => e.Series).But(e => e.EpisodeFile).EqualTo(excpected);
}
2011-06-22 01:12:20 +00:00
}
2011-12-01 19:05:17 +00:00
}
2013-03-02 18:25:39 +00:00
*/