2012-02-21 04:25:19 +01:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
|
|
|
|
using PetaPoco;
|
2012-10-17 02:08:47 +02:00
|
|
|
|
using TvdbLib.Data;
|
2012-02-21 04:25:19 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 21:54:03 +01:00
|
|
|
|
public class SeasonProviderTest : SqlCeTest
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2012-02-28 06:50:56 +01:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
|
2012-02-21 04:25:19 +01:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
2012-02-28 06:50:56 +01:00
|
|
|
|
public void SetIgnore_should_update_ignored_status(bool ignoreFlag)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
|
|
|
|
var fakeSeason = Builder<Season>.CreateNew()
|
2012-02-28 06:50:56 +01:00
|
|
|
|
.With(s => s.Ignored = !ignoreFlag)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
.Build();
|
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(4)
|
|
|
|
|
.All()
|
|
|
|
|
.With(c => c.SeriesId = fakeSeason.SeriesId)
|
|
|
|
|
.With(c => c.SeasonNumber = fakeSeason.SeasonId)
|
|
|
|
|
.With(c => c.Ignored = !ignoreFlag)
|
|
|
|
|
.Build().ToList();
|
|
|
|
|
|
|
|
|
|
fakeEpisodes.ForEach(c => Db.Insert(c));
|
|
|
|
|
|
2012-02-21 04:25:19 +01:00
|
|
|
|
var id = Db.Insert(fakeSeason);
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-28 06:50:56 +01:00
|
|
|
|
Mocker.Resolve<SeasonProvider>().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, ignoreFlag);
|
2012-02-21 04:25:19 +01:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-28 06:50:56 +01:00
|
|
|
|
var season = Db.SingleOrDefault<Season>(id);
|
|
|
|
|
season.Ignored.Should().Be(ignoreFlag);
|
|
|
|
|
|
|
|
|
|
var episodes = Db.Fetch<Episode>();
|
|
|
|
|
episodes.Should().HaveSameCount(fakeEpisodes);
|
|
|
|
|
episodes.Should().OnlyContain(c => c.Ignored == ignoreFlag);
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeason = Builder<Season>.CreateNew()
|
2012-02-28 06:50:56 +01:00
|
|
|
|
.With(s => s.Ignored = ignoreFlag)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeason);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-28 06:50:56 +01:00
|
|
|
|
result.Should().Be(ignoreFlag);
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-02-28 06:50:56 +01:00
|
|
|
|
public void IsIgnored_should_throw_an_exception_if_not_in_db()
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2012-02-28 06:50:56 +01:00
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Mocker.Resolve<SeasonProvider>().IsIgnored(10, 0));
|
2012-02-21 07:50:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void All_should_return_seasons_with_episodes()
|
|
|
|
|
{
|
|
|
|
|
const int seriesId = 10;
|
|
|
|
|
|
|
|
|
|
var season = Builder<Season>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = seriesId)
|
|
|
|
|
.With(s => s.SeasonNumber = 4)
|
|
|
|
|
.With(s => s.Ignored = true)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
|
|
|
|
.With(e => e.SeasonNumber = season.SeasonNumber)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(season);
|
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<SeasonProvider>().All(seriesId);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
|
result.First().Episodes.Should().HaveCount(episodes.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void All_should_return_all_seasons_with_episodes()
|
|
|
|
|
{
|
|
|
|
|
const int seriesId = 10;
|
|
|
|
|
|
|
|
|
|
//Setup
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
var seasons = Builder<Season>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(s => s.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episodes = new List<Episode>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < seasons.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var newEps = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
|
|
|
|
.With(e => e.SeasonNumber = i + 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
episodes.AddRange(newEps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(seasons);
|
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<SeasonProvider>().All(seriesId);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveCount(5);
|
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
foreach (var season in result)
|
2012-02-21 07:50:38 +01:00
|
|
|
|
{
|
|
|
|
|
season.Episodes.Count.Should().Be(2);
|
2012-02-28 06:50:56 +01:00
|
|
|
|
season.Episodes.Should().OnlyContain(c => c.SeasonNumber == season.SeasonNumber);
|
2012-02-21 07:50:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-28 06:50:56 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void EnsureSeason_should_add_all_seasons_for_new_series()
|
|
|
|
|
{
|
|
|
|
|
var seasons = new[] { 0, 1, 2, 3, 4, 5 };
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasons);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(12).SequenceEqual(seasons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void EnsureSeason_should_add_missing_seasons()
|
|
|
|
|
{
|
|
|
|
|
var seasonsA = new[] { 0, 1, 2, 3 };
|
|
|
|
|
var seasonsB = new[] { 0, 1, 2, 3, 4, 5 };
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasonsA);
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(12).SequenceEqual(seasonsA);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasonsB);
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(12).SequenceEqual(seasonsB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void EnsureSeason_marks_season_zero_as_ignored()
|
|
|
|
|
{
|
|
|
|
|
var seasons = new[] { 0, 1, 2, 3 };
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasons);
|
|
|
|
|
Db.Fetch<Season>().Should().Contain(c => c.SeasonNumber == 0 && c.Ignored);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void EnsureSeason_none_zero_seasons_arent_ignored()
|
|
|
|
|
{
|
|
|
|
|
var seasons = new[] { 1, 2, 3 };
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasons);
|
|
|
|
|
Db.Fetch<Season>().Should().OnlyContain(c => c.Ignored == false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetSeason_should_return_seasons_for_specified_series_only()
|
|
|
|
|
{
|
|
|
|
|
var seriesA = new[] { 1, 2, 3 };
|
|
|
|
|
var seriesB = new[] { 4, 5, 6 };
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(1, seriesA);
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().EnsureSeasons(2, seriesB);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(1).Should().Equal(seriesA);
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(2).Should().Equal(seriesB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetSeason_should_return_emptylist_if_series_doesnt_exist()
|
|
|
|
|
{
|
|
|
|
|
Mocker.Resolve<SeasonProvider>().GetSeasons(1).Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|