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.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.DecisionEngine;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
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
|
|
|
|
|
2012-10-17 07:39:06 +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,
|
2012-10-17 07:39:06 +00:00
|
|
|
|
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,
|
2012-10-17 07:39:06 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|