2011-10-21 02:42:17 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2013-02-24 09:48:52 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-02-24 22:18:48 +03:00
|
|
|
using NzbDrone.Core.Download;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-10-21 02:42:17 +03:00
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using PetaPoco;
|
2012-10-17 03:08:47 +03:00
|
|
|
using TvdbLib.Data;
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-19 09:01:03 +03:00
|
|
|
namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests
|
2011-10-21 02:42:17 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 23:54:03 +03:00
|
|
|
public class EpisodeProviderTest : SqlCeTest
|
2011-10-21 02:42:17 +03:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void GetEpisodes_exists()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisodes_by_season_episode_exists()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 1)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
2013-02-20 05:05:15 +03:00
|
|
|
.And(e => e.SeasonNumber = 2).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.Insert(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-24 22:57:33 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(fakeSeries.OID, 2, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes);
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisodes_by_season_episode_doesnt_exists()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, 1, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.Should().BeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_with_EpisodeFile()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
2012-10-14 03:36:16 +03:00
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
|
|
|
Db.Insert(fakeFile);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
|
|
|
|
public void GetEpisodes_invalid_series()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<SeriesService>();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
.All().With(e => e.SeriesId = 1).Build();
|
|
|
|
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().GetEpisode(1);
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
2013-02-20 05:05:15 +03:00
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
[Test]
|
|
|
|
public void GetEpisodesBySeason_success()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 12)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
.All().With(c => c.SeriesId = 12).And(c => c.SeasonNumber = 2)
|
|
|
|
.TheFirst(5).With(c => c.SeasonNumber = 1)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(episodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var seasonEposodes = Mocker.Resolve<EpisodeService>().GetEpisodesBySeason(12, 2);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Fetch<Episode>().Should().HaveCount(10);
|
2011-10-21 02:42:17 +03:00
|
|
|
seasonEposodes.Should().HaveCount(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_emptyRepo()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var actualCount = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList().Count;
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>().VerifyAll();
|
2011-10-21 02:42:17 +03:00
|
|
|
actualCount.Should().Be(episodeCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(10).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now)
|
2011-10-21 02:42:17 +03:00
|
|
|
.TheFirst(7).With(e => e.FirstAired = new DateTime(1800, 1, 1))
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var storedEpisodes = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2011-10-21 02:42:17 +03:00
|
|
|
storedEpisodes.Should().HaveCount(10);
|
|
|
|
storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(7);
|
|
|
|
storedEpisodes.Where(e => e.AirDate != null).Should().HaveCount(3);
|
|
|
|
}
|
|
|
|
|
2011-11-24 09:28:52 +03:00
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null_for_existing_episodes()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.TvDbEpisodeId = 12345)
|
|
|
|
.With(e => e.AirDate = DateTime.Today)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeTvDbEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(1)
|
|
|
|
.All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now)
|
2011-11-24 09:28:52 +03:00
|
|
|
.TheFirst(1).With(e => e.FirstAired = new DateTime(1800, 1, 1))
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-11-24 09:28:52 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-11-24 09:28:52 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-11-24 09:28:52 +03:00
|
|
|
.Returns(fakeTvDbEpisodes);
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-11-24 09:28:52 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var storedEpisodes = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2011-11-24 09:28:52 +03:00
|
|
|
storedEpisodes.Should().HaveCount(1);
|
|
|
|
storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(1);
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_ignore_episode_zero()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-10-21 02:42:17 +03:00
|
|
|
.TheFirst(1)
|
2011-10-23 08:39:14 +03:00
|
|
|
.With(e => e.EpisodeNumber = 0)
|
|
|
|
.With(e => e.SeasonNumber = 15)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>().VerifyAll();
|
2011-10-21 02:42:17 +03:00
|
|
|
result.Should().HaveCount(episodeCount);
|
|
|
|
result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
2012-02-05 07:34:28 +03:00
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_skip_future_episodes_with_no_title()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
|
|
|
.With(a => c.FirstAired = DateTime.Now.AddDays(-2))
|
|
|
|
.With(e => e.EpisodeName = "Something")
|
|
|
|
.TheFirst(3)
|
|
|
|
.With(e => e.EpisodeName = "")
|
|
|
|
.With(e => e.FirstAired = DateTime.Now.AddDays(10))
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-02-05 07:34:28 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2012-02-05 07:34:28 +03:00
|
|
|
result.Should().HaveCount(episodeCount - 3);
|
|
|
|
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_skip_older_than_1900_year_episodes_with_no_title()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
|
|
|
.With(a => c.FirstAired = DateTime.Now.AddDays(-2))
|
|
|
|
.With(e => e.EpisodeName = "Something")
|
|
|
|
.TheFirst(3)
|
|
|
|
.With(e => e.EpisodeName = "")
|
2013-02-20 05:05:15 +03:00
|
|
|
.With(e => e.FirstAired = new DateTime(1889, 1, 1))
|
2012-02-05 07:34:28 +03:00
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-02-05 07:34:28 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2012-02-05 07:34:28 +03:00
|
|
|
result.Should().HaveCount(episodeCount - 3);
|
|
|
|
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_add_future_episodes_with_title()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(10).
|
|
|
|
All()
|
|
|
|
.With(a => a.FirstAired = DateTime.Now.AddDays(10))
|
|
|
|
.With(e => e.EpisodeName = "Something")
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-02-05 07:34:28 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2012-02-05 07:34:28 +03:00
|
|
|
result.Should().HaveSameCount(fakeEpisodes.Episodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_add_old_episodes_with_no_title()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(10).
|
|
|
|
All()
|
|
|
|
.With(a => a.FirstAired = DateTime.Now.AddDays(-10))
|
|
|
|
.With(e => e.EpisodeName = string.Empty)
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-02-05 07:34:28 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-02-05 07:34:28 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2012-02-05 07:34:28 +03:00
|
|
|
result.Should().HaveSameCount(fakeEpisodes.Episodes);
|
|
|
|
}
|
|
|
|
|
2011-11-30 11:21:18 +03:00
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_ignore_season_zero()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-11-30 11:21:18 +03:00
|
|
|
.With(e => e.SeasonNumber = 0)
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-11-30 11:21:18 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-11-30 11:21:18 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
2011-11-30 11:21:18 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-11-30 11:21:18 +03:00
|
|
|
.Returns(fakeEpisodes);
|
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.GetMock<SeasonRepository>()
|
2012-02-21 06:25:19 +03:00
|
|
|
.Setup(s => s.IsIgnored(seriesId, 0))
|
|
|
|
.Returns(true);
|
|
|
|
|
2011-11-30 11:21:18 +03:00
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-11-30 11:21:18 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>().VerifyAll();
|
2011-11-30 11:21:18 +03:00
|
|
|
result.Should().HaveCount(episodeCount);
|
|
|
|
result.Where(e => e.Ignored).Should().HaveCount(episodeCount);
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
[Test]
|
|
|
|
public void new_episodes_only_calls_Insert()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var currentEpisodes = new List<Episode>();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.InsertMany(It.Is<IEnumerable<Episode>>(l => l.Count() == 5)), Times.Once());
|
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.Update(It.IsAny<IEnumerable<Episode>>()), Times.Never());
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void existing_episodes_only_calls_Update()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var currentEpisodes = new List<Episode>();
|
|
|
|
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
|
|
|
{
|
|
|
|
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, Series = fakeSeries });
|
|
|
|
}
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.InsertMany(It.Is<IEnumerable<Episode>>(l => l.Count() == 0)), Times.Once());
|
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(It.Is<IEnumerable<Episode>>(l => l.Count() == 5)), Times.Once());
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_try_to_get_existing_episode_using_tvdbid_first()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var fakeTvDbResult = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Id = seriesId)
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(
|
|
|
|
Builder<TvdbEpisode>.CreateListOfSize(1)
|
|
|
|
.All().With(g => g.Id = 99)
|
|
|
|
.Build())
|
|
|
|
)
|
|
|
|
.Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
var fakeEpisodeList = new List<Episode> { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries } };
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(fakeEpisodeList);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(fakeTvDbResult);
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(fakeEpisodeList), Times.Once());
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_episode()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Id = seriesId)
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>{
|
|
|
|
Builder<TvdbEpisode>.CreateNew()
|
|
|
|
.With(g => g.Id = 99)
|
|
|
|
.With(g => g.SeasonNumber = 4)
|
|
|
|
.With(g => g.EpisodeNumber = 15)
|
|
|
|
.With(g=>g.SeriesId = seriesId)
|
|
|
|
.Build()
|
|
|
|
})
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var localEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
.With(c => c.SeasonNumber = 4)
|
|
|
|
.With(c => c.EpisodeNumber = 15)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(new List<Episode> { localEpisode });
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(new List<Episode> { localEpisode }), Times.Once());
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void existing_episodes_keep_their_episodeId_file_id()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var currentEpisodes = new List<Episode>();
|
|
|
|
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
|
|
|
{
|
2012-10-07 08:30:12 +03:00
|
|
|
currentEpisodes.Add(new Episode
|
|
|
|
{
|
2013-02-20 05:05:15 +03:00
|
|
|
TvDbEpisodeId = tvDbEpisode.Id,
|
|
|
|
OID = 99,
|
|
|
|
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
|
|
|
Ignored = true,
|
|
|
|
Series = fakeSeries,
|
|
|
|
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
|
|
|
SeasonNumber = tvDbEpisode.SeasonNumber
|
2012-10-07 08:30:12 +03:00
|
|
|
});
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-10-21 02:42:17 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
var updatedEpisodes = new List<Episode>();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.GetMock<IDatabase>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
|
|
|
|
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
updatedEpisodes.Should().HaveSameCount(tvdbSeries.Episodes);
|
2013-02-20 05:05:15 +03:00
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.OID == 99);
|
2011-10-21 02:42:17 +03:00
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 69);
|
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
|
|
|
|
}
|
|
|
|
|
2012-10-07 08:30:12 +03:00
|
|
|
[Test]
|
|
|
|
public void existing_episodes_remote_their_episodeId_file_id_when_episode_number_doesnt_match_tvdbid()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-10-07 08:30:12 +03:00
|
|
|
|
|
|
|
var currentEpisodes = new List<Episode>();
|
|
|
|
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
|
|
|
{
|
|
|
|
currentEpisodes.Add(new Episode
|
|
|
|
{
|
|
|
|
TvDbEpisodeId = tvDbEpisode.Id,
|
2013-02-20 05:05:15 +03:00
|
|
|
OID = 99,
|
|
|
|
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
2012-10-07 08:30:12 +03:00
|
|
|
Ignored = true,
|
|
|
|
Series = fakeSeries,
|
|
|
|
EpisodeNumber = tvDbEpisode.EpisodeNumber + 1,
|
|
|
|
SeasonNumber = tvDbEpisode.SeasonNumber
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-10-07 08:30:12 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
var updatedEpisodes = new List<Episode>();
|
|
|
|
|
|
|
|
Mocker.GetMock<IDatabase>()
|
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
Mocker.GetMock<IDatabase>()
|
|
|
|
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
|
|
|
|
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-10-07 08:30:12 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void existing_episodes_remote_their_episodeId_file_id_when_season_number_doesnt_match_tvdbid()
|
|
|
|
{
|
|
|
|
const int seriesId = 71663;
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-10-07 08:30:12 +03:00
|
|
|
|
|
|
|
var currentEpisodes = new List<Episode>();
|
|
|
|
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
|
|
|
{
|
|
|
|
currentEpisodes.Add(new Episode
|
|
|
|
{
|
|
|
|
TvDbEpisodeId = tvDbEpisode.Id,
|
2013-02-20 05:05:15 +03:00
|
|
|
OID = 99,
|
|
|
|
EpisodeFile = new EpisodeFile { EpisodeFileId = 69 },
|
2012-10-07 08:30:12 +03:00
|
|
|
Ignored = true,
|
|
|
|
Series = fakeSeries,
|
|
|
|
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
|
|
|
SeasonNumber = tvDbEpisode.SeasonNumber + 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-10-07 08:30:12 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
var updatedEpisodes = new List<Episode>();
|
|
|
|
|
|
|
|
Mocker.GetMock<IDatabase>()
|
|
|
|
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
Mocker.GetMock<IDatabase>()
|
|
|
|
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
|
|
|
|
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-10-07 08:30:12 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
|
|
|
|
}
|
|
|
|
|
2011-12-02 11:35:56 +03:00
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_ignore_new_episode_for_ignored_season()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 2;
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.SeasonNumber = 5)
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
|
|
|
.With(e => e.TvDbEpisodeId = 11)
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
|
|
|
.With(e => e.Ignored = true)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-12-02 11:35:56 +03:00
|
|
|
.With(e => e.SeasonNumber = 5)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
|
|
|
.With(e => e.Id = 11)
|
|
|
|
.TheNext(1)
|
|
|
|
.With(e => e.EpisodeNumber = 2)
|
|
|
|
.With(e => e.Id = 22)
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2011-12-02 11:35:56 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2011-12-02 11:35:56 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.GetMock<SeasonRepository>()
|
2012-02-21 06:25:19 +03:00
|
|
|
.Setup(s => s.IsIgnored(seriesId, It.IsAny<int>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
2011-12-02 11:35:56 +03:00
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2011-12-02 11:35:56 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2011-12-02 11:35:56 +03:00
|
|
|
Mocker.GetMock<TvDbProvider>().VerifyAll();
|
|
|
|
result.Should().HaveCount(episodeCount);
|
|
|
|
result.Where(e => e.Ignored).Should().HaveCount(episodeCount);
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
[Test]
|
|
|
|
[Explicit]
|
|
|
|
public void Add_daily_show_episodes()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
|
|
|
Mocker.Resolve<TvDbProvider>();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-24 22:39:31 +03:00
|
|
|
Mocker.GetMock<IConfigService>()
|
2011-10-21 02:42:17 +03:00
|
|
|
.Setup(e => e.DefaultQualityProfile).Returns(1);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(Builder<QualityProfile>.CreateNew().Build());
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
var seriesRepo = Mocker.Resolve<ISeriesRepository>();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
const int tvDbSeriesId = 71256;
|
|
|
|
//act
|
2013-02-20 05:05:15 +03:00
|
|
|
var seriesProvider = Mocker.Resolve<SeriesService>();
|
|
|
|
|
|
|
|
seriesProvider.AddSeries("Test Series", "c:\\test\\", tvDbSeriesId, 1, null);
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
var episodeProvider = Mocker.Resolve<EpisodeService>();
|
|
|
|
episodeProvider.RefreshEpisodeInfo(seriesRepo.Get(tvDbSeriesId));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//assert
|
|
|
|
var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId);
|
|
|
|
episodes.Should().NotBeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_by_Season_Episode_none_existing()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, 1, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.Should().BeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_by_Season_Episode_with_EpisodeFile()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
2012-10-14 03:36:16 +03:00
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
|
|
|
Db.Insert(fakeFile);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, 1, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_by_Season_Episode_without_EpisodeFile()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).TheFirst(1).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, 1, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
episode.EpisodeFile.Should().BeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_by_AirDate_with_EpisodeFile()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
2012-10-14 03:36:16 +03:00
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
|
|
|
Db.Insert(fakeFile);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, fakeEpisodes[0].AirDate.Value);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisode_by_AirDate_without_EpisodeFile()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
2013-02-20 05:05:15 +03:00
|
|
|
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).Build();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.InsertMany(fakeEpisodes);
|
|
|
|
Db.Insert(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episode = Mocker.Resolve<EpisodeService>().GetEpisode(1, fakeEpisodes[0].AirDate.Value);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
|
|
|
|
episode.Series.ShouldHave().AllPropertiesBut(s => s.EpisodeCount, s => s.EpisodeFileCount, s => s.SeasonCount, s => s.NextAiring).EqualTo(fakeSeries);
|
|
|
|
episode.EpisodeFile.Should().BeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void MarkEpisodeAsFetched()
|
|
|
|
{
|
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-21 02:42:17 +03:00
|
|
|
.All().With(e => e.GrabDate = null)
|
|
|
|
.Build();
|
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
var parseResult = new EpisodeParseResult() { Episodes = fakeEpisodes };
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().Handle(new EpisodeGrabbedEvent(parseResult));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
Mocker.GetMock<IEpisodeRepository>().Verify(c=>c.Update(fakeEpisodes[0]),Times.Once());
|
|
|
|
Mocker.GetMock<IEpisodeRepository>().Verify(c=>c.Update(fakeEpisodes[1]),Times.Once());
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddEpisode_episode_is_ignored_when_full_season_is_ignored()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
episodes.ForEach(c => Db.Insert(c));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var newEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.SeriesId = 10)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.EpisodeNumber = 8)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.Build();
|
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.GetMock<SeasonRepository>()
|
2012-02-21 06:25:19 +03:00
|
|
|
.Setup(s => s.IsIgnored(newEpisode.SeriesId, newEpisode.SeasonNumber))
|
|
|
|
.Returns(true);
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().AddEpisode(newEpisode);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
episodesInDb.Should().HaveCount(5);
|
|
|
|
episodesInDb.Should().OnlyContain(e => e.Ignored);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddEpisode_episode_is_not_ignored_when_full_season_is_not_ignored()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
episodes.ForEach(c => Db.Insert(c));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var newEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.SeriesId = 10)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.EpisodeNumber = 8)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().AddEpisode(newEpisode);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
episodesInDb.Should().HaveCount(5);
|
|
|
|
episodesInDb.Should().OnlyContain(e => e.Ignored == false);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddEpisode_episode_is_not_ignored_when_not_full_season_is_not_ignored()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.And(c => c.SeasonNumber = 1)
|
|
|
|
.And(c => c.Ignored = true)
|
|
|
|
.TheFirst(2)
|
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
episodes.ForEach(c => Db.Insert(c));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var newEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(e => e.SeriesId = 10)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.EpisodeNumber = 8)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().AddEpisode(newEpisode);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
episodesInDb.Should().HaveCount(5);
|
|
|
|
episodesInDb.Where(e => e.EpisodeNumber == 8 && !e.Ignored).Should().HaveCount(1);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IgnoreEpisode_Ignore()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
episodes.ForEach(c => Db.Insert(c));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().SetEpisodeIgnore(1, true);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
episodesInDb.Should().HaveCount(4);
|
|
|
|
episodesInDb.Where(e => e.Ignored).Should().HaveCount(1);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IgnoreEpisode_RemoveIgnore()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
episodes.ForEach(c => Db.Insert(c));
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().SetEpisodeIgnore(1, false);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
episodesInDb.Should().HaveCount(4);
|
|
|
|
episodesInDb.Where(e => !e.Ignored).Should().HaveCount(1);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EpisodesWithoutFiles_no_specials()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.TheFirst(2)
|
2011-10-23 08:39:14 +03:00
|
|
|
.Section(1, 2)
|
2011-10-21 02:42:17 +03:00
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.Build().ToList();
|
|
|
|
|
|
|
|
var specials = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 0)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.TheFirst(1).With(c => c.Ignored = true)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
Db.InsertMany(specials);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var missingFiles = Mocker.Resolve<EpisodeService>().EpisodesWithoutFiles(false);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
missingFiles.Should().HaveCount(1);
|
|
|
|
missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(1);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EpisodesWithoutFiles_with_specials()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.TheFirst(2)
|
2011-10-23 08:39:14 +03:00
|
|
|
.Section(1, 2)
|
2011-10-21 02:42:17 +03:00
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.Build().ToList();
|
|
|
|
|
|
|
|
var specials = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 0)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = false)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
Db.InsertMany(specials);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var missingFiles = Mocker.Resolve<EpisodeService>().EpisodesWithoutFiles(true);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
missingFiles.Should().HaveCount(2);
|
|
|
|
missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(2);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EpisodesWithFiles_success()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
.With(c => c.EpisodeFileId = 1)
|
2012-10-14 03:36:16 +03:00
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.With(c => c.EpisodeFile = episodeFile)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.Insert(episodeFile);
|
|
|
|
Db.InsertMany(episodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var withFiles = Mocker.Resolve<EpisodeService>().EpisodesWithFiles();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
withFiles.Should().HaveCount(2);
|
|
|
|
withFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(0);
|
|
|
|
withFiles.Where(e => e.EpisodeFile == null).Should().HaveCount(0);
|
|
|
|
|
|
|
|
foreach (var withFile in withFiles)
|
|
|
|
{
|
|
|
|
withFile.EpisodeFile.Should().NotBeNull();
|
|
|
|
withFile.Series.Title.Should().NotBeNullOrEmpty();
|
|
|
|
}
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EpisodesWithFiles_no_files()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.AirDate = DateTime.Today.AddDays(-4))
|
|
|
|
.With(c => c.Ignored = true)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.InsertMany(episodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var withFiles = Mocker.Resolve<EpisodeService>().EpisodesWithFiles();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
withFiles.Should().HaveCount(0);
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisodesByFileId_multi_episodes()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
2013-02-20 05:05:15 +03:00
|
|
|
.With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 })
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episodes = Mocker.Resolve<EpisodeService>().GetEpisodesByFileId(12345);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episodes.Should().HaveCount(2);
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetEpisodesByFileId_single_episode()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 10)
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
2013-02-20 05:05:15 +03:00
|
|
|
.With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 })
|
2011-10-21 02:42:17 +03:00
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(series);
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var episodes = Mocker.Resolve<EpisodeService>().GetEpisodesByFileId(12345);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
episodes.Should().HaveCount(1);
|
|
|
|
episodes.First().ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisode);
|
2011-12-01 04:04:46 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IsFirstOrLastEpisodeInSeason_false()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().IsFirstOrLastEpisodeOfSeason(10, 1, 5);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IsFirstOrLastEpisodeInSeason_true_first()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().IsFirstOrLastEpisodeOfSeason(10, 1, 1);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IsFirstOrLastEpisodeInSeason_true_last()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 10)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().IsFirstOrLastEpisodeOfSeason(10, 1, 10);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Unpacking, 1)]
|
|
|
|
[TestCase("The Office (US) - S01E01 - Episode Title", PostDownloadStatusType.Failed, 1)]
|
|
|
|
[TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Unpacking, 2)]
|
|
|
|
[TestCase("The Office (US) - S01E01E02 - Episode Title", PostDownloadStatusType.Failed, 2)]
|
|
|
|
[TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Unpacking, 10)]
|
|
|
|
[TestCase("The Office (US) - Season 01 - Episode Title", PostDownloadStatusType.Failed, 10)]
|
|
|
|
public void SetPostDownloadStatus(string folderName, PostDownloadStatusType postDownloadStatus, int episodeCount)
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 12345)
|
2011-10-21 02:42:17 +03:00
|
|
|
.With(s => s.CleanTitle = "officeus")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(episodeCount)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 12345)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("officeus")).Returns(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().SetPostDownloadStatus(fakeEpisodes.Select(e => e.OID).ToList(), postDownloadStatus);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var result = Db.Fetch<Episode>();
|
2011-10-21 02:42:17 +03:00
|
|
|
result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(episodeCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SetPostDownloadStatus_Invalid_EpisodeId()
|
|
|
|
{
|
2011-12-01 04:04:46 +03:00
|
|
|
WithRealDb();
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
var postDownloadStatus = PostDownloadStatusType.Failed;
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 22:57:33 +03:00
|
|
|
.With(s => s.OID = 12345)
|
2011-10-21 02:42:17 +03:00
|
|
|
.With(s => s.CleanTitle = "officeus")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
.All()
|
|
|
|
.With(c => c.SeriesId = 12345)
|
|
|
|
.With(c => c.SeasonNumber = 1)
|
|
|
|
.With(c => c.PostDownloadStatus = PostDownloadStatusType.Unknown)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-01 04:04:46 +03:00
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
Db.InsertMany(fakeEpisodes);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("officeus")).Returns(fakeSeries);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().SetPostDownloadStatus(new List<int> { 300 }, postDownloadStatus);
|
2011-10-21 02:42:17 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:04:46 +03:00
|
|
|
var result = Db.Fetch<Episode>();
|
2011-10-21 02:42:17 +03:00
|
|
|
result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[ExpectedException(typeof(ArgumentException))]
|
|
|
|
public void SetPostDownloadStatus_should_throw_if_episode_list_is_empty()
|
|
|
|
{
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().SetPostDownloadStatus(new List<int>(), PostDownloadStatusType.Failed);
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
2012-01-14 22:09:48 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RefreshEpisodeInfo_should_ignore_episode_zero_except_if_season_one()
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 5;
|
|
|
|
|
|
|
|
var tvdbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
c => c.Episodes =
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
All()
|
2012-10-17 03:08:47 +03:00
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-01-14 22:09:48 +03:00
|
|
|
.With(e => e.EpisodeNumber = 0)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.TheNext(1)
|
|
|
|
.With(e => e.SeasonNumber = 2)
|
|
|
|
.TheNext(1)
|
|
|
|
.With(e => e.SeasonNumber = 3)
|
|
|
|
.TheNext(1)
|
|
|
|
.With(e => e.SeasonNumber = 4)
|
|
|
|
.TheNext(1)
|
|
|
|
.With(e => e.SeasonNumber = 5)
|
|
|
|
.Build())
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
2013-02-24 22:57:33 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(c => c.OID = seriesId).Build();
|
2012-01-14 22:09:48 +03:00
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<TvDbProvider>()
|
2012-10-17 03:08:47 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true, false))
|
2012-01-14 22:09:48 +03:00
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 05:05:15 +03:00
|
|
|
Mocker.Resolve<EpisodeService>().RefreshEpisodeInfo(fakeSeries);
|
2012-01-14 22:09:48 +03:00
|
|
|
|
|
|
|
//Assert
|
2013-02-20 05:05:15 +03:00
|
|
|
var result = Mocker.Resolve<EpisodeService>().GetEpisodeBySeries(seriesId).ToList();
|
2012-01-14 22:09:48 +03:00
|
|
|
result.Should().HaveCount(episodeCount);
|
|
|
|
result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1);
|
|
|
|
result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse();
|
|
|
|
}
|
2013-01-11 04:15:36 +03:00
|
|
|
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
}
|
|
|
|
}
|