2013-04-15 04:41:39 +03:00
|
|
|
using System;
|
2012-09-19 04:30:30 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2013-03-07 03:19:49 +03:00
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-04-15 04:41:39 +03:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-09-19 04:30:30 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
2013-02-19 05:19:38 +03:00
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-04-15 04:41:39 +03:00
|
|
|
|
|
|
|
public class CustomStartDateSpecificationFixture : CoreTest<CustomStartDateSpecification>
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
private CustomStartDateSpecification _customStartDateSpecification;
|
2012-09-19 04:30:30 +03:00
|
|
|
|
2013-04-15 04:41:39 +03:00
|
|
|
private RemoteEpisode parseResultMulti;
|
|
|
|
private RemoteEpisode parseResultSingle;
|
2012-09-19 04:30:30 +03:00
|
|
|
private Series fakeSeries;
|
|
|
|
private Episode firstEpisode;
|
|
|
|
private Episode secondEpisode;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification = Mocker.Resolve<CustomStartDateSpecification>();
|
2012-09-19 04:30:30 +03:00
|
|
|
|
2012-10-17 10:39:06 +03:00
|
|
|
firstEpisode = new Episode { AirDate = DateTime.Today };
|
|
|
|
secondEpisode = new Episode { AirDate = DateTime.Today };
|
|
|
|
|
2012-09-19 04:30:30 +03:00
|
|
|
fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(c => c.Monitored = true)
|
2012-09-20 18:37:40 +03:00
|
|
|
.With(c => c.CustomStartDate = null)
|
2012-09-19 04:30:30 +03:00
|
|
|
.Build();
|
|
|
|
|
2013-04-15 04:41:39 +03:00
|
|
|
parseResultMulti = new RemoteEpisode
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
Series = fakeSeries,
|
2012-10-17 10:39:06 +03:00
|
|
|
Episodes = new List<Episode> { firstEpisode, secondEpisode }
|
2012-09-19 04:30:30 +03:00
|
|
|
};
|
|
|
|
|
2013-04-15 04:41:39 +03:00
|
|
|
parseResultSingle = new RemoteEpisode
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
Series = fakeSeries,
|
2012-10-17 10:39:06 +03:00
|
|
|
Episodes = new List<Episode> { firstEpisode }
|
2012-09-19 04:30:30 +03: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 18:37:40 +03:00
|
|
|
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-1);
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithAiredAfterLastWeek()
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-7);
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_single_episode()
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_multiple_episodes()
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_both_episodes_air_after_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_episode_airs_after_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_first_episode_aired_after_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
|
|
|
WithSecondEpisodeYear();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_second_episode_aired_after_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
|
|
|
WithFirstEpisodeLastYear();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_both_episodes_aired_before_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
|
|
|
WithFirstEpisodeLastYear();
|
|
|
|
WithSecondEpisodeYear();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_episode_aired_before_cutoff()
|
|
|
|
{
|
|
|
|
WithAiredAfterLastWeek();
|
|
|
|
WithFirstEpisodeLastYear();
|
2012-09-20 18:37:40 +03:00
|
|
|
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
|
2012-09-19 04:30:30 +03:00
|
|
|
}
|
2012-10-18 21:50:52 +03: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 04:30:30 +03:00
|
|
|
}
|
|
|
|
}
|