Radarr/NzbDrone.Core.Test/DecisionEngineTests/CustomStartDateSpecificatio...

137 lines
4.4 KiB
C#
Raw Normal View History

using System;
2012-09-19 01:30:30 +00:00
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
2012-09-19 01:30:30 +00:00
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]
public class CustomStartDateSpecificationFixture : CoreTest<CustomStartDateSpecification>
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 RemoteEpisode parseResultMulti;
private RemoteEpisode parseResultSingle;
2012-09-19 01:30:30 +00:00
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 RemoteEpisode
2012-09-19 01:30:30 +00:00
{
Series = fakeSeries,
Episodes = new List<Episode> { firstEpisode, secondEpisode }
2012-09-19 01:30:30 +00:00
};
parseResultSingle = new RemoteEpisode
2012-09-19 01:30:30 +00:00
{
Series = fakeSeries,
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
}
}