sonarr-repo-only/src/NzbDrone.Core.Test/DecisionEngineTests/RetentionSpecificationFixtu...

82 lines
2.1 KiB
C#
Raw Normal View History

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;
using NzbDrone.Core.DecisionEngine.Specifications;
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]
public class RetentionSpecificationFixture : CoreTest<RetentionSpecification>
2012-02-17 09:52:29 +00:00
{
private RemoteEpisode parseResult;
2012-02-17 09:52:29 +00:00
[SetUp]
public void Setup()
{
parseResult = new RemoteEpisode
2012-02-17 09:52:29 +00:00
{
2014-02-20 02:23:55 +00:00
Release = new ReleaseInfo()
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-02-20 02:23:55 +00:00
parseResult.Release.PublishDate = DateTime.Now.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);
Subject.IsSatisfiedBy(parseResult, 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);
Subject.IsSatisfiedBy(parseResult, 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);
Subject.IsSatisfiedBy(parseResult, 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);
Subject.IsSatisfiedBy(parseResult, 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);
Subject.IsSatisfiedBy(parseResult, null).Accepted.Should().BeTrue();
2012-02-17 09:52:29 +00:00
}
}
}