1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-15 07:22:35 +01:00
Radarr/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/CustomStartDateSpecificationFixture.cs
Mark McDowall 9c6d78d479 Cleanup and updates for XEM
SceneSource added to signify to lookup via scene name
Use Episodes for naming instead of EpisodeNumbers (in ParseResult)
2012-10-17 00:39:06 -07:00

141 lines
4.5 KiB
C#

// 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
public class CustomStartDateSpecificationFixture : CoreTest
{
private CustomStartDateSpecification _customStartDateSpecification;
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private Series fakeSeries;
private Episode firstEpisode;
private Episode secondEpisode;
[SetUp]
public void Setup()
{
_customStartDateSpecification = Mocker.Resolve<CustomStartDateSpecification>();
firstEpisode = new Episode { AirDate = DateTime.Today };
secondEpisode = new Episode { AirDate = DateTime.Today };
fakeSeries = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(c => c.CustomStartDate = null)
.Build();
parseResultMulti = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
Episodes = new List<Episode> { firstEpisode, secondEpisode }
};
parseResultSingle = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
Episodes = new List<Episode> { firstEpisode }
};
}
private void WithFirstEpisodeLastYear()
{
firstEpisode.AirDate = DateTime.Today.AddYears(-1);
}
private void WithSecondEpisodeYear()
{
secondEpisode.AirDate = DateTime.Today.AddYears(-1);
}
private void WithAiredAfterYesterday()
{
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-1);
}
private void WithAiredAfterLastWeek()
{
fakeSeries.CustomStartDate = DateTime.Today.AddDays(-7);
}
[Test]
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_single_episode()
{
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
[Test]
public void should_return_true_when_downloadEpisodesAiredAfter_is_null_for_multiple_episodes()
{
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_return_true_if_both_episodes_air_after_cutoff()
{
WithAiredAfterLastWeek();
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_return_true_if_episode_airs_after_cutoff()
{
WithAiredAfterLastWeek();
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
[Test]
public void should_return_true_if_first_episode_aired_after_cutoff()
{
WithAiredAfterLastWeek();
WithSecondEpisodeYear();
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_return_true_if_second_episode_aired_after_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_return_false_if_both_episodes_aired_before_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
WithSecondEpisodeYear();
_customStartDateSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_return_false_if_episode_aired_before_cutoff()
{
WithAiredAfterLastWeek();
WithFirstEpisodeLastYear();
_customStartDateSpecification.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
}
}
}