2013-09-13 23:17:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using FluentAssertions;
|
2012-02-17 09:52:29 +00:00
|
|
|
|
using NUnit.Framework;
|
2013-02-24 06:48:52 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-07 00:19:49 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2014-05-13 17:57:46 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2012-02-17 09:52:29 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
2013-02-19 02:19:38 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
|
|
public class RetentionSpecificationFixture : CoreTest<RetentionSpecification>
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-05-13 17:57:46 +00:00
|
|
|
|
private RemoteEpisode _remoteEpisode;
|
2012-02-17 09:52:29 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2014-05-13 17:57:46 +00:00
|
|
|
|
_remoteEpisode = new RemoteEpisode
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Release = new ReleaseInfo() { DownloadProtocol = DownloadProtocol.Usenet }
|
2012-02-17 09:52:29 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 02:23:55 +00:00
|
|
|
|
private void WithRetention(int days)
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(days);
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 02:23:55 +00:00
|
|
|
|
private void WithAge(int days)
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-12-15 23:40:53 +00:00
|
|
|
|
_remoteEpisode.Release.PublishDate = DateTime.UtcNow.AddDays(-days);
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-02-20 02:23:55 +00:00
|
|
|
|
public void should_return_true_when_retention_is_set_to_zero()
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
WithRetention(0);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-02-20 02:23:55 +00:00
|
|
|
|
public void should_return_true_when_release_if_younger_than_retention()
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
WithRetention(1000);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-02-20 02:23:55 +00:00
|
|
|
|
public void should_return_true_when_release_and_retention_are_the_same()
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
WithRetention(100);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-02-20 02:23:55 +00:00
|
|
|
|
public void should_return_false_when_old_than_retention()
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
WithRetention(10);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-02-20 02:23:55 +00:00
|
|
|
|
public void should_return_true_if_release_came_out_today_and_retention_is_zero()
|
2012-02-17 09:52:29 +00:00
|
|
|
|
{
|
2014-02-20 02:23:55 +00:00
|
|
|
|
WithRetention(0);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
2014-05-13 17:57:46 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_when_release_is_not_usenet()
|
|
|
|
|
{
|
|
|
|
|
_remoteEpisode.Release.DownloadProtocol = DownloadProtocol.Torrent;
|
|
|
|
|
|
|
|
|
|
WithRetention(10);
|
|
|
|
|
WithAge(100);
|
|
|
|
|
|
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2012-02-17 09:52:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|