(cherry picked from commit 6f51e72d0073444b441bee5508322cc9e52e98e4)pull/10396/head
parent
593b943cb0
commit
eca95826c2
@ -1,207 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser;
|
||||
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 CutoffSpecificationFixture : CoreTest<CutoffSpecification>
|
||||
{
|
||||
private CustomFormat _customFormat;
|
||||
private RemoteMovie _remoteMovie;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.SetConstant<IUpgradableSpecification>(Mocker.Resolve<UpgradableSpecification>());
|
||||
|
||||
_remoteMovie = new RemoteMovie()
|
||||
{
|
||||
Movie = Builder<Movie>.CreateNew().Build(),
|
||||
ParsedMovieInfo = Builder<ParsedMovieInfo>.CreateNew().With(x => x.Quality = null).Build()
|
||||
};
|
||||
|
||||
GivenOldCustomFormats(new List<CustomFormat>());
|
||||
}
|
||||
|
||||
private void GivenProfile(QualityProfile profile)
|
||||
{
|
||||
CustomFormatsTestHelpers.GivenCustomFormats();
|
||||
profile.FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems();
|
||||
profile.MinFormatScore = 0;
|
||||
_remoteMovie.Movie.QualityProfile = profile;
|
||||
|
||||
Console.WriteLine(profile.ToJson());
|
||||
}
|
||||
|
||||
private void GivenFileQuality(QualityModel quality)
|
||||
{
|
||||
_remoteMovie.Movie.MovieFile = Builder<MovieFile>.CreateNew().With(x => x.Quality = quality).Build();
|
||||
}
|
||||
|
||||
private void GivenNewQuality(QualityModel quality)
|
||||
{
|
||||
_remoteMovie.ParsedMovieInfo.Quality = quality;
|
||||
}
|
||||
|
||||
private void GivenOldCustomFormats(List<CustomFormat> formats)
|
||||
{
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(x => x.ParseCustomFormat(It.IsAny<MovieFile>()))
|
||||
.Returns(formats);
|
||||
}
|
||||
|
||||
private void GivenNewCustomFormats(List<CustomFormat> formats)
|
||||
{
|
||||
_remoteMovie.CustomFormats = formats;
|
||||
}
|
||||
|
||||
private void GivenCustomFormatHigher()
|
||||
{
|
||||
_customFormat = new CustomFormat("My Format", new ResolutionSpecification { Value = (int)Resolution.R1080p }) { Id = 1 };
|
||||
|
||||
CustomFormatsTestHelpers.GivenCustomFormats(_customFormat);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_current_episode_is_less_than_cutoff()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.Bluray1080p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.DVD, new Revision(version: 2)));
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_current_episode_is_equal_to_cutoff()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV720p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_current_episode_is_greater_than_cutoff()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV720p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.Bluray1080p, new Revision(version: 2)));
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_new_episode_is_proper_but_existing_is_not()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV720p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 1)));
|
||||
GivenNewQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_cutoff_is_met_and_quality_is_higher()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV720p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
|
||||
GivenNewQuality(new QualityModel(Quality.Bluray1080p, new Revision(version: 2)));
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_custom_formats_is_met_and_quality_and_format_higher()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV720p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
MinFormatScore = 0,
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems("My Format"),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.HDTV720p));
|
||||
GivenNewQuality(new QualityModel(Quality.Bluray1080p));
|
||||
|
||||
GivenCustomFormatHigher();
|
||||
|
||||
GivenOldCustomFormats(new List<CustomFormat>());
|
||||
GivenNewCustomFormats(new List<CustomFormat> { _customFormat });
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_cutoffs_are_met_but_is_a_revision_upgrade()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.HDTV1080p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)));
|
||||
GivenNewQuality(new QualityModel(Quality.WEBDL1080p, new Revision(version: 2)));
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_quality_profile_does_not_allow_upgrades_but_cutoff_is_set_to_highest_quality()
|
||||
{
|
||||
GivenProfile(new QualityProfile
|
||||
{
|
||||
Cutoff = Quality.RAWHD.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = false
|
||||
});
|
||||
|
||||
GivenFileQuality(new QualityModel(Quality.WEBDL1080p));
|
||||
GivenNewQuality(new QualityModel(Quality.Bluray1080p));
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
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.Parser;
|
||||
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 QualityUpgradeSpecificationFixture : CoreTest<UpgradableSpecification>
|
||||
{
|
||||
private static CustomFormat _customFormat1 = new CustomFormat("My Format 1", new ResolutionSpecification { Value = (int)Resolution.R1080p }) { Id = 1 };
|
||||
private static CustomFormat _customFormat2 = new CustomFormat("My Format 2", new ResolutionSpecification { Value = (int)Resolution.R480p }) { Id = 2 };
|
||||
|
||||
public static object[] IsUpgradeTestCases =
|
||||
{
|
||||
// Quality upgrade trumps custom format
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat>(), Quality.SDTV, 2, new List<CustomFormat>(), true },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, Quality.SDTV, 2, new List<CustomFormat> { _customFormat1 }, true },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, Quality.SDTV, 2, new List<CustomFormat> { _customFormat2 }, true },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat2 }, Quality.SDTV, 2, new List<CustomFormat> { _customFormat1 }, true },
|
||||
|
||||
// Revision upgrade trumps custom format
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.WEBDL720p, 2, new List<CustomFormat>(), true },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { _customFormat1 }, Quality.WEBDL720p, 2, new List<CustomFormat> { _customFormat1 }, true },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { _customFormat1 }, Quality.WEBDL720p, 2, new List<CustomFormat> { _customFormat2 }, true },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { _customFormat2 }, Quality.WEBDL720p, 2, new List<CustomFormat> { _customFormat1 }, true },
|
||||
|
||||
// Custom formats apply if quality same
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat>(), Quality.SDTV, 1, new List<CustomFormat>(), false },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, false },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, Quality.SDTV, 1, new List<CustomFormat> { _customFormat2 }, true },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { _customFormat2 }, Quality.SDTV, 1, new List<CustomFormat> { _customFormat1 }, false },
|
||||
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.HDTV720p, 2, new List<CustomFormat>(), false },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.HDTV720p, 2, new List<CustomFormat>(), false },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.WEBDL720p, 1, new List<CustomFormat>(), false },
|
||||
new object[] { Quality.WEBDL1080p, 1, new List<CustomFormat>(), Quality.WEBDL1080p, 1, new List<CustomFormat>(), false }
|
||||
};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
CustomFormatsTestHelpers.GivenCustomFormats(_customFormat1, _customFormat2);
|
||||
}
|
||||
|
||||
private void GivenAutoDownloadPropers(ProperDownloadTypes type)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(type);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource("IsUpgradeTestCases")]
|
||||
public void IsUpgradeTest(Quality current,
|
||||
int currentVersion,
|
||||
List<CustomFormat> currentFormats,
|
||||
Quality newQuality,
|
||||
int newVersion,
|
||||
List<CustomFormat> newFormats,
|
||||
bool expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(_customFormat1.Name, _customFormat2.Name),
|
||||
MinFormatScore = 0
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(profile,
|
||||
new QualityModel(current, new Revision(version: currentVersion)),
|
||||
currentFormats,
|
||||
new QualityModel(newQuality, new Revision(version: newVersion)),
|
||||
newFormats)
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_proper_and_download_propers_is_do_not_download()
|
||||
{
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotUpgrade);
|
||||
|
||||
var profile = new QualityProfile { Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
|
||||
Subject.IsUpgradable(profile,
|
||||
new QualityModel(Quality.DVD, new Revision(version: 2)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.DVD, new Revision(version: 1)),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_release_and_existing_file_are_the_same()
|
||||
{
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>())
|
||||
.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser;
|
||||
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 UpgradeSpecificationFixture : CoreTest<UpgradableSpecification>
|
||||
{
|
||||
private static readonly CustomFormat CustomFormat1 = new ("My Format 1", new ResolutionSpecification { Value = (int)Resolution.R1080p }) { Id = 1 };
|
||||
private static readonly CustomFormat CustomFormat2 = new ("My Format 2", new ResolutionSpecification { Value = (int)Resolution.R480p }) { Id = 2 };
|
||||
|
||||
public static object[] IsUpgradeTestCases =
|
||||
{
|
||||
// Quality upgrade trumps custom format
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat>(), Quality.SDTV, 2, new List<CustomFormat>(), UpgradeableRejectReason.None },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, Quality.SDTV, 2, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.None },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, Quality.SDTV, 2, new List<CustomFormat> { CustomFormat2 }, UpgradeableRejectReason.None },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat2 }, Quality.SDTV, 2, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.None },
|
||||
|
||||
// Revision upgrade trumps custom format
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.WEBDL720p, 2, new List<CustomFormat>(), UpgradeableRejectReason.None },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { CustomFormat1 }, Quality.WEBDL720p, 2, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.None },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { CustomFormat1 }, Quality.WEBDL720p, 2, new List<CustomFormat> { CustomFormat2 }, UpgradeableRejectReason.None },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat> { CustomFormat2 }, Quality.WEBDL720p, 2, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.None },
|
||||
|
||||
// Custom formats apply if quality same
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat>(), Quality.SDTV, 1, new List<CustomFormat>(), UpgradeableRejectReason.CustomFormatScore },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.CustomFormatScore },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, Quality.SDTV, 1, new List<CustomFormat> { CustomFormat2 }, UpgradeableRejectReason.CustomFormatCutoff },
|
||||
new object[] { Quality.SDTV, 1, new List<CustomFormat> { CustomFormat2 }, Quality.SDTV, 1, new List<CustomFormat> { CustomFormat1 }, UpgradeableRejectReason.CustomFormatScore },
|
||||
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.HDTV720p, 2, new List<CustomFormat>(), UpgradeableRejectReason.BetterQuality },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.HDTV720p, 2, new List<CustomFormat>(), UpgradeableRejectReason.BetterQuality },
|
||||
new object[] { Quality.WEBDL720p, 1, new List<CustomFormat>(), Quality.WEBDL720p, 1, new List<CustomFormat>(), UpgradeableRejectReason.CustomFormatScore },
|
||||
new object[] { Quality.WEBDL1080p, 1, new List<CustomFormat>(), Quality.WEBDL1080p, 1, new List<CustomFormat>(), UpgradeableRejectReason.CustomFormatScore }
|
||||
};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
CustomFormatsTestHelpers.GivenCustomFormats(CustomFormat1, CustomFormat2);
|
||||
}
|
||||
|
||||
private void GivenAutoDownloadPropers(ProperDownloadTypes type)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(type);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(IsUpgradeTestCases))]
|
||||
public void IsUpgradeTest(Quality current,
|
||||
int currentVersion,
|
||||
List<CustomFormat> currentFormats,
|
||||
Quality newQuality,
|
||||
int newVersion,
|
||||
List<CustomFormat> newFormats,
|
||||
UpgradeableRejectReason expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
UpgradeAllowed = true,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems(CustomFormat1.Name, CustomFormat2.Name)
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(current, new Revision(version: currentVersion)),
|
||||
currentFormats,
|
||||
new QualityModel(newQuality, new Revision(version: newVersion)),
|
||||
newFormats)
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_proper_and_download_propers_is_do_not_download()
|
||||
{
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.DVD, new Revision(version: 1)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.DVD, new Revision(version: 2)),
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.None);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_release_and_existing_file_are_the_same()
|
||||
{
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.CustomFormatScore);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_release_has_higher_quality_and_cutoff_is_not_already_met()
|
||||
{
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
Cutoff = Quality.HDTV1080p.Id
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.HDTV1080p, new Revision(version: 1)),
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.None);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_release_has_higher_quality_and_cutoff_is_already_met()
|
||||
{
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
Cutoff = Quality.HDTV720p.Id
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
|
||||
new List<CustomFormat>(),
|
||||
new QualityModel(Quality.HDTV1080p, new Revision(version: 1)),
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.QualityCutoff);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class CutoffSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IUpgradableSpecification _upgradableSpecification;
|
||||
private readonly ICustomFormatCalculationService _formatService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public CutoffSpecification(IUpgradableSpecification upgradableSpecification,
|
||||
ICustomFormatCalculationService formatService,
|
||||
Logger logger)
|
||||
{
|
||||
_upgradableSpecification = upgradableSpecification;
|
||||
_formatService = formatService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public SpecificationPriority Priority => SpecificationPriority.Default;
|
||||
public RejectionType Type => RejectionType.Permanent;
|
||||
|
||||
public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
var profile = subject.Movie.QualityProfile;
|
||||
var file = subject.Movie.MovieFile;
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
file.Movie = subject.Movie;
|
||||
_logger.Debug("Comparing file quality with report. Existing file is {0}", file.Quality);
|
||||
|
||||
var customFormats = _formatService.ParseCustomFormat(file);
|
||||
|
||||
if (!_upgradableSpecification.CutoffNotMet(profile,
|
||||
file.Quality,
|
||||
customFormats,
|
||||
subject.ParsedMovieInfo.Quality))
|
||||
{
|
||||
_logger.Debug("Existing custom formats {0} meet cutoff",
|
||||
customFormats.ConcatToString());
|
||||
|
||||
var qualityCutoffIndex = profile.GetIndex(profile.Cutoff);
|
||||
var qualityCutoff = profile.Items[qualityCutoffIndex.Index];
|
||||
|
||||
return Decision.Reject("Existing file meets cutoff: {0}", qualityCutoff);
|
||||
}
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public enum UpgradeableRejectReason
|
||||
{
|
||||
None,
|
||||
BetterQuality,
|
||||
BetterRevision,
|
||||
QualityCutoff,
|
||||
CustomFormatScore,
|
||||
CustomFormatCutoff
|
||||
}
|
||||
}
|
Loading…
Reference in new issue