Refactored retention spec

This commit is contained in:
Mark McDowall 2014-02-19 18:23:55 -08:00
parent 811122f879
commit 46f904d165
2 changed files with 27 additions and 29 deletions

View File

@ -20,65 +20,62 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
parseResult = new RemoteEpisode parseResult = new RemoteEpisode
{ {
Release = new ReleaseInfo Release = new ReleaseInfo()
{
PublishDate = DateTime.Now.AddDays(-100)
}
}; };
} }
private void WithUnlimitedRetention() private void WithRetention(int days)
{ {
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(0); Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(days);
} }
private void WithLongRetention() private void WithAge(int days)
{ {
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(1000); parseResult.Release.PublishDate = DateTime.Now.AddDays(-days);
}
private void WithShortRetention()
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(10);
}
private void WithEqualRetention()
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(100);
} }
[Test] [Test]
public void unlimited_retention_should_return_true() public void should_return_true_when_retention_is_set_to_zero()
{ {
WithUnlimitedRetention(); WithRetention(0);
WithAge(100);
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue(); Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
} }
[Test] [Test]
public void longer_retention_should_return_true() public void should_return_true_when_release_if_younger_than_retention()
{ {
WithLongRetention(); WithRetention(1000);
WithAge(100);
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue(); Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
} }
[Test] [Test]
public void equal_retention_should_return_true() public void should_return_true_when_release_and_retention_are_the_same()
{ {
WithEqualRetention(); WithRetention(100);
WithAge(100);
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue(); Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
} }
[Test] [Test]
public void shorter_retention_should_return_false() public void should_return_false_when_old_than_retention()
{ {
WithShortRetention(); WithRetention(10);
WithAge(100);
Subject.IsSatisfiedBy(parseResult, null).Should().BeFalse(); Subject.IsSatisfiedBy(parseResult, null).Should().BeFalse();
} }
[Test] [Test]
public void zeroDay_report_should_return_true() public void should_return_true_if_release_came_out_today_and_retention_is_zero()
{ {
WithUnlimitedRetention(); WithRetention(0);
WithAge(100);
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue(); Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
} }
} }

View File

@ -28,9 +28,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{ {
var age = subject.Release.Age; var age = subject.Release.Age;
var retention = _configService.Retention;
_logger.Trace("Checking if report meets retention requirements. {0}", age); _logger.Trace("Checking if report meets retention requirements. {0}", age);
if (_configService.Retention > 0 && age > _configService.Retention) if (retention > 0 && age > retention)
{ {
_logger.Trace("Report age: {0} rejected by user's retention limit", age); _logger.Trace("Report age: {0} rejected by user's retention limit", age);
return false; return false;