mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
New: Custom Formats
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
+116
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class CustomFormatAllowedByProfileSpecificationFixture : CoreTest<CustomFormatAllowedbyProfileSpecification>
|
||||
{
|
||||
private RemoteBook _remoteAlbum;
|
||||
|
||||
private CustomFormat _format1;
|
||||
private CustomFormat _format2;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_format1 = new CustomFormat("Awesome Format");
|
||||
_format1.Id = 1;
|
||||
|
||||
_format2 = new CustomFormat("Cool Format");
|
||||
_format2.Id = 2;
|
||||
|
||||
var fakeArtist = Builder<Author>.CreateNew()
|
||||
.With(c => c.QualityProfile = new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
MinFormatScore = 1
|
||||
})
|
||||
.Build();
|
||||
|
||||
_remoteAlbum = new RemoteBook
|
||||
{
|
||||
Author = fakeArtist,
|
||||
ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
};
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats(_format1, _format2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_allow_if_format_score_greater_than_min()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { _format1 };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name);
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_deny_if_format_score_not_greater_than_min()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { _format2 };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name);
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Console.WriteLine(_remoteAlbum.CustomFormatScore);
|
||||
Console.WriteLine(_remoteAlbum.Author.QualityProfile.Value.MinFormatScore);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_deny_if_format_score_not_greater_than_min_2()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { _format2, _format1 };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name);
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_allow_if_all_format_is_defined_in_profile()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { _format2, _format1 };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name, _format2.Name);
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_deny_if_no_format_was_parsed_and_min_score_positive()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name, _format2.Name);
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_allow_if_no_format_was_parsed_min_score_is_zero()
|
||||
{
|
||||
_remoteAlbum.CustomFormats = new List<CustomFormat> { };
|
||||
_remoteAlbum.Author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_format1.Name, _format2.Name);
|
||||
_remoteAlbum.Author.QualityProfile.Value.MinFormatScore = 0;
|
||||
_remoteAlbum.CustomFormatScore = _remoteAlbum.Author.QualityProfile.Value.CalculateCustomFormatScore(_remoteAlbum.CustomFormats);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
@@ -11,8 +12,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[TestFixture]
|
||||
public class CutoffSpecificationFixture : CoreTest<UpgradableSpecification>
|
||||
{
|
||||
private static readonly int NoPreferredWordScore = 0;
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_current_book_is_less_than_cutoff()
|
||||
{
|
||||
@@ -20,10 +19,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
new List<QualityModel> { new QualityModel(Quality.Unknown, new Revision(version: 2)) },
|
||||
NoPreferredWordScore).Should().BeTrue();
|
||||
new List<CustomFormat>()).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -33,10 +33,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
NoPreferredWordScore).Should().BeFalse();
|
||||
new List<CustomFormat>()).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -46,10 +47,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.AZW3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
NoPreferredWordScore).Should().BeFalse();
|
||||
new List<CustomFormat>()).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -59,10 +61,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3, new Revision(version: 1)) },
|
||||
NoPreferredWordScore,
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3, new Revision(version: 2))).Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -73,30 +76,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
NoPreferredWordScore,
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.FLAC, new Revision(version: 2))).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_cutoffs_are_met_and_score_is_higher()
|
||||
{
|
||||
QualityProfile profile = new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
Subject.CutoffNotMet(
|
||||
profile,
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
NoPreferredWordScore,
|
||||
new QualityModel(Quality.FLAC, new Revision(version: 2)),
|
||||
10).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_cutoffs_are_met_but_is_a_revision_upgrade()
|
||||
{
|
||||
@@ -104,14 +91,31 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
};
|
||||
|
||||
Subject.CutoffNotMet(
|
||||
profile,
|
||||
new List<QualityModel> { new QualityModel(Quality.FLAC, new Revision(version: 1)) },
|
||||
NoPreferredWordScore,
|
||||
new QualityModel(Quality.FLAC, new Revision(version: 2)),
|
||||
NoPreferredWordScore).Should().BeTrue();
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.FLAC, new Revision(version: 2))).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_quality_profile_does_not_allow_upgrades_but_cutoff_is_set_to_highest_quality()
|
||||
{
|
||||
QualityProfile profile = new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false
|
||||
};
|
||||
|
||||
Subject.CutoffNotMet(
|
||||
profile,
|
||||
new List<QualityModel> { new QualityModel(Quality.Unknown, new Revision(version: 1)) },
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3, new Revision(version: 2))).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,15 +416,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBook1 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC));
|
||||
var remoteBook2 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC));
|
||||
|
||||
remoteBook1.PreferredWordScore = 10;
|
||||
remoteBook2.PreferredWordScore = 0;
|
||||
remoteBook1.CustomFormatScore = 10;
|
||||
remoteBook2.CustomFormatScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteBook1));
|
||||
decisions.Add(new DownloadDecision(remoteBook2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteBook.PreferredWordScore.Should().Be(10);
|
||||
qualifiedReports.First().RemoteBook.CustomFormatScore.Should().Be(10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -437,8 +437,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBook1 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(1)));
|
||||
var remoteBook2 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(2)));
|
||||
|
||||
remoteBook1.PreferredWordScore = 10;
|
||||
remoteBook2.PreferredWordScore = 0;
|
||||
remoteBook1.CustomFormatScore = 10;
|
||||
remoteBook2.CustomFormatScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteBook1));
|
||||
@@ -458,8 +458,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBook1 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(1)));
|
||||
var remoteBook2 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(2)));
|
||||
|
||||
remoteBook1.PreferredWordScore = 10;
|
||||
remoteBook2.PreferredWordScore = 0;
|
||||
remoteBook1.CustomFormatScore = 10;
|
||||
remoteBook2.CustomFormatScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteBook1));
|
||||
@@ -479,8 +479,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBook1 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(1)));
|
||||
var remoteBook2 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(2)));
|
||||
|
||||
remoteBook1.PreferredWordScore = 10;
|
||||
remoteBook2.PreferredWordScore = 0;
|
||||
remoteBook1.CustomFormatScore = 10;
|
||||
remoteBook2.CustomFormatScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteBook1));
|
||||
@@ -489,7 +489,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteBook.ParsedBookInfo.Quality.Quality.Should().Be(Quality.FLAC);
|
||||
qualifiedReports.First().RemoteBook.ParsedBookInfo.Quality.Revision.Version.Should().Be(1);
|
||||
qualifiedReports.First().RemoteBook.PreferredWordScore.Should().Be(10);
|
||||
qualifiedReports.First().RemoteBook.CustomFormatScore.Should().Be(10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -536,8 +536,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBook1 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(1, 0)));
|
||||
var remoteBook2 = GivenRemoteBook(new List<Book> { GivenBook(1) }, new QualityModel(Quality.FLAC, new Revision(1, 1)));
|
||||
|
||||
remoteBook1.PreferredWordScore = 10;
|
||||
remoteBook2.PreferredWordScore = 0;
|
||||
remoteBook1.CustomFormatScore = 10;
|
||||
remoteBook2.CustomFormatScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteBook1));
|
||||
@@ -548,7 +548,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
qualifiedReports.First().RemoteBook.ParsedBookInfo.Quality.Quality.Should().Be(Quality.FLAC);
|
||||
qualifiedReports.First().RemoteBook.ParsedBookInfo.Quality.Revision.Version.Should().Be(1);
|
||||
qualifiedReports.First().RemoteBook.ParsedBookInfo.Quality.Revision.Real.Should().Be(0);
|
||||
qualifiedReports.First().RemoteBook.PreferredWordScore.Should().Be(10);
|
||||
qualifiedReports.First().RemoteBook.CustomFormatScore.Should().Be(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Queue;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
@@ -31,11 +34,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Mocker.Resolve<UpgradableSpecification>();
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats();
|
||||
|
||||
_author = Builder<Author>.CreateNew()
|
||||
.With(e => e.QualityProfile = new QualityProfile
|
||||
{
|
||||
UpgradeAllowed = true,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(),
|
||||
MinFormatScore = 0
|
||||
})
|
||||
.Build();
|
||||
|
||||
@@ -59,8 +66,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.With(r => r.Author = _author)
|
||||
.With(r => r.Books = new List<Book> { _book })
|
||||
.With(r => r.ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3) })
|
||||
.With(r => r.PreferredWordScore = 0)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(x => x.ParseCustomFormat(It.IsAny<RemoteBook>(), It.IsAny<long>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
}
|
||||
|
||||
private void GivenEmptyQueue()
|
||||
@@ -70,6 +81,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.Returns(new List<Queue.Queue>());
|
||||
}
|
||||
|
||||
private void GivenQueueFormats(List<CustomFormat> formats)
|
||||
{
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(x => x.ParseCustomFormat(It.IsAny<RemoteBook>(), It.IsAny<long>()))
|
||||
.Returns(formats);
|
||||
}
|
||||
|
||||
private void GivenQueue(IEnumerable<RemoteBook> remoteBooks, TrackedDownloadState trackedDownloadState = TrackedDownloadState.Downloading)
|
||||
{
|
||||
var queue = remoteBooks.Select(remoteBook => new Queue.Queue
|
||||
@@ -97,6 +115,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.With(r => r.Author = _otherAuthor)
|
||||
.With(r => r.Books = new List<Book> { _book })
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -115,6 +134,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.Build();
|
||||
|
||||
@@ -136,6 +156,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.AZW3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -153,6 +174,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -160,9 +182,17 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_qualities_are_the_same_with_higher_preferred_word_score()
|
||||
public void should_return_true_when_qualities_are_the_same_with_higher_custom_format_score()
|
||||
{
|
||||
_remoteBook.PreferredWordScore = 1;
|
||||
_remoteBook.CustomFormats = new List<CustomFormat> { new CustomFormat("My Format", new ReleaseTitleSpecification { Value = "MP3" }) { Id = 1 } };
|
||||
|
||||
var lowFormat = new List<CustomFormat> { new CustomFormat("Bad Format", new ReleaseTitleSpecification { Value = "MP3" }) { Id = 2 } };
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats(_remoteBook.CustomFormats.First(), lowFormat.First());
|
||||
|
||||
_author.QualityProfile.Value.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems("My Format");
|
||||
|
||||
GivenQueueFormats(lowFormat);
|
||||
|
||||
var remoteBook = Builder<RemoteBook>.CreateNew()
|
||||
.With(r => r.Author = _author)
|
||||
@@ -172,6 +202,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = lowFormat)
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -189,6 +220,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -208,6 +240,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -225,6 +258,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -242,6 +276,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
_remoteBook.Books.Add(_otherBook);
|
||||
@@ -261,6 +296,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
_remoteBook.Books.Add(_otherBook);
|
||||
@@ -275,6 +311,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var remoteBooks = Builder<RemoteBook>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(r => r.Author = _author)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.With(r => r.ParsedBookInfo = new ParsedBookInfo
|
||||
{
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
@@ -305,6 +342,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.FLAC)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook });
|
||||
@@ -324,6 +362,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Quality = new QualityModel(Quality.MP3)
|
||||
})
|
||||
.With(r => r.Release = _releaseInfo)
|
||||
.With(r => r.CustomFormats = new List<CustomFormat>())
|
||||
.Build();
|
||||
|
||||
GivenQueue(new List<RemoteBook> { remoteBook }, TrackedDownloadState.DownloadFailedPending);
|
||||
|
||||
+10
-9
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -33,7 +34,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Mocker.SetConstant<ITermMatcherService>(Mocker.Resolve<TermMatcherService>());
|
||||
}
|
||||
|
||||
private void GivenRestictions(string required, string ignored)
|
||||
private void GivenRestictions(List<string> required, List<string> ignored)
|
||||
{
|
||||
Mocker.GetMock<IReleaseProfileService>()
|
||||
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
|
||||
@@ -60,7 +61,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_be_true_when_title_contains_one_required_term()
|
||||
{
|
||||
GivenRestictions("WEBRip", null);
|
||||
GivenRestictions(new List<string> { "WEBRip" }, new List<string>());
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
@@ -68,7 +69,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_be_false_when_title_does_not_contain_any_required_terms()
|
||||
{
|
||||
GivenRestictions("doesnt,exist", null);
|
||||
GivenRestictions(new List<string> { "doesnt", "exist" }, new List<string>());
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
@@ -76,7 +77,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_be_true_when_title_does_not_contain_any_ignored_terms()
|
||||
{
|
||||
GivenRestictions(null, "ignored");
|
||||
GivenRestictions(new List<string>(), new List<string> { "ignored" });
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
@@ -84,7 +85,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_be_false_when_title_contains_one_anded_ignored_terms()
|
||||
{
|
||||
GivenRestictions(null, "edited");
|
||||
GivenRestictions(new List<string>(), new List<string> { "edited" });
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
@@ -95,7 +96,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[TestCase("X264,NOTTHERE")]
|
||||
public void should_ignore_case_when_matching_required(string required)
|
||||
{
|
||||
GivenRestictions(required, null);
|
||||
GivenRestictions(required.Split(',').ToList(), new List<string>());
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
@@ -106,7 +107,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[TestCase("X264,NOTTHERE")]
|
||||
public void should_ignore_case_when_matching_ignored(string ignored)
|
||||
{
|
||||
GivenRestictions(null, ignored);
|
||||
GivenRestictions(new List<string>(), ignored.Split(',').ToList());
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
@@ -120,7 +121,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
|
||||
.Returns(new List<ReleaseProfile>
|
||||
{
|
||||
new ReleaseProfile { Required = "320", Ignored = "www.Speed.cd" }
|
||||
new ReleaseProfile { Required = new List<string> { "320" }, Ignored = new List<string> { "www.Speed.cd" } }
|
||||
});
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
@@ -132,7 +133,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[TestCase(@"/\.WEB/", true)]
|
||||
public void should_match_perl_regex(string pattern, bool expected)
|
||||
{
|
||||
GivenRestictions(pattern, null);
|
||||
GivenRestictions(pattern.Split(',').ToList(), new List<string>());
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().Be(expected);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
@@ -87,7 +88,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
private void GivenUpgradeForExistingFile()
|
||||
{
|
||||
Mocker.GetMock<IUpgradableSpecification>()
|
||||
.Setup(s => s.IsUpgradable(It.IsAny<QualityProfile>(), It.IsAny<QualityModel>(), It.IsAny<int>(), It.IsAny<QualityModel>(), It.IsAny<int>()))
|
||||
.Setup(s => s.IsUpgradable(It.IsAny<QualityProfile>(), It.IsAny<QualityModel>(), It.IsAny<List<CustomFormat>>(), It.IsAny<QualityModel>(), It.IsAny<List<CustomFormat>>()))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
@@ -117,8 +118,23 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_true_when_quality_is_last_allowed_in_profile()
|
||||
public void should_be_false_when_quality_is_last_allowed_in_profile_and_bypass_disabled()
|
||||
{
|
||||
_remoteBook.Release.PublishDate = DateTime.UtcNow;
|
||||
_remoteBook.ParsedBookInfo.Quality = new QualityModel(Quality.MP3);
|
||||
|
||||
_delayProfile.UsenetDelay = 720;
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_true_when_quality_is_last_allowed_in_profile_and_bypass_enabled()
|
||||
{
|
||||
_delayProfile.UsenetDelay = 720;
|
||||
_delayProfile.BypassIfHighestQuality = true;
|
||||
|
||||
_remoteBook.Release.PublishDate = DateTime.UtcNow;
|
||||
_remoteBook.ParsedBookInfo.Quality = new QualityModel(Quality.MP3);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue();
|
||||
@@ -194,5 +210,43 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_false_when_custom_format_score_is_above_minimum_but_bypass_disabled()
|
||||
{
|
||||
_remoteBook.Release.PublishDate = DateTime.UtcNow;
|
||||
_remoteBook.CustomFormatScore = 100;
|
||||
|
||||
_delayProfile.UsenetDelay = 720;
|
||||
_delayProfile.MinimumCustomFormatScore = 50;
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_false_when_custom_format_score_is_above_minimum_and_bypass_enabled_but_under_minimum()
|
||||
{
|
||||
_remoteBook.Release.PublishDate = DateTime.UtcNow;
|
||||
_remoteBook.CustomFormatScore = 5;
|
||||
|
||||
_delayProfile.UsenetDelay = 720;
|
||||
_delayProfile.BypassIfAboveCustomFormatScore = true;
|
||||
_delayProfile.MinimumCustomFormatScore = 50;
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_true_when_custom_format_score_is_above_minimum_and_bypass_enabled()
|
||||
{
|
||||
_remoteBook.Release.PublishDate = DateTime.UtcNow;
|
||||
_remoteBook.CustomFormatScore = 100;
|
||||
|
||||
_delayProfile.UsenetDelay = 720;
|
||||
_delayProfile.BypassIfAboveCustomFormatScore = true;
|
||||
_delayProfile.MinimumCustomFormatScore = 50;
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-3
@@ -6,6 +6,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.History;
|
||||
@@ -13,9 +14,10 @@ using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
{
|
||||
[TestFixture]
|
||||
public class HistorySpecificationFixture : CoreTest<HistorySpecification>
|
||||
@@ -37,6 +39,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Mocker.Resolve<UpgradableSpecification>();
|
||||
_upgradeHistory = Mocker.Resolve<HistorySpecification>();
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats();
|
||||
|
||||
var singleBookList = new List<Book> { new Book { Id = FIRST_ALBUM_ID } };
|
||||
var doubleBookList = new List<Book>
|
||||
{
|
||||
@@ -50,6 +54,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
UpgradeAllowed = true,
|
||||
Cutoff = Quality.MP3.Id,
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems("None"),
|
||||
MinFormatScore = 0,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
})
|
||||
.Build();
|
||||
@@ -58,14 +64,16 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Author = _fakeAuthor,
|
||||
ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
Books = doubleBookList
|
||||
Books = doubleBookList,
|
||||
CustomFormats = new List<CustomFormat>()
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteBook
|
||||
{
|
||||
Author = _fakeAuthor,
|
||||
ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
Books = singleBookList
|
||||
Books = singleBookList,
|
||||
CustomFormats = new List<CustomFormat>()
|
||||
};
|
||||
|
||||
_upgradableQuality = new QualityModel(Quality.MP3, new Revision(version: 1));
|
||||
@@ -74,6 +82,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.EnableCompletedDownloadHandling)
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(x => x.ParseCustomFormat(It.IsAny<EntityHistory>(), It.IsAny<Author>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
}
|
||||
|
||||
private void GivenMostRecentForBook(int bookId, string downloadId, QualityModel quality, DateTime date, EntityHistoryEventType eventType)
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@@ -11,93 +13,197 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[TestFixture]
|
||||
public class UpgradeAllowedSpecificationFixture : CoreTest<UpgradableSpecification>
|
||||
{
|
||||
[Test]
|
||||
public void should_return_false_when_quality_is_better_and_upgrade_allowed_is_false_for_quality_profile()
|
||||
private CustomFormat _customFormatOne;
|
||||
private CustomFormat _customFormatTwo;
|
||||
private QualityProfile _qualityProfile;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
_customFormatOne = new CustomFormat
|
||||
{
|
||||
Id = 1,
|
||||
Name = "One"
|
||||
};
|
||||
_customFormatTwo = new CustomFormat
|
||||
{
|
||||
Id = 2,
|
||||
Name = "Two"
|
||||
};
|
||||
|
||||
_qualityProfile = new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false,
|
||||
CutoffFormatScore = 100,
|
||||
FormatItems = new List<ProfileFormatItem>
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = _customFormatOne,
|
||||
Score = 50
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = _customFormatTwo,
|
||||
Score = 100
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_quality_is_better_custom_formats_are_the_same_and_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.FLAC))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.FLAC),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_quality_is_same_and_custom_format_is_upgrade_and_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne },
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatTwo })
|
||||
.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_custom_format_upgrade_when_upgrading_is_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = true;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne },
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatTwo })
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_same_custom_format_score_when_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne },
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne })
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_lower_custom_format_score_when_upgrading_is_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = true;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatTwo },
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne })
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_lower_language_when_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatTwo },
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat> { _customFormatOne })
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_quality_upgrade_when_upgrading_is_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = true;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.FLAC))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.FLAC),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_same_quality_when_upgrading_is_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = true;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.MP3))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_same_quality_when_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false
|
||||
},
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.MP3))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_lower_quality_when_upgrading_is_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = true;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
},
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.MP3))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.PDF),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_lower_quality_when_upgrading_is_not_allowed()
|
||||
{
|
||||
_qualityProfile.UpgradeAllowed = false;
|
||||
|
||||
Subject.IsUpgradeAllowed(
|
||||
new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.FLAC.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false
|
||||
},
|
||||
_qualityProfile,
|
||||
new QualityModel(Quality.MP3),
|
||||
new QualityModel(Quality.MP3))
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.PDF),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@ using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
@@ -29,6 +32,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Mocker.Resolve<UpgradableSpecification>();
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats();
|
||||
|
||||
_firstFile = new BookFile { Quality = new QualityModel(Quality.FLAC, new Revision(version: 2)), DateAdded = DateTime.Now };
|
||||
_secondFile = new BookFile { Quality = new QualityModel(Quality.FLAC, new Revision(version: 2)), DateAdded = DateTime.Now };
|
||||
|
||||
@@ -40,7 +45,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
UpgradeAllowed = true,
|
||||
Cutoff = Quality.MP3.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems("None"),
|
||||
MinFormatScore = 0,
|
||||
})
|
||||
.Build();
|
||||
|
||||
@@ -52,15 +59,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
Author = fakeAuthor,
|
||||
ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
Books = doubleBookList
|
||||
Books = doubleBookList,
|
||||
CustomFormats = new List<CustomFormat>()
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteBook
|
||||
{
|
||||
Author = fakeAuthor,
|
||||
ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.MP3, new Revision(version: 2)) },
|
||||
Books = singleBookList
|
||||
Books = singleBookList,
|
||||
CustomFormats = new List<CustomFormat>()
|
||||
};
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(x => x.ParseCustomFormat(It.IsAny<BookFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
}
|
||||
|
||||
private void WithFirstFileUpgradable()
|
||||
@@ -136,6 +149,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_be_false_if_some_tracks_are_upgradable_and_some_are_downgrades()
|
||||
{
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<BookFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
WithFirstFileUpgradable();
|
||||
_parseResultSingle.ParsedBookInfo.Quality = new QualityModel(Quality.MP3);
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
@@ -23,8 +24,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
new object[] { Quality.MP3, 1, Quality.MP3, 1, Quality.MP3, false }
|
||||
};
|
||||
|
||||
private static readonly int NoPreferredWordScore = 0;
|
||||
|
||||
private void GivenAutoDownloadPropers(ProperDownloadTypes type)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
@@ -47,9 +46,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(current, new Revision(version: currentVersion)),
|
||||
NoPreferredWordScore,
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(newQuality, new Revision(version: newVersion)),
|
||||
NoPreferredWordScore)
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
@@ -66,9 +65,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.MP3, new Revision(version: 1)),
|
||||
NoPreferredWordScore,
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3, new Revision(version: 2)),
|
||||
NoPreferredWordScore)
|
||||
new List<CustomFormat>())
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -85,9 +84,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.MP3, new Revision(version: 1)),
|
||||
NoPreferredWordScore,
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.MP3, new Revision(version: 2)),
|
||||
NoPreferredWordScore)
|
||||
new List<CustomFormat>())
|
||||
.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user