mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
New: Custom Formats
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user