@ -9,14 +9,15 @@ using NUnit.Framework;
using NzbDrone.Core.DecisionEngine ;
using NzbDrone.Core.DecisionEngine.Specifications.RssSync ;
using NzbDrone.Core.Download.Pending ;
using NzbDrone.Core.Indexers ;
using NzbDrone.Core.IndexerSearch.Definitions ;
using NzbDrone.Core.MediaFiles ;
using NzbDrone.Core.Parser.Model ;
using NzbDrone.Core.Profiles ;
using NzbDrone.Core.Profiles.Delay ;
using NzbDrone.Core.Qualities ;
using NzbDrone.Core.Test.Framework ;
using NzbDrone.Core.Tv ;
using NzbDrone.Test.Common ;
namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
{
@ -24,6 +25,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
public class DelaySpecificationFixture : CoreTest < DelaySpecification >
{
private Profile _profile ;
private DelayProfile _delayProfile ;
private RemoteEpisode _remoteEpisode ;
[SetUp]
@ -32,6 +34,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
_profile = Builder < Profile > . CreateNew ( )
. Build ( ) ;
_delayProfile = Builder < DelayProfile > . CreateNew ( )
. With ( d = > d . PreferredProtocol = DownloadProtocol . Usenet )
. Build ( ) ;
var series = Builder < Series > . CreateNew ( )
. With ( s = > s . Profile = _profile )
. Build ( ) ;
@ -46,13 +52,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
_profile . Items . Add ( new ProfileQualityItem { Allowed = true , Quality = Quality . Bluray720p } ) ;
_profile . Cutoff = Quality . WEBDL720p ;
_profile . GrabDelayMode = GrabDelayMode . Always ;
_remoteEpisode . ParsedEpisodeInfo = new ParsedEpisodeInfo ( ) ;
_remoteEpisode . Release = new ReleaseInfo ( ) ;
_remoteEpisode . Release . DownloadProtocol = DownloadProtocol . Usenet ;
_remoteEpisode . Episodes = Builder < Episode > . CreateListOfSize ( 1 ) . Build ( ) . ToList ( ) ;
_remoteEpisode . Episodes . First ( ) . EpisodeFileId = 0 ;
Mocker . GetMock < IDelayProfileService > ( )
. Setup ( s = > s . BestForTags ( It . IsAny < HashSet < int > > ( ) ) )
. Returns ( _delayProfile ) ;
Mocker . GetMock < IPendingReleaseService > ( )
. Setup ( s = > s . GetPendingRemoteEpisodes ( It . IsAny < int > ( ) ) )
. Returns ( new List < RemoteEpisode > ( ) ) ;
}
private void GivenExistingFile ( QualityModel quality )
@ -81,7 +95,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
[Test]
public void should_be_true_when_profile_does_not_have_a_delay ( )
{
_ profile. Grab Delay = 0 ;
_ delayProfile. Usenet Delay = 0 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
@ -99,8 +113,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
{
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . HDTV720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow . AddHours ( - 10 ) ;
_ profile. Grab Delay = 1 ;
_ delayProfile. Usenet Delay = 1 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
@ -111,7 +125,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . SDTV ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_ profile. Grab Delay = 12 ;
_ delayProfile. Usenet Delay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeFalse ( ) ;
}
@ -129,7 +143,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
. Setup ( s = > s . IsRevisionUpgrade ( It . IsAny < QualityModel > ( ) , It . IsAny < QualityModel > ( ) ) )
. Returns ( true ) ;
_ profile. Grab Delay = 12 ;
_ delayProfile. Usenet Delay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
@ -147,47 +161,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
. Setup ( s = > s . IsRevisionUpgrade ( It . IsAny < QualityModel > ( ) , It . IsAny < QualityModel > ( ) ) )
. Returns ( true ) ;
_profile . GrabDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
[Test]
public void should_be_true_when_release_meets_cutoff_and_mode_is_cutoff ( )
{
_profile . GrabDelayMode = GrabDelayMode . Cutoff ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . WEBDL720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
_delayProfile . UsenetDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
[Test]
public void should_be_true_when_release_exceeds_cutoff_and_mode_is_cutoff ( )
{
_profile . GrabDelayMode = GrabDelayMode . Cutoff ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . Bluray720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
[Test]
public void should_be_false_when_release_is_below_cutoff_and_mode_is_cutoff ( )
{
_profile . GrabDelayMode = GrabDelayMode . Cutoff ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . HDTV720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeFalse ( ) ;
}
[Test]
public void should_be_false_when_release_is_proper_for_existing_episode_of_different_quality ( )
{
@ -196,82 +174,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
GivenExistingFile ( new QualityModel ( Quality . SDTV ) ) ;
_profile . GrabDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeFalse ( ) ;
}
[Test]
public void should_be_false_when_release_is_first_detected_and_mode_is_first ( )
{
_profile . GrabDelayMode = GrabDelayMode . First ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . HDTV720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
Mocker . GetMock < IPendingReleaseService > ( )
. Setup ( s = > s . GetPendingRemoteEpisodes ( It . IsAny < Int32 > ( ) ) )
. Returns ( new List < RemoteEpisode > ( ) ) ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeFalse ( ) ;
}
[Test]
public void should_be_false_when_release_is_not_first_but_oldest_has_not_expired_and_type_is_first ( )
{
_profile . GrabDelayMode = GrabDelayMode . First ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . HDTV720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
Mocker . GetMock < IPendingReleaseService > ( )
. Setup ( s = > s . GetPendingRemoteEpisodes ( It . IsAny < Int32 > ( ) ) )
. Returns ( new List < RemoteEpisode > { _remoteEpisode . JsonClone ( ) } ) ;
_delayProfile . UsenetDelay = 12 ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeFalse ( ) ;
}
[Test]
public void should_be_true_when_existing_pending_release_expired_and_mode_is_first ( )
{
_profile . GrabDelayMode = GrabDelayMode . First ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . WEBDL720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
var pendingRemoteEpisode = _remoteEpisode . JsonClone ( ) ;
pendingRemoteEpisode . Release . PublishDate = DateTime . UtcNow . AddHours ( - 15 ) ;
Mocker . GetMock < IPendingReleaseService > ( )
. Setup ( s = > s . GetPendingRemoteEpisodes ( It . IsAny < Int32 > ( ) ) )
. Returns ( new List < RemoteEpisode > { pendingRemoteEpisode } ) ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
[Test]
public void should_be_true_when_one_existing_pending_release_is_expired_and_mode_is_first ( )
{
_profile . GrabDelayMode = GrabDelayMode . First ;
_remoteEpisode . ParsedEpisodeInfo . Quality = new QualityModel ( Quality . WEBDL720p ) ;
_remoteEpisode . Release . PublishDate = DateTime . UtcNow ;
_profile . GrabDelay = 12 ;
var pendingRemoteEpisode1 = _remoteEpisode . JsonClone ( ) ;
pendingRemoteEpisode1 . Release . PublishDate = DateTime . UtcNow . AddHours ( - 15 ) ;
var pendingRemoteEpisode2 = _remoteEpisode . JsonClone ( ) ;
pendingRemoteEpisode2 . Release . PublishDate = DateTime . UtcNow . AddHours ( 5 ) ;
Mocker . GetMock < IPendingReleaseService > ( )
. Setup ( s = > s . GetPendingRemoteEpisodes ( It . IsAny < Int32 > ( ) ) )
. Returns ( new List < RemoteEpisode > { pendingRemoteEpisode1 , pendingRemoteEpisode2 } ) ;
Subject . IsSatisfiedBy ( _remoteEpisode , null ) . Accepted . Should ( ) . BeTrue ( ) ;
}
}
}