2013-04-15 01:41:39 +00:00
|
|
|
|
using System;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
2013-02-19 02:19:38 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
|
|
public class MonitoredEpisodeSpecificationFixture : CoreTest<MonitoredEpisodeSpecification>
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
private MonitoredEpisodeSpecification monitoredEpisodeSpecification;
|
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
|
private RemoteEpisode parseResultMulti;
|
|
|
|
|
private RemoteEpisode parseResultSingle;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
private Series fakeSeries;
|
|
|
|
|
private Episode firstEpisode;
|
|
|
|
|
private Episode secondEpisode;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
monitoredEpisodeSpecification = Mocker.Resolve<MonitoredEpisodeSpecification>();
|
|
|
|
|
|
|
|
|
|
fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Monitored = true)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
|
|
var singleEpisodeList = new List<Episode> { firstEpisode };
|
|
|
|
|
var doubleEpisodeList = new List<Episode> { firstEpisode, secondEpisode };
|
|
|
|
|
|
|
|
|
|
parseResultMulti = new RemoteEpisode
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2013-04-15 01:41:39 +00:00
|
|
|
|
Episodes = doubleEpisodeList
|
2012-02-07 05:08:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
|
parseResultSingle = new RemoteEpisode
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
Series = fakeSeries,
|
2013-04-15 01:41:39 +00:00
|
|
|
|
Episodes = singleEpisodeList
|
2012-02-07 05:08:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
firstEpisode = new Episode { Ignored = false };
|
|
|
|
|
secondEpisode = new Episode { Ignored = false };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithFirstEpisodeIgnored()
|
|
|
|
|
{
|
|
|
|
|
firstEpisode.Ignored = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithSecondEpisodeIgnored()
|
|
|
|
|
{
|
|
|
|
|
secondEpisode.Ignored = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void setup_should_return_monitored_episode_should_return_true()
|
|
|
|
|
{
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void not_monitored_series_should_be_skipped()
|
|
|
|
|
{
|
|
|
|
|
fakeSeries.Monitored = false;
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void not_in_db_should_be_skipped()
|
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-04-15 01:41:39 +00:00
|
|
|
|
.Setup(p => p.FindByTitle(It.IsAny<String>()))
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Returns<Series>(null);
|
|
|
|
|
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void only_episode_ignored_should_return_false()
|
|
|
|
|
{
|
|
|
|
|
WithFirstEpisodeIgnored();
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void both_episodes_ignored_should_return_false()
|
|
|
|
|
{
|
|
|
|
|
WithFirstEpisodeIgnored();
|
|
|
|
|
WithSecondEpisodeIgnored();
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void only_first_episode_ignored_should_return_monitored()
|
|
|
|
|
{
|
|
|
|
|
WithFirstEpisodeIgnored();
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void only_second_episode_ignored_should_return_monitored()
|
|
|
|
|
{
|
|
|
|
|
WithSecondEpisodeIgnored();
|
|
|
|
|
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|