mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 01:37:07 +00:00
Added unit tests.
This commit is contained in:
parent
462eb53897
commit
64ca52667b
3 changed files with 113 additions and 0 deletions
|
@ -115,6 +115,7 @@
|
||||||
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
|
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
|
||||||
<Compile Include="ProviderTests\AnalyticsProviderTests\AnalyticsProviderFixture.cs" />
|
<Compile Include="ProviderTests\AnalyticsProviderTests\AnalyticsProviderFixture.cs" />
|
||||||
<Compile Include="ProviderTests\ConfigProviderTests\ConfigCachingFixture.cs" />
|
<Compile Include="ProviderTests\ConfigProviderTests\ConfigCachingFixture.cs" />
|
||||||
|
<Compile Include="ProviderTests\DecisionEngineTests\RetentionSpecificationFixture.cs" />
|
||||||
<Compile Include="ProviderTests\DecisionEngineTests\QualityAllowedByProfileSpecificationFixtrue.cs" />
|
<Compile Include="ProviderTests\DecisionEngineTests\QualityAllowedByProfileSpecificationFixtrue.cs" />
|
||||||
<Compile Include="ProviderTests\DecisionEngineTests\UpgradeHistorySpecificationFixtrue.cs" />
|
<Compile Include="ProviderTests\DecisionEngineTests\UpgradeHistorySpecificationFixtrue.cs" />
|
||||||
<Compile Include="ProviderTests\DecisionEngineTests\UpgradeDiskSpecificationFixtrue.cs" />
|
<Compile Include="ProviderTests\DecisionEngineTests\UpgradeDiskSpecificationFixtrue.cs" />
|
||||||
|
|
|
@ -44,6 +44,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
||||||
Mocker.GetMock<AlreadyInQueueSpecification>()
|
Mocker.GetMock<AlreadyInQueueSpecification>()
|
||||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
|
Mocker.GetMock<RetentionSpecification>()
|
||||||
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||||
|
.Returns(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WithProfileNotAllowed()
|
private void WithProfileNotAllowed()
|
||||||
|
@ -74,6 +78,13 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WithOverRetention()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<RetentionSpecification>()
|
||||||
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||||
|
.Returns(false);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_be_allowed_if_all_conditions_are_met()
|
public void should_be_allowed_if_all_conditions_are_met()
|
||||||
{
|
{
|
||||||
|
@ -108,12 +119,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
||||||
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
|
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_be_allowed_if_report_is_over_retention()
|
||||||
|
{
|
||||||
|
WithOverRetention();
|
||||||
|
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_be_allowed_if_none_of_conditions_are_met()
|
public void should_not_be_allowed_if_none_of_conditions_are_met()
|
||||||
{
|
{
|
||||||
WithNoDiskUpgrade();
|
WithNoDiskUpgrade();
|
||||||
WithNotAcceptableSize();
|
WithNotAcceptableSize();
|
||||||
WithProfileNotAllowed();
|
WithProfileNotAllowed();
|
||||||
|
WithOverRetention();
|
||||||
|
|
||||||
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
|
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
// 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.Core;
|
||||||
|
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 RetentionSpecificationFixture : CoreTest
|
||||||
|
{
|
||||||
|
private RetentionSpecification retentionSpecification;
|
||||||
|
|
||||||
|
private EpisodeParseResult parseResult;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
retentionSpecification = Mocker.Resolve<RetentionSpecification>();
|
||||||
|
|
||||||
|
parseResult = new EpisodeParseResult
|
||||||
|
{
|
||||||
|
Age = 100
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithUnlimitedRetention()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.Retention).Returns(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithLongRetention()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.Retention).Returns(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithShortRetention()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.Retention).Returns(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithEqualRetention()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.Retention).Returns(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void unlimited_retention_should_return_true()
|
||||||
|
{
|
||||||
|
WithUnlimitedRetention();
|
||||||
|
retentionSpecification.IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void longer_retention_should_return_true()
|
||||||
|
{
|
||||||
|
WithLongRetention();
|
||||||
|
retentionSpecification.IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void equal_retention_should_return_true()
|
||||||
|
{
|
||||||
|
WithEqualRetention();
|
||||||
|
retentionSpecification.IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void shorter_retention_should_return_false()
|
||||||
|
{
|
||||||
|
WithShortRetention();
|
||||||
|
retentionSpecification.IsSatisfiedBy(parseResult).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void zeroDay_report_should_return_true()
|
||||||
|
{
|
||||||
|
WithUnlimitedRetention();
|
||||||
|
retentionSpecification.IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue