2013-04-20 20:13:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-04-20 23:36:23 +00:00
|
|
|
|
using NzbDrone.Core.SeriesStats;
|
2013-04-20 20:13:57 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
2013-04-20 23:36:23 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.SeriesStatsTests
|
2013-04-20 20:13:57 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-20 23:36:23 +00:00
|
|
|
|
public class SeriesStatisticsFixture : DbTest<SeriesStatisticsRepository, Series>
|
2013-04-20 20:13:57 +00:00
|
|
|
|
{
|
2013-09-09 00:31:31 +00:00
|
|
|
|
private Series _series;
|
2013-04-20 20:13:57 +00:00
|
|
|
|
private Episode _episode;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-09-09 00:31:31 +00:00
|
|
|
|
_series = Builder<Series>.CreateNew()
|
2013-04-20 20:13:57 +00:00
|
|
|
|
.With(s => s.Id = 0)
|
|
|
|
|
.With(s => s.Runtime = 30)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-09-09 00:31:31 +00:00
|
|
|
|
_series.Id = Db.Insert(_series).Id;
|
2013-04-20 20:13:57 +00:00
|
|
|
|
|
|
|
|
|
_episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.Id = 0)
|
2013-09-09 00:31:31 +00:00
|
|
|
|
.With(e => e.EpisodeFileId = 0)
|
|
|
|
|
.With(e => e.Monitored = false)
|
|
|
|
|
.With(e => e.SeriesId = _series.Id)
|
2013-07-26 03:25:24 +00:00
|
|
|
|
.With(e => e.AirDateUtc = DateTime.Today.AddDays(5))
|
2013-04-20 20:13:57 +00:00
|
|
|
|
.Build();
|
2013-09-09 00:31:31 +00:00
|
|
|
|
}
|
2013-04-20 20:13:57 +00:00
|
|
|
|
|
2013-09-09 00:31:31 +00:00
|
|
|
|
private void GivenEpisodeWithFile()
|
|
|
|
|
{
|
|
|
|
|
_episode.EpisodeFileId = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenMonitoredEpisode()
|
|
|
|
|
{
|
|
|
|
|
_episode.Monitored = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenFile()
|
|
|
|
|
{
|
2013-04-20 20:13:57 +00:00
|
|
|
|
Db.Insert(_episode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-04-20 23:36:23 +00:00
|
|
|
|
public void should_get_stats_for_series()
|
2013-04-20 20:13:57 +00:00
|
|
|
|
{
|
2013-09-09 00:31:31 +00:00
|
|
|
|
GivenMonitoredEpisode();
|
|
|
|
|
GivenFile();
|
|
|
|
|
|
2013-04-20 20:13:57 +00:00
|
|
|
|
var stats = Subject.SeriesStatistics();
|
|
|
|
|
|
|
|
|
|
stats.Should().HaveCount(1);
|
2013-07-26 03:25:24 +00:00
|
|
|
|
stats.First().NextAiring.Should().Be(_episode.AirDateUtc);
|
2013-04-20 20:13:57 +00:00
|
|
|
|
}
|
2013-09-09 00:31:31 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_have_next_airing_for_episode_with_file()
|
|
|
|
|
{
|
|
|
|
|
GivenEpisodeWithFile();
|
|
|
|
|
GivenFile();
|
|
|
|
|
|
|
|
|
|
var stats = Subject.SeriesStatistics();
|
|
|
|
|
|
|
|
|
|
stats.Should().HaveCount(1);
|
|
|
|
|
stats.First().NextAiring.Should().NotHaveValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_include_unmonitored_episode_in_episode_count()
|
|
|
|
|
{
|
|
|
|
|
GivenFile();
|
|
|
|
|
|
|
|
|
|
var stats = Subject.SeriesStatistics();
|
|
|
|
|
|
|
|
|
|
stats.Should().HaveCount(1);
|
|
|
|
|
stats.First().EpisodeCount.Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_include_unmonitored_episode_with_file_in_episode_count()
|
|
|
|
|
{
|
|
|
|
|
GivenEpisodeWithFile();
|
|
|
|
|
GivenFile();
|
|
|
|
|
|
|
|
|
|
var stats = Subject.SeriesStatistics();
|
|
|
|
|
|
|
|
|
|
stats.Should().HaveCount(1);
|
|
|
|
|
stats.First().EpisodeCount.Should().Be(1);
|
|
|
|
|
}
|
2013-04-20 20:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|