Sonarr/NzbDrone.Core.Test/DecisionEngineTests/CustomStartDateSpecificatio...

149 lines
4.8 KiB
C#
Raw Normal View History

2012-09-19 01:30:30 +00:00
// ReSharper disable RedundantUsingDirective
using System.Linq;
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Tv;
2012-09-19 01:30:30 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
2013-02-19 02:19:38 +00:00
using NzbDrone.Core.DecisionEngine;
2012-09-19 01:30:30 +00:00
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
2013-02-19 02:19:38 +00:00
namespace NzbDrone.Core.Test.DecisionEngineTests
2012-09-19 01:30:30 +00:00
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class CustomStartDateSpecificationFixture : CoreTest
2012-09-19 01:30:30 +00:00
{
2012-09-20 15:37:40 +00:00
private CustomStartDateSpecification _customStartDateSpecification;
2012-09-19 01:30:30 +00:00
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private Series fakeSeries;
private Episode firstEpisode;
private Episode secondEpisode;
[SetUp]
public void Setup()
{
2012-09-20 15:37:40 +00:00
_customStartDateSpecification = Mocker.Resolve<CustomStartDateSpecification>();
2012-09-19 01:30:30 +00:00
firstEpisode = new Episode { AirDate = DateTime.Today };
secondEpisode = new Episode { AirDate = DateTime.Today };
2012-09-19 01:30:30 +00:00
fakeSeries = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
2012-09-20 15:37:40 +00:00
.With(c => c.CustomStartDate = null)
2012-09-19 01:30:30 +00:00
.Build();
parseResultMulti = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
Episodes = new List<Episode> { firstEpisode, secondEpisode }
2012-09-19 01:30:30 +00:00
};
parseResultSingle = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
Episodes = new List<Episode> { firstEpisode }
2012-09-19 01:30:30 +00:00
};
}
private void WithFirstEpisodeLastYear()
{
firstEpisode.AirDate = DateTime.Today.AddYears(-1);
}
private void WithSecondEpisodeYear()
{
secondEpisode.AirDate = DateTime.Today.AddYears(-1);
}
private void WithAiredAfterYesterday()
{
2012-09-20 15:37:40 +00:00
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-1);
2012-09-19 01:30:30 +00:00
}
private void WithAiredAfterLastWeek()
{
2012-09-20 15:37:40 +00:00
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-7);
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_single_episode()
{
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_multiple_episodes()
{
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_if_both_episodes_air_after_cutoff()
{
WithAiredAfterLastWeek();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_if_episode_airs_after_cutoff()
{
WithAiredAfterLastWeek();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_if_first_episode_aired_after_cutoff()
{
WithAiredAfterLastWeek();
WithSecondEpisodeYear();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_true_if_second_episode_aired_after_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_false_if_both_episodes_aired_before_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
WithSecondEpisodeYear();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
2012-09-19 01:30:30 +00:00
}
[Test]
public void should_return_false_if_episode_aired_before_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
2012-09-20 15:37:40 +00:00
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
2012-09-19 01:30:30 +00:00
}
2012-10-18 18:50:52 +00:00
[Test]
public void should_return_true_if_episode_airs_the_same_day_as_the_cutoff()
{
fakeSeries.CustomStartDate = DateTime.Today;
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
2012-09-19 01:30:30 +00:00
}
}