2012-02-21 03:25:19 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2013-02-19 06:01:03 +00:00
|
|
|
|
|
2012-02-21 03:25:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-21 03:25:19 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
2013-02-19 06:01:03 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.TvTests
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-03-02 18:25:39 +00:00
|
|
|
|
public class SeasonProviderTest : ObjectDbTest
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2012-02-28 05:50:56 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-03-02 18:25:39 +00:00
|
|
|
|
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeason = Builder<Season>.CreateNew()
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.With(s => s.Ignored = ignoreFlag)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeason);
|
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
var result = Mocker.Resolve<SeasonRepository>().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
|
2012-02-21 03:25:19 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-28 05:50:56 +00:00
|
|
|
|
result.Should().Be(ignoreFlag);
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-02-28 05:50:56 +00:00
|
|
|
|
public void IsIgnored_should_throw_an_exception_if_not_in_db()
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Mocker.Resolve<SeasonRepository>().IsIgnored(10, 0));
|
2012-02-21 06:50:38 +00: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
|
2013-02-20 02:05:15 +00:00
|
|
|
|
var result = Mocker.Resolve<SeasonRepository>().GetSeasonBySeries(seriesId);
|
2012-02-21 06:50:38 +00:00
|
|
|
|
|
|
|
|
|
//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
|
2013-03-02 18:25:39 +00:00
|
|
|
|
|
2012-02-21 06:50:38 +00:00
|
|
|
|
|
|
|
|
|
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
|
2013-02-20 02:05:15 +00:00
|
|
|
|
var result = Mocker.Resolve<SeasonRepository>().GetSeasonBySeries(seriesId);
|
2012-02-21 06:50:38 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveCount(5);
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
foreach (var season in result)
|
2012-02-21 06:50:38 +00:00
|
|
|
|
{
|
|
|
|
|
season.Episodes.Count.Should().Be(2);
|
2012-02-28 05:50:56 +00:00
|
|
|
|
season.Episodes.Should().OnlyContain(c => c.SeasonNumber == season.SeasonNumber);
|
2012-02-21 06:50:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetSeason_should_return_seasons_for_specified_series_only()
|
|
|
|
|
{
|
|
|
|
|
var seriesA = new[] { 1, 2, 3 };
|
|
|
|
|
var seriesB = new[] { 4, 5, 6 };
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(1).Should().Equal(seriesA);
|
|
|
|
|
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(2).Should().Equal(seriesB);
|
2012-02-28 05:50:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetSeason_should_return_emptylist_if_series_doesnt_exist()
|
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<SeasonRepository>().GetSeasonNumbers(1).Should().BeEmpty();
|
2012-02-28 05:50:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|