2011-06-22 03:12:20 +02:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-21 01:42:17 +02:00
|
|
|
|
|
2011-11-24 09:28:20 +01:00
|
|
|
|
using System;
|
2011-06-22 03:12:20 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-12-20 01:45:47 +01:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-10-17 09:56:07 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 21:54:03 +01:00
|
|
|
|
public class EpisodeProviderTest_GetEpisodesByParseResult : SqlCeTest
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
2012-01-06 22:25:27 +01:00
|
|
|
|
private EpisodeProvider episodeProvider;
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
private Series fakeSeries;
|
|
|
|
|
private Series fakeDailySeries;
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
private Episode fakeEpisode;
|
|
|
|
|
private Episode fakeDailyEpisode;
|
|
|
|
|
private Episode fakeEpisode2;
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
2012-01-06 22:25:27 +01:00
|
|
|
|
fakeSeries = Builder<Series>.CreateNew().Build();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
fakeDailySeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.IsDaily = true)
|
|
|
|
|
.Build();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
2012-02-03 07:49:34 +01:00
|
|
|
|
.With(e => e.Title = "Episode (1)")
|
2012-01-06 22:25:27 +01:00
|
|
|
|
.Build();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
fakeEpisode2 = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(e => e.SeasonNumber = fakeEpisode.SeasonNumber)
|
|
|
|
|
.With(e => e.EpisodeNumber = fakeEpisode.EpisodeNumber + 1)
|
2012-02-03 07:49:34 +01:00
|
|
|
|
.With(e => e.Title = "Episode (2)")
|
2012-01-06 22:25:27 +01:00
|
|
|
|
.Build();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
fakeDailyEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(e => e.AirDate = DateTime.Now.Date)
|
|
|
|
|
.With(e => e.Title = "Daily Episode 1")
|
|
|
|
|
.Build();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
episodeProvider = Mocker.Resolve<EpisodeProvider>();
|
2011-06-22 03:12:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void existing_single_episode_should_return_single_existing_episode()
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
2012-01-06 22:25:27 +01:00
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
Db.Insert(fakeSeries);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
2011-12-01 20:05:17 +01:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2012-01-06 22:25:27 +01:00
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
|
|
|
|
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
|
2011-12-01 20:05:17 +01:00
|
|
|
|
};
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
|
|
|
|
ep.Should().HaveCount(1);
|
2012-01-06 22:25:27 +01:00
|
|
|
|
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
|
|
|
|
|
VerifyEpisode(ep[0], fakeEpisode);
|
2011-12-01 20:05:17 +01:00
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(1);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void single_none_existing_episode_should_return_nothing_and_add_nothing()
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
2011-12-01 20:05:17 +01:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2012-01-06 22:25:27 +01:00
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
|
|
|
|
EpisodeNumbers = new List<int> { 10 }
|
2011-12-01 20:05:17 +01:00
|
|
|
|
};
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episode = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
episode.Should().BeEmpty();
|
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(0);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void single_none_existing_series_should_return_nothing_and_add_nothing()
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
2012-01-06 22:25:27 +01:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
|
|
|
|
SeasonNumber = 10,
|
|
|
|
|
EpisodeNumbers = new List<int> { 10 }
|
|
|
|
|
};
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episode = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
episode.Should().BeEmpty();
|
2011-12-01 20:05:17 +01:00
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(0);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void existing_multi_episode_should_return_all_episodes()
|
2011-06-22 03:12:20 +02:00
|
|
|
|
{
|
2012-01-06 22:25:27 +01:00
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
Db.Insert(fakeEpisode2);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
2011-12-01 20:05:17 +01:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2012-01-06 22:25:27 +01:00
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
|
|
|
|
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
|
2011-12-01 20:05:17 +01:00
|
|
|
|
};
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-06-22 03:12:20 +02:00
|
|
|
|
|
|
|
|
|
ep.Should().HaveCount(2);
|
2011-12-01 20:05:17 +01:00
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(2);
|
2011-10-04 04:01:39 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
VerifyEpisode(ep[0], fakeEpisode);
|
|
|
|
|
VerifyEpisode(ep[1], fakeEpisode2);
|
2012-02-03 07:49:34 +01:00
|
|
|
|
parseResult.EpisodeTitle.Should().Be("Episode");
|
2012-01-06 22:25:27 +01:00
|
|
|
|
}
|
2011-10-04 04:01:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void none_existing_multi_episode_should_not_return_or_add_anything()
|
2011-10-04 04:01:39 +02:00
|
|
|
|
{
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
2012-01-06 22:25:27 +01:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
|
|
|
|
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
|
|
|
|
|
};
|
2011-10-04 04:01:39 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-10-04 04:01:39 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
ep.Should().BeEmpty();
|
2012-02-03 07:49:34 +01:00
|
|
|
|
Db.Fetch<Episode>().Should().BeEmpty();
|
2011-10-04 04:01:39 +02:00
|
|
|
|
}
|
2011-10-21 01:07:47 +02:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
|
2011-10-21 01:07:47 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_null()
|
|
|
|
|
{
|
|
|
|
|
//Act
|
2012-01-06 22:25:27 +01:00
|
|
|
|
var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult());
|
2011-10-21 01:07:47 +02:00
|
|
|
|
//Assert
|
|
|
|
|
episodes.Should().NotBeNull();
|
|
|
|
|
episodes.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_empty()
|
|
|
|
|
{
|
|
|
|
|
//Act
|
2012-01-06 22:25:27 +01:00
|
|
|
|
var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { EpisodeNumbers = new List<int>() });
|
2011-10-21 01:07:47 +02:00
|
|
|
|
//Assert
|
|
|
|
|
episodes.Should().NotBeNull();
|
|
|
|
|
episodes.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-24 09:28:20 +01:00
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void should_return_single_episode_when_air_date_is_provided()
|
2011-11-24 09:28:20 +01:00
|
|
|
|
{
|
2011-12-01 02:10:36 +01:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeDailyEpisode);
|
2011-11-24 09:28:20 +01:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries });
|
2011-11-24 09:28:20 +01:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episodes.Should().HaveCount(1);
|
2012-01-06 22:25:27 +01:00
|
|
|
|
VerifyEpisode(episodes[0], fakeDailyEpisode);
|
2011-12-01 02:10:36 +01:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(1);
|
2011-11-24 09:28:20 +01:00
|
|
|
|
}
|
2011-12-01 20:05:17 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void should_not_add_episode_when_episode_doesnt_exist()
|
2011-12-01 20:05:17 +01:00
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries });
|
2011-12-01 20:05:17 +01:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-01-06 22:25:27 +01:00
|
|
|
|
episodes.Should().HaveCount(0);
|
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(0);
|
2011-12-01 20:05:17 +01:00
|
|
|
|
}
|
2011-12-02 07:26:24 +01:00
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
|
2011-12-02 07:26:24 +01:00
|
|
|
|
[Test]
|
2012-02-03 07:49:34 +01:00
|
|
|
|
public void GetEpisodeParseResult_should_return_single_title_for_multiple_episodes()
|
2011-12-02 07:26:24 +01:00
|
|
|
|
{
|
2012-01-06 22:25:27 +01:00
|
|
|
|
Db.Insert(fakeSeries);
|
2011-12-02 07:26:24 +01:00
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
Db.Insert(fakeEpisode2);
|
2012-01-06 22:25:27 +01:00
|
|
|
|
|
2011-12-02 07:26:24 +01:00
|
|
|
|
var parseResult = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2012-01-06 22:25:27 +01:00
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
2011-12-03 03:29:05 +01:00
|
|
|
|
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
|
2011-12-02 07:26:24 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-12-02 07:26:24 +01:00
|
|
|
|
|
|
|
|
|
ep.Should().HaveCount(2);
|
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(2);
|
2012-01-06 22:25:27 +01:00
|
|
|
|
|
|
|
|
|
VerifyEpisode(ep[0], fakeEpisode);
|
|
|
|
|
VerifyEpisode(ep[1], fakeEpisode2);
|
|
|
|
|
|
2012-02-03 07:49:34 +01:00
|
|
|
|
parseResult.EpisodeTitle.Should().Be("Episode");
|
2011-12-02 07:26:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisodeParseResult_should_return_single_title_for_single_episode()
|
|
|
|
|
{
|
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2012-01-06 22:25:27 +01:00
|
|
|
|
SeasonNumber = fakeEpisode.SeasonNumber,
|
2011-12-03 03:29:05 +01:00
|
|
|
|
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
|
2011-12-02 07:26:24 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-12-02 07:26:24 +01:00
|
|
|
|
|
|
|
|
|
ep.Should().HaveCount(1);
|
|
|
|
|
Db.Fetch<Episode>().Should().HaveCount(1);
|
|
|
|
|
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
|
|
|
|
|
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
|
|
|
|
|
}
|
2011-12-20 01:45:47 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-06 22:25:27 +01:00
|
|
|
|
public void GetEpisodeParseResult_should_return_nothing_when_series_is_not_daily_but_parsed_daily()
|
2011-12-20 01:45:47 +01:00
|
|
|
|
{
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
|
|
var parseResult = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
|
|
|
|
AirDate = DateTime.Today
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-06 22:25:27 +01:00
|
|
|
|
var ep = episodeProvider.GetEpisodesByParseResult(parseResult);
|
2011-12-20 01:45:47 +01:00
|
|
|
|
|
|
|
|
|
ep.Should().BeEmpty();
|
2011-12-20 01:58:26 +01:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-12-20 01:45:47 +01:00
|
|
|
|
}
|
2012-01-06 22:25:27 +01:00
|
|
|
|
|
|
|
|
|
private void VerifyEpisode(Episode actual, Episode excpected)
|
|
|
|
|
{
|
|
|
|
|
actual.ShouldHave().AllProperties().But(e => e.Series).But(e => e.EpisodeFile).EqualTo(excpected);
|
|
|
|
|
}
|
2011-06-22 03:12:20 +02:00
|
|
|
|
}
|
2011-12-01 20:05:17 +01:00
|
|
|
|
}
|