@ -4,7 +4,7 @@ using System.Linq;
using Moq ;
using Moq ;
using NzbDrone.Core.Indexers ;
using NzbDrone.Core.Indexers ;
using NzbDrone.Core.Profiles.Delay ;
using NzbDrone.Core.Profiles.Delay ;
using NzbDrone.Core. Tv ;
using NzbDrone.Core. Music ;
using NzbDrone.Core.Profiles ;
using NzbDrone.Core.Profiles ;
using NzbDrone.Core.Qualities ;
using NzbDrone.Core.Qualities ;
using NzbDrone.Core.Parser.Model ;
using NzbDrone.Core.Parser.Model ;
@ -26,33 +26,32 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
GivenPreferredDownloadProtocol ( DownloadProtocol . Usenet ) ;
GivenPreferredDownloadProtocol ( DownloadProtocol . Usenet ) ;
}
}
private Episode GivenEpisode ( int id )
private Album GivenAlbum ( int id )
{
{
return Builder < Episode > . CreateNew ( )
return Builder < Album > . CreateNew ( )
. With ( e = > e . Id = id )
. With ( e = > e . Id = id )
. With ( e = > e . EpisodeNumber = id )
. Build ( ) ;
. Build ( ) ;
}
}
private Remote Episode GivenRemoteEpisode ( List < Episode > episode s, QualityModel quality , int age = 0 , long size = 0 , DownloadProtocol downloadProtocol = DownloadProtocol . Usenet )
private Remote Album GivenRemoteAlbum ( List < Album > album s, QualityModel quality , int age = 0 , long size = 0 , DownloadProtocol downloadProtocol = DownloadProtocol . Usenet )
{
{
var remote Episode = new RemoteEpisode ( ) ;
var remote Album = new RemoteAlbum ( ) ;
remote Episode. ParsedEpisodeInfo = new ParsedEpisode Info( ) ;
remote Album. ParsedAlbumInfo = new ParsedAlbum Info( ) ;
remote Episode. ParsedEpisode Info. Quality = quality ;
remote Album. ParsedAlbum Info. Quality = quality ;
remote Episode. Episodes = new List < Episode > ( ) ;
remote Album. Albums = new List < Album > ( ) ;
remote Episode. Episodes . AddRange ( episode s) ;
remote Album. Albums . AddRange ( album s) ;
remote Episode . Release = new ReleaseInfo ( ) ;
remote Album . Release = new ReleaseInfo ( ) ;
remote Episode . Release . PublishDate = DateTime . Now . AddDays ( - age ) ;
remote Album . Release . PublishDate = DateTime . Now . AddDays ( - age ) ;
remote Episode . Release . Size = size ;
remote Album . Release . Size = size ;
remote Episode . Release . DownloadProtocol = downloadProtocol ;
remote Album . Release . DownloadProtocol = downloadProtocol ;
remote Episode. Series = Builder < Series > . CreateNew ( )
remote Album. Artist = Builder < Artist > . CreateNew ( )
. With ( e = > e . Profile = new Profile { Items = Qualities . QualityFixture . GetDefaultQualities ( ) } )
. With ( e = > e . Profile = new Profile { Items = Qualities . QualityFixture . GetDefaultQualities ( ) } )
. Build ( ) ;
. Build ( ) ;
return remote Episode ;
return remote Album ;
}
}
private void GivenPreferredDownloadProtocol ( DownloadProtocol downloadProtocol )
private void GivenPreferredDownloadProtocol ( DownloadProtocol downloadProtocol )
@ -68,103 +67,75 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
[Test]
public void should_put_propers_before_non_propers ( )
public void should_put_propers_before_non_propers ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 , new Revision ( version : 1 ) ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 , new Revision ( version : 1 ) ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 , new Revision ( version : 2 ) ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 , new Revision ( version : 2 ) ) ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode. ParsedEpisode Info. Quality . Revision . Version . Should ( ) . Be ( 2 ) ;
qualifiedReports . First ( ) . Remote Album. ParsedAlbum Info. Quality . Revision . Version . Should ( ) . Be ( 2 ) ;
}
}
[Test]
[Test]
public void should_put_higher_quality_before_lower ( )
public void should_put_higher_quality_before_lower ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_192 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_192 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . RemoteEpisode . ParsedEpisodeInfo . Quality . Quality . Should ( ) . Be ( Quality . MP3_256 ) ;
qualifiedReports . First ( ) . RemoteAlbum . ParsedAlbumInfo . Quality . Quality . Should ( ) . Be ( Quality . MP3_256 ) ;
}
[Test]
public void should_order_by_lowest_number_of_episodes ( )
{
var remoteEpisode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteEpisode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode1 ) ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . RemoteEpisode . Episodes . First ( ) . EpisodeNumber . Should ( ) . Be ( 1 ) ;
}
[Test]
public void should_order_by_lowest_number_of_episodes_with_multiple_episodes ( )
{
var remoteEpisode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 2 ) , GivenEpisode ( 3 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteEpisode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) , GivenEpisode ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode1 ) ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . RemoteEpisode . Episodes . First ( ) . EpisodeNumber . Should ( ) . Be ( 1 ) ;
}
}
[Test]
[Test]
public void should_order_by_age_then_largest_rounded_to_200mb ( )
public void should_order_by_age_then_largest_rounded_to_200mb ( )
{
{
var remote EpisodeSd = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_192 ) , size : 100. Megabytes ( ) , age : 1 ) ;
var remoteAlbumSd = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_192 ) , size : 100. Megabytes ( ) , age : 1 ) ;
var remote EpisodeHdSmallOld = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 1200. Megabytes ( ) , age : 1000 ) ;
var remoteAlbumHdSmallOld = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 1200. Megabytes ( ) , age : 1000 ) ;
var remote EpisodeSmallYoung = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 1250. Megabytes ( ) , age : 10 ) ;
var remoteAlbumSmallYoung = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 1250. Megabytes ( ) , age : 10 ) ;
var remote EpisodeHdLargeYoung = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 3000. Megabytes ( ) , age : 1 ) ;
var remoteAlbumHdLargeYoung = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 3000. Megabytes ( ) , age : 1 ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode Sd) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbumSd ) ) ;
decisions . Add ( new DownloadDecision ( remote Episode HdSmallOld) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbumHdSmallOld ) ) ;
decisions . Add ( new DownloadDecision ( remote Episode SmallYoung) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbumSmallYoung ) ) ;
decisions . Add ( new DownloadDecision ( remote Episode HdLargeYoung) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbumHdLargeYoung ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode. Should ( ) . Be ( remoteEpisode HdLargeYoung) ;
qualifiedReports . First ( ) . RemoteAlbum . Should ( ) . Be ( remoteAlbumHdLargeYoung ) ;
}
}
[Test]
[Test]
public void should_order_by_youngest ( )
public void should_order_by_youngest ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , age : 10 ) ;
var remoteAlbum1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , age : 10 ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , age : 5 ) ;
var remoteAlbum2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , age : 5 ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode. Should ( ) . Be ( remoteEpisode 2) ;
qualifiedReports . First ( ) . Remote Album. Should ( ) . Be ( remoteAlbum 2) ;
}
}
[Test]
[Test]
public void should_not_throw_if_no_episodes_are_found ( )
public void should_not_throw_if_no_episodes_are_found ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 500. Megabytes ( ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 500. Megabytes ( ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 500. Megabytes ( ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , size : 500. Megabytes ( ) ) ;
remote Episode1. Episodes = new List < Episode > ( ) ;
remote Album1. Albums = new List < Album > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
Subject . PrioritizeDecisions ( decisions ) ;
Subject . PrioritizeDecisions ( decisions ) ;
}
}
@ -174,15 +145,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
{
GivenPreferredDownloadProtocol ( DownloadProtocol . Usenet ) ;
GivenPreferredDownloadProtocol ( DownloadProtocol . Usenet ) ;
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Torrent ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Torrent ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Usenet ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Usenet ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode . Release . DownloadProtocol . Should ( ) . Be ( DownloadProtocol . Usenet ) ;
qualifiedReports . First ( ) . Remote Album . Release . DownloadProtocol . Should ( ) . Be ( DownloadProtocol . Usenet ) ;
}
}
[Test]
[Test]
@ -190,69 +161,36 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
{
GivenPreferredDownloadProtocol ( DownloadProtocol . Torrent ) ;
GivenPreferredDownloadProtocol ( DownloadProtocol . Torrent ) ;
var remoteEpisode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Torrent ) ;
var remoteAlbum1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Torrent ) ;
var remoteEpisode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Usenet ) ;
var remoteAlbum2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) , downloadProtocol : DownloadProtocol . Usenet ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode1 ) ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . RemoteEpisode . Release . DownloadProtocol . Should ( ) . Be ( DownloadProtocol . Torrent ) ;
}
[Test]
public void should_prefer_season_pack_above_single_episode ( )
{
var remoteEpisode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) , GivenEpisode ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteEpisode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
remoteEpisode1 . ParsedEpisodeInfo . FullSeason = true ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode1 ) ) ;
decisions . Add ( new DownloadDecision ( remoteEpisode2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . RemoteEpisode . ParsedEpisodeInfo . FullSeason . Should ( ) . BeTrue ( ) ;
}
[Test]
public void should_prefer_multiepisode_over_single_episode_for_anime ( )
{
var remoteEpisode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) , GivenEpisode ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteEpisode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
remoteEpisode1 . Series . SeriesType = SeriesTypes . Anime ;
remoteEpisode2 . Series . SeriesType = SeriesTypes . Anime ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbum1 ) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbum2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode. Episodes . Count . Should ( ) . Be ( remoteEpisode1 . Episodes . Cou nt) ;
qualifiedReports . First ( ) . RemoteAlbum . Release . DownloadProtocol . Should ( ) . Be ( DownloadProtocol . Torrent ) ;
}
}
[Test]
[Test]
public void should_prefer_single_ episode_over_multi_episode_for_non_anime ( )
public void should_prefer_single_album_over_multi_album ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) , GivenEpisode ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteAlbum1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) , GivenAlbum ( 2 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteAlbum2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbum1 ) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remoteAlbum2 ) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode. Episode s. Count . Should ( ) . Be ( remote Episode2. Episode s. Count ) ;
qualifiedReports . First ( ) . RemoteAlbum . Albums . Count . Should ( ) . Be ( remoteAlbum2 . Albums . Count ) ;
}
}
[Test]
[Test]
public void should_prefer_releases_with_more_seeders ( )
public void should_prefer_releases_with_more_seeders ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteAlbum1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remoteAlbum2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
torrentInfo1 . PublishDate = DateTime . Now ;
torrentInfo1 . PublishDate = DateTime . Now ;
@ -263,22 +201,22 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
var torrentInfo2 = torrentInfo1 . JsonClone ( ) ;
var torrentInfo2 = torrentInfo1 . JsonClone ( ) ;
torrentInfo2 . Seeders = 100 ;
torrentInfo2 . Seeders = 100 ;
remote Episode 1. Release = torrentInfo1 ;
remote Album 1. Release = torrentInfo1 ;
remote Episode 2. Release = torrentInfo2 ;
remote Album 2. Release = torrentInfo2 ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Episode . Release ) . Seeders . Should ( ) . Be ( torrentInfo2 . Seeders ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Album . Release ) . Seeders . Should ( ) . Be ( torrentInfo2 . Seeders ) ;
}
}
[Test]
[Test]
public void should_prefer_releases_with_more_peers_given_equal_number_of_seeds ( )
public void should_prefer_releases_with_more_peers_given_equal_number_of_seeds ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
torrentInfo1 . PublishDate = DateTime . Now ;
torrentInfo1 . PublishDate = DateTime . Now ;
@ -291,22 +229,22 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
var torrentInfo2 = torrentInfo1 . JsonClone ( ) ;
var torrentInfo2 = torrentInfo1 . JsonClone ( ) ;
torrentInfo2 . Peers = 100 ;
torrentInfo2 . Peers = 100 ;
remote Episode 1. Release = torrentInfo1 ;
remote Album 1. Release = torrentInfo1 ;
remote Episode 2. Release = torrentInfo2 ;
remote Album 2. Release = torrentInfo2 ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Episode . Release ) . Peers . Should ( ) . Be ( torrentInfo2 . Peers ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Album . Release ) . Peers . Should ( ) . Be ( torrentInfo2 . Peers ) ;
}
}
[Test]
[Test]
public void should_prefer_releases_with_more_peers_no_seeds ( )
public void should_prefer_releases_with_more_peers_no_seeds ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
torrentInfo1 . PublishDate = DateTime . Now ;
torrentInfo1 . PublishDate = DateTime . Now ;
@ -320,22 +258,22 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
torrentInfo2 . Seeders = 0 ;
torrentInfo2 . Seeders = 0 ;
torrentInfo2 . Peers = 100 ;
torrentInfo2 . Peers = 100 ;
remote Episode 1. Release = torrentInfo1 ;
remote Album 1. Release = torrentInfo1 ;
remote Episode 2. Release = torrentInfo2 ;
remote Album 2. Release = torrentInfo2 ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Episode . Release ) . Peers . Should ( ) . Be ( torrentInfo2 . Peers ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Album . Release ) . Peers . Should ( ) . Be ( torrentInfo2 . Peers ) ;
}
}
[Test]
[Test]
public void should_prefer_first_release_if_peers_and_size_are_too_similar ( )
public void should_prefer_first_release_if_peers_and_size_are_too_similar ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
torrentInfo1 . PublishDate = DateTime . Now ;
torrentInfo1 . PublishDate = DateTime . Now ;
@ -349,42 +287,42 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
torrentInfo2 . Peers = 10 ;
torrentInfo2 . Peers = 10 ;
torrentInfo1 . Size = 250. Megabytes ( ) ;
torrentInfo1 . Size = 250. Megabytes ( ) ;
remote Episode 1. Release = torrentInfo1 ;
remote Album 1. Release = torrentInfo1 ;
remote Episode 2. Release = torrentInfo2 ;
remote Album 2. Release = torrentInfo2 ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Episode . Release ) . Should ( ) . Be ( torrentInfo1 ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Album . Release ) . Should ( ) . Be ( torrentInfo1 ) ;
}
}
[Test]
[Test]
public void should_prefer_first_release_if_age_and_size_are_too_similar ( )
public void should_prefer_first_release_if_age_and_size_are_too_similar ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_256 ) ) ;
remote Episode 1. Release . PublishDate = DateTime . UtcNow . AddDays ( - 100 ) ;
remote Album 1. Release . PublishDate = DateTime . UtcNow . AddDays ( - 100 ) ;
remote Episode 1. Release . Size = 200. Megabytes ( ) ;
remote Album 1. Release . Size = 200. Megabytes ( ) ;
remote Episode 2. Release . PublishDate = DateTime . UtcNow . AddDays ( - 150 ) ;
remote Album 2. Release . PublishDate = DateTime . UtcNow . AddDays ( - 150 ) ;
remote Episode 2. Release . Size = 250. Megabytes ( ) ;
remote Album 2. Release . Size = 250. Megabytes ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
qualifiedReports . First ( ) . Remote Episode . Release . Should ( ) . Be ( remote Episode 1. Release ) ;
qualifiedReports . First ( ) . Remote Album . Release . Should ( ) . Be ( remote Album 1. Release ) ;
}
}
[Test]
[Test]
public void should_prefer_quality_over_the_number_of_peers ( )
public void should_prefer_quality_over_the_number_of_peers ( )
{
{
var remote Episode1 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_512 ) ) ;
var remote Album1 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_512 ) ) ;
var remote Episode2 = GivenRemoteEpisode ( new List < Episode > { GivenEpisode ( 1 ) } , new QualityModel ( Quality . MP3_192 ) ) ;
var remote Album2 = GivenRemoteAlbum ( new List < Album > { GivenAlbum ( 1 ) } , new QualityModel ( Quality . MP3_192 ) ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
var torrentInfo1 = new TorrentInfo ( ) ;
torrentInfo1 . PublishDate = DateTime . Now ;
torrentInfo1 . PublishDate = DateTime . Now ;
@ -398,15 +336,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
torrentInfo2 . Peers = 10 ;
torrentInfo2 . Peers = 10 ;
torrentInfo1 . Size = 250. Megabytes ( ) ;
torrentInfo1 . Size = 250. Megabytes ( ) ;
remote Episode 1. Release = torrentInfo1 ;
remote Album 1. Release = torrentInfo1 ;
remote Episode 2. Release = torrentInfo2 ;
remote Album 2. Release = torrentInfo2 ;
var decisions = new List < DownloadDecision > ( ) ;
var decisions = new List < DownloadDecision > ( ) ;
decisions . Add ( new DownloadDecision ( remote Episode 1) ) ;
decisions . Add ( new DownloadDecision ( remote Album 1) ) ;
decisions . Add ( new DownloadDecision ( remote Episode 2) ) ;
decisions . Add ( new DownloadDecision ( remote Album 2) ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
var qualifiedReports = Subject . PrioritizeDecisions ( decisions ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Episode . Release ) . Should ( ) . Be ( torrentInfo1 ) ;
( ( TorrentInfo ) qualifiedReports . First ( ) . Remote Album . Release ) . Should ( ) . Be ( torrentInfo1 ) ;
}
}
}
}
}
}