diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 38baf2798..41a19adcc 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -331,10 +331,10 @@ stages:
artifactName: '$(testName)Tests'
targetPath: $(testsFolder)
- bash: |
- wget https://mediaarea.net/repo/deb/repo-mediaarea_1.0-9_all.deb
- sudo dpkg -i repo-mediaarea_1.0-9_all.deb
+ wget https://mediaarea.net/repo/deb/repo-mediaarea_1.0-11_all.deb
+ sudo dpkg -i repo-mediaarea_1.0-11_all.deb
sudo apt-get update
- sudo apt-get install -y libmediainfo-dev libmediainfo0v5 mediainfo
+ sudo apt-get install -y --allow-unauthenticated libmediainfo-dev libmediainfo0v5 mediainfo
displayName: Install mediainfo
condition: and(succeeded(), eq(variables['osName'], 'Linux'))
- powershell: Set-Service SCardSvr -StartupType Manual
diff --git a/frontend/src/Activity/Blacklist/BlacklistRow.js b/frontend/src/Activity/Blacklist/BlacklistRow.js
index a7a66050f..3f715f2a7 100644
--- a/frontend/src/Activity/Blacklist/BlacklistRow.js
+++ b/frontend/src/Activity/Blacklist/BlacklistRow.js
@@ -44,6 +44,7 @@ class BlacklistRow extends Component {
movie,
sourceTitle,
quality,
+ customFormats,
languages,
date,
protocol,
@@ -112,11 +113,11 @@ class BlacklistRow extends Component {
);
}
- if (name === 'quality.customFormats') {
+ if (name === 'customFormats') {
return (
);
@@ -186,6 +187,7 @@ BlacklistRow.propTypes = {
movie: PropTypes.object.isRequired,
sourceTitle: PropTypes.string.isRequired,
quality: PropTypes.object.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object).isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
date: PropTypes.string.isRequired,
protocol: PropTypes.string.isRequired,
diff --git a/frontend/src/Activity/History/HistoryRow.js b/frontend/src/Activity/History/HistoryRow.js
index 8c796d8e1..46af6c6c3 100644
--- a/frontend/src/Activity/History/HistoryRow.js
+++ b/frontend/src/Activity/History/HistoryRow.js
@@ -54,6 +54,7 @@ class HistoryRow extends Component {
const {
movie,
quality,
+ customFormats,
languages,
qualityCutoffNotMet,
eventType,
@@ -126,11 +127,11 @@ class HistoryRow extends Component {
);
}
- if (name === 'quality.customFormats') {
+ if (name === 'customFormats') {
return (
);
@@ -219,6 +220,7 @@ HistoryRow.propTypes = {
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
quality: PropTypes.object.isRequired,
qualityCutoffNotMet: PropTypes.bool.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object).isRequired,
eventType: PropTypes.string.isRequired,
sourceTitle: PropTypes.string.isRequired,
date: PropTypes.string.isRequired,
diff --git a/frontend/src/Activity/Queue/QueueRow.js b/frontend/src/Activity/Queue/QueueRow.js
index ff5f07899..5f9a1d810 100644
--- a/frontend/src/Activity/Queue/QueueRow.js
+++ b/frontend/src/Activity/Queue/QueueRow.js
@@ -72,6 +72,7 @@ class QueueRow extends Component {
errorMessage,
movie,
quality,
+ customFormats,
languages,
protocol,
indexer,
@@ -169,11 +170,11 @@ class QueueRow extends Component {
);
}
- if (name === 'quality.customFormats') {
+ if (name === 'customFormats') {
return (
);
@@ -329,6 +330,7 @@ QueueRow.propTypes = {
errorMessage: PropTypes.string,
movie: PropTypes.object,
quality: PropTypes.object.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object),
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
protocol: PropTypes.string.isRequired,
indexer: PropTypes.string,
diff --git a/frontend/src/InteractiveSearch/InteractiveSearchRow.js b/frontend/src/InteractiveSearch/InteractiveSearchRow.js
index bb1a5f2c0..69d1c4ad2 100644
--- a/frontend/src/InteractiveSearch/InteractiveSearchRow.js
+++ b/frontend/src/InteractiveSearch/InteractiveSearchRow.js
@@ -113,6 +113,7 @@ class InteractiveSearchRow extends Component {
seeders,
leechers,
quality,
+ customFormats,
languages,
indexerFlags,
rejections,
@@ -177,7 +178,7 @@ class InteractiveSearchRow extends Component {
@@ -279,6 +280,7 @@ InteractiveSearchRow.propTypes = {
seeders: PropTypes.number,
leechers: PropTypes.number,
quality: PropTypes.object.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object).isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
rejections: PropTypes.arrayOf(PropTypes.string).isRequired,
indexerFlags: PropTypes.arrayOf(PropTypes.string).isRequired,
diff --git a/frontend/src/Movie/History/MovieHistoryRow.js b/frontend/src/Movie/History/MovieHistoryRow.js
index e21cc82dd..15241031e 100644
--- a/frontend/src/Movie/History/MovieHistoryRow.js
+++ b/frontend/src/Movie/History/MovieHistoryRow.js
@@ -9,6 +9,7 @@ import TableRow from 'Components/Table/TableRow';
import TableRowCell from 'Components/Table/Cells/TableRowCell';
import Popover from 'Components/Tooltip/Popover';
import MovieQuality from 'Movie/MovieQuality';
+import MovieFormats from 'Movie/MovieFormats';
import MovieLanguage from 'Movie/MovieLanguage';
import HistoryDetailsConnector from 'Activity/History/Details/HistoryDetailsConnector';
import HistoryEventTypeCell from 'Activity/History/HistoryEventTypeCell';
@@ -64,6 +65,7 @@ class MovieHistoryRow extends Component {
eventType,
sourceTitle,
quality,
+ customFormats,
languages,
qualityCutoffNotMet,
date,
@@ -98,6 +100,12 @@ class MovieHistoryRow extends Component {
/>
+
+
+
+
@@ -152,6 +160,7 @@ MovieHistoryRow.propTypes = {
sourceTitle: PropTypes.string.isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
quality: PropTypes.object.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object).isRequired,
qualityCutoffNotMet: PropTypes.bool.isRequired,
date: PropTypes.string.isRequired,
data: PropTypes.object.isRequired,
diff --git a/frontend/src/Movie/History/MovieHistoryTableContent.js b/frontend/src/Movie/History/MovieHistoryTableContent.js
index 2a914dcbf..c790233df 100644
--- a/frontend/src/Movie/History/MovieHistoryTableContent.js
+++ b/frontend/src/Movie/History/MovieHistoryTableContent.js
@@ -26,6 +26,12 @@ const columns = [
label: 'Quality',
isVisible: true
},
+ {
+ name: 'customFormats',
+ label: 'Custom Formats',
+ isSortable: false,
+ isVisible: true
+ },
{
name: 'date',
label: 'Date',
diff --git a/frontend/src/MovieFile/Editor/MovieFileEditorRow.js b/frontend/src/MovieFile/Editor/MovieFileEditorRow.js
index 371419daa..bbc1cecab 100644
--- a/frontend/src/MovieFile/Editor/MovieFileEditorRow.js
+++ b/frontend/src/MovieFile/Editor/MovieFileEditorRow.js
@@ -86,6 +86,7 @@ class MovieFileEditorRow extends Component {
size,
quality,
qualityCutoffNotMet,
+ customFormats,
languages
} = this.props;
@@ -173,7 +174,7 @@ class MovieFileEditorRow extends Component {
className={styles.formats}
>
@@ -233,6 +234,7 @@ MovieFileEditorRow.propTypes = {
size: PropTypes.number.isRequired,
relativePath: PropTypes.string.isRequired,
quality: PropTypes.object.isRequired,
+ customFormats: PropTypes.arrayOf(PropTypes.object).isRequired,
qualityCutoffNotMet: PropTypes.bool.isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
mediaInfo: PropTypes.object.isRequired,
diff --git a/frontend/src/Settings/CustomFormats/CustomFormats/CustomFormat.js b/frontend/src/Settings/CustomFormats/CustomFormats/CustomFormat.js
index dacc0c019..974d4b5b5 100644
--- a/frontend/src/Settings/CustomFormats/CustomFormats/CustomFormat.js
+++ b/frontend/src/Settings/CustomFormats/CustomFormats/CustomFormat.js
@@ -123,9 +123,6 @@ class CustomFormat extends Component {
Are you sure you want to delete custom format '{name}'?
-
- This will remove all associations to this format in the DB. This may result in existing files being updated.
-
}
confirmLabel="Delete"
diff --git a/frontend/src/Store/Actions/Creators/createHandleActions.js b/frontend/src/Store/Actions/Creators/createHandleActions.js
index 744186483..dc998b350 100644
--- a/frontend/src/Store/Actions/Creators/createHandleActions.js
+++ b/frontend/src/Store/Actions/Creators/createHandleActions.js
@@ -16,6 +16,13 @@ const blacklistedProperties = [
'id'
];
+function createItemMap(data) {
+ return data.reduce((acc, d, index, array) => {
+ acc[d.id] = index;
+ return acc;
+ }, {});
+}
+
export default function createHandleActions(handlers, defaultState, section) {
return handleActions({
@@ -42,7 +49,7 @@ export default function createHandleActions(handlers, defaultState, section) {
if (_.isArray(payload.data)) {
newState.items = payload.data;
- newState.itemMap = _.zipObject(_.map(payload.data, 'id'), _.range(payload.data.length));
+ newState.itemMap = createItemMap(newState.items);
} else {
newState.item = payload.data;
}
@@ -67,7 +74,7 @@ export default function createHandleActions(handlers, defaultState, section) {
const items = newState.items;
if (!newState.itemMap) {
- newState.itemMap = _.zipObject(_.map(items, 'id'), _.range(items.length));
+ newState.itemMap = createItemMap(items);
}
const index = payload.id in newState.itemMap ? newState.itemMap[payload.id] : -1;
@@ -126,7 +133,7 @@ export default function createHandleActions(handlers, defaultState, section) {
newState.items = [...newState.items];
_.remove(newState.items, { id: payload.id });
- newState.itemMap = _.zipObject(_.map(newState.items, 'id'), _.range(newState.items.length));
+ newState.itemMap = createItemMap(newState.items);
return updateSectionState(state, payloadSection, newState);
}
diff --git a/frontend/src/Store/Actions/blacklistActions.js b/frontend/src/Store/Actions/blacklistActions.js
index e50433980..63737cc41 100644
--- a/frontend/src/Store/Actions/blacklistActions.js
+++ b/frontend/src/Store/Actions/blacklistActions.js
@@ -51,9 +51,9 @@ export const defaultState = {
isVisible: true
},
{
- name: 'quality.customFormats',
- label: 'Custom Formats',
- isSortable: true,
+ name: 'customFormats',
+ label: 'Formats',
+ isSortable: false,
isVisible: true
},
{
diff --git a/frontend/src/Store/Actions/historyActions.js b/frontend/src/Store/Actions/historyActions.js
index a30de3716..54d1be04a 100644
--- a/frontend/src/Store/Actions/historyActions.js
+++ b/frontend/src/Store/Actions/historyActions.js
@@ -52,9 +52,9 @@ export const defaultState = {
isVisible: true
},
{
- name: 'quality.customFormats',
- label: 'Custom Formats',
- isSortable: true,
+ name: 'customFormats',
+ label: 'Formats',
+ isSortable: false,
isVisible: true
},
{
diff --git a/frontend/src/Store/Actions/queueActions.js b/frontend/src/Store/Actions/queueActions.js
index 94145a187..1f568c14b 100644
--- a/frontend/src/Store/Actions/queueActions.js
+++ b/frontend/src/Store/Actions/queueActions.js
@@ -81,9 +81,9 @@ export const defaultState = {
isVisible: true
},
{
- name: 'quality.customFormats',
- label: 'Custom Formats',
- isSortable: true,
+ name: 'customFormats',
+ label: 'Formats',
+ isSortable: false,
isVisible: true
},
{
diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs
index 06b2106ae..63c534c65 100644
--- a/src/NzbDrone.Api/History/HistoryModule.cs
+++ b/src/NzbDrone.Api/History/HistoryModule.cs
@@ -35,7 +35,7 @@ namespace NzbDrone.Api.History
if (model.Movie != null)
{
- resource.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(model.Movie.Profile, model.Quality);
+ resource.QualityCutoffNotMet = _qualityUpgradableSpecification.QualityCutoffNotMet(model.Movie.Profile, model.Quality);
}
return resource;
diff --git a/src/NzbDrone.Api/Qualities/CustomFormatModule.cs b/src/NzbDrone.Api/Qualities/CustomFormatModule.cs
index c14bfa4a2..94d9b6edc 100644
--- a/src/NzbDrone.Api/Qualities/CustomFormatModule.cs
+++ b/src/NzbDrone.Api/Qualities/CustomFormatModule.cs
@@ -11,11 +11,15 @@ namespace NzbDrone.Api.Qualities
public class CustomFormatModule : RadarrRestModule
{
private readonly ICustomFormatService _formatService;
+ private readonly ICustomFormatCalculationService _formatCalculator;
private readonly IParsingService _parsingService;
- public CustomFormatModule(ICustomFormatService formatService, IParsingService parsingService)
+ public CustomFormatModule(ICustomFormatService formatService,
+ ICustomFormatCalculationService formatCalculator,
+ IParsingService parsingService)
{
_formatService = formatService;
+ _formatCalculator = formatCalculator;
_parsingService = parsingService;
SharedValidator.RuleFor(c => c.Name).NotEmpty();
@@ -103,8 +107,8 @@ namespace NzbDrone.Api.Qualities
return new CustomFormatTestResource
{
- Matches = _parsingService.MatchFormatTags(parsed).ToResource(),
- MatchedFormats = parsed.Quality.CustomFormats.ToResource()
+ Matches = _formatCalculator.MatchFormatTags(parsed).ToResource(),
+ MatchedFormats = _formatCalculator.ParseCustomFormat(parsed).ToResource()
};
}
@@ -125,8 +129,8 @@ namespace NzbDrone.Api.Qualities
return new CustomFormatTestResource
{
- Matches = _parsingService.MatchFormatTags(parsed).ToResource(),
- MatchedFormats = parsed.Quality.CustomFormats.ToResource()
+ Matches = _formatCalculator.MatchFormatTags(parsed).ToResource(),
+ MatchedFormats = _formatCalculator.ParseCustomFormat(parsed).ToResource()
};
}
}
diff --git a/src/NzbDrone.Api/Qualities/FormatTagMatchResultResource.cs b/src/NzbDrone.Api/Qualities/FormatTagMatchResultResource.cs
index c8209c2b3..fc8a03945 100644
--- a/src/NzbDrone.Api/Qualities/FormatTagMatchResultResource.cs
+++ b/src/NzbDrone.Api/Qualities/FormatTagMatchResultResource.cs
@@ -27,7 +27,7 @@ namespace NzbDrone.Api.Qualities
public static class QualityTagMatchResultResourceMapper
{
- public static FormatTagMatchResultResource ToResource(this FormatTagMatchResult model)
+ public static FormatTagMatchResultResource ToResource(this CustomFormatMatchResult model)
{
if (model == null)
{
@@ -41,7 +41,7 @@ namespace NzbDrone.Api.Qualities
};
}
- public static List ToResource(this IList models)
+ public static List ToResource(this IList models)
{
return models.Select(ToResource).ToList();
}
diff --git a/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs b/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs
index 1b58b79c7..830e2af44 100644
--- a/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs
+++ b/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs
@@ -1,9 +1,7 @@
-using System.Collections.Generic;
-using System.Linq;
+using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo;
-using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
@@ -22,11 +20,6 @@ namespace NzbDrone.Common.Test
container.Register(new MainDatabase(null));
container.Resolve().Register();
- // A dummy custom format repository since this isn't a DB test
- var mockCustomFormat = Mocker.GetMock();
- mockCustomFormat.Setup(x => x.All()).Returns(new List());
- container.Register(mockCustomFormat.Object);
-
Mocker.SetConstant(container);
var handlers = Subject.BuildAll>()
diff --git a/src/NzbDrone.Core.Test/CustomFormats/CustomFormatComparerFixture.cs b/src/NzbDrone.Core.Test/CustomFormats/CustomFormatComparerFixture.cs
new file mode 100644
index 000000000..f994e1a9f
--- /dev/null
+++ b/src/NzbDrone.Core.Test/CustomFormats/CustomFormatComparerFixture.cs
@@ -0,0 +1,129 @@
+using System.Collections.Generic;
+using FluentAssertions;
+using NUnit.Framework;
+using NzbDrone.Core.CustomFormats;
+using NzbDrone.Core.Profiles;
+using NzbDrone.Core.Test.CustomFormats;
+using NzbDrone.Core.Test.Framework;
+
+namespace NzbDrone.Core.Test.Qualities
+{
+ [TestFixture]
+ public class CustomFormatsComparerFixture : CoreTest
+ {
+ private CustomFormat _customFormat1;
+ private CustomFormat _customFormat2;
+ private CustomFormat _customFormat3;
+ private CustomFormat _customFormat4;
+
+ public CustomFormatsComparer Subject { get; set; }
+
+ [SetUp]
+ public void Setup()
+ {
+ }
+
+ private void GivenDefaultProfileWithFormats()
+ {
+ _customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
+ _customFormat2 = new CustomFormat("My Format 2", "L_FRENCH") { Id = 2 };
+ _customFormat3 = new CustomFormat("My Format 3", "L_SPANISH") { Id = 3 };
+ _customFormat4 = new CustomFormat("My Format 4", "L_ITALIAN") { Id = 4 };
+
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None, _customFormat1, _customFormat2, _customFormat3, _customFormat4);
+
+ Subject = new CustomFormatsComparer(new Profile { Items = QualityFixture.GetDefaultQualities(), FormatItems = CustomFormatsFixture.GetSampleFormatItems() });
+ }
+
+ [Test]
+ public void should_be_lesser_when_first_format_is_worse()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat1 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeLessThan(0);
+ }
+
+ [Test]
+ public void should_be_zero_when_formats_are_equal()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat2 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().Be(0);
+ }
+
+ [Test]
+ public void should_be_greater_when_first_format_is_better()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat3 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeGreaterThan(0);
+ }
+
+ [Test]
+ public void should_be_greater_when_multiple_formats_better()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat3, _customFormat4 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeGreaterThan(0);
+ }
+
+ [Test]
+ public void should_be_greater_when_best_format_is_better()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat1, _customFormat3 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeGreaterThan(0);
+ }
+
+ [Test]
+ public void should_be_greater_when_best_format_equal_but_more_lower_formats()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat1, _customFormat2 };
+ var second = new List { _customFormat2 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeGreaterThan(0);
+ }
+
+ [Test]
+ public void should_not_be_greater_when_best_format_worse_but_more_lower_formats()
+ {
+ GivenDefaultProfileWithFormats();
+
+ var first = new List { _customFormat1, _customFormat2, _customFormat3 };
+ var second = new List { _customFormat4 };
+
+ var compare = Subject.Compare(first, second);
+
+ compare.Should().BeLessThan(0);
+ }
+ }
+}
diff --git a/src/NzbDrone.Core.Test/CustomFormats/QualityTagFixture.cs b/src/NzbDrone.Core.Test/CustomFormats/QualityTagFixture.cs
index 5daa39746..368d88b15 100644
--- a/src/NzbDrone.Core.Test/CustomFormats/QualityTagFixture.cs
+++ b/src/NzbDrone.Core.Test/CustomFormats/QualityTagFixture.cs
@@ -3,6 +3,7 @@ using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Parser;
+using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.CustomFormats
diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/165_remove_custom_formats_from_quality_model.cs b/src/NzbDrone.Core.Test/Datastore/Migration/165_remove_custom_formats_from_quality_model.cs
new file mode 100644
index 000000000..88d9eb7de
--- /dev/null
+++ b/src/NzbDrone.Core.Test/Datastore/Migration/165_remove_custom_formats_from_quality_model.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Dapper;
+using FluentAssertions;
+using NUnit.Framework;
+using NzbDrone.Core.Datastore.Migration;
+using NzbDrone.Core.Download.Pending;
+using NzbDrone.Core.Languages;
+using NzbDrone.Core.Parser.Model;
+using NzbDrone.Core.Qualities;
+using NzbDrone.Core.Test.Framework;
+
+namespace NzbDrone.Core.Test.Datastore.Migration
+{
+ [TestFixture]
+ public class remove_custom_formats_from_quality_modelFixture : MigrationTest
+ {
+ [Test]
+ public void should_remove_custom_format_from_pending_releases()
+ {
+ var db = WithDapperMigrationTestDb(c =>
+ {
+ c.Insert.IntoTable("PendingReleases").Row(new
+ {
+ MovieId = 1,
+ Title = "Test Movie",
+ Added = DateTime.UtcNow,
+ ParsedMovieInfo = @"{
+ ""movieTitle"": ""Skyfall"",
+ ""simpleReleaseTitle"": ""A Movie (2012) \u002B Extras (1080p BluRay x265 HEVC 10bit DTS 5.1 SAMPA) [QxR]"",
+ ""quality"": {
+ ""quality"": {
+ ""id"": 7,
+ ""name"": ""Bluray-1080p"",
+ ""source"": ""bluray"",
+ ""resolution"": 1080,
+ ""modifier"": ""none""
+ },
+ ""customFormats"": [
+ {
+ ""name"": ""Standard High Def Surround Sound Movie"",
+ ""formatTags"": [
+ {
+ ""raw"": ""R_1080"",
+ ""tagType"": ""resolution"",
+ ""tagModifier"": 0,
+ ""value"": ""r1080p""
+ },
+ {
+ ""raw"": ""L_English"",
+ ""tagType"": ""language"",
+ ""tagModifier"": 0,
+ ""value"": {
+ ""id"": 1,
+ ""name"": ""English""
+ }
+ },
+ {
+ ""raw"": ""C_DTS"",
+ ""tagType"": ""custom"",
+ ""tagModifier"": 0,
+ ""value"": ""dts""
+ }
+ ],
+ ""id"": 1
+ }
+ ],
+ ""revision"": {
+ ""version"": 1,
+ ""real"": 0,
+ ""isRepack"": false
+ },
+ ""hardcodedSubs"": null,
+ ""qualityDetectionSource"": ""name""
+ },
+ ""releaseGroup"": ""QxR"",
+ ""releaseHash"": """",
+ ""edition"": """",
+ ""year"": 2012,
+ ""imdbId"": """"
+}",
+ Release = "{}",
+ Reason = PendingReleaseReason.Delay
+ });
+ });
+
+ var json = db.Query("SELECT ParsedMovieInfo FROM PendingReleases").First();
+ json.Should().NotContain("customFormats");
+
+ var pending = db.Query("SELECT ParsedMovieInfo FROM PendingReleases").First();
+ pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
+ pending.Languages.Should().BeEmpty();
+ }
+
+ [Test]
+ public void should_fix_quality_for_pending_releases()
+ {
+ var db = WithDapperMigrationTestDb(c =>
+ {
+ c.Insert.IntoTable("PendingReleases").Row(new
+ {
+ MovieId = 1,
+ Title = "Test Movie",
+ Added = DateTime.UtcNow,
+ ParsedMovieInfo = @"{
+ ""languages"": [
+ ""english""
+ ],
+ ""movieTitle"": ""Joy"",
+ ""simpleReleaseTitle"": ""A Movie.2015.1080p.BluRay.AVC.DTS-HD.MA.5.1-RARBG [f"",
+ ""quality"": {
+ ""quality"": {
+ ""id"": 7,
+ ""name"": ""Bluray-1080p"",
+ ""source"": ""bluray"",
+ ""resolution"": ""r1080P"",
+ ""modifier"": ""none""
+ },
+ ""customFormats"": [],
+ ""revision"": {
+ ""version"": 1,
+ ""real"": 0
+ }
+ },
+ ""releaseGroup"": ""RARBG"",
+ ""edition"": """",
+ ""year"": 2015,
+ ""imdbId"": """"
+}",
+ Release = "{}",
+ Reason = PendingReleaseReason.Delay
+ });
+ });
+
+ var json = db.Query("SELECT ParsedMovieInfo FROM PendingReleases").First();
+ json.Should().NotContain("customFormats");
+ json.Should().NotContain("resolution");
+
+ var pending = db.Query("SELECT ParsedMovieInfo FROM PendingReleases").First();
+ pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
+ pending.Languages.Should().BeEquivalentTo(new List { Language.English });
+ }
+ }
+}
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/CustomFormatAllowedByProfileSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/CustomFormatAllowedByProfileSpecificationFixture.cs
index 78d259595..85add58f4 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/CustomFormatAllowedByProfileSpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/CustomFormatAllowedByProfileSpecificationFixture.cs
@@ -47,7 +47,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_allow_if_format_is_defined_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { _format1 };
+ _remoteMovie.CustomFormats = new List { _format1 };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(_format1.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
@@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_deny_if_format_is_defined_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { _format2 };
+ _remoteMovie.CustomFormats = new List { _format2 };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(_format1.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
@@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_deny_if_one_format_is_defined_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { _format2, _format1 };
+ _remoteMovie.CustomFormats = new List { _format2, _format1 };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(_format1.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
@@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_allow_if_all_format_is_defined_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { _format2, _format1 };
+ _remoteMovie.CustomFormats = new List { _format2, _format1 };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(_format1.Name, _format2.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
@@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_deny_if_no_format_was_parsed_and_none_not_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { };
+ _remoteMovie.CustomFormats = new List { };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(_format1.Name, _format2.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
@@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_allow_if_no_format_was_parsed_and_none_in_profile()
{
- _remoteMovie.ParsedMovieInfo.Quality.CustomFormats = new List { };
+ _remoteMovie.CustomFormats = new List { };
_remoteMovie.Movie.Profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems(CustomFormat.None.Name, _format1.Name, _format2.Name);
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/CutoffSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/CutoffSpecificationFixture.cs
index a64347692..721d7fa91 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/CutoffSpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/CutoffSpecificationFixture.cs
@@ -1,8 +1,15 @@
+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.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.CustomFormats;
@@ -11,13 +18,55 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
- public class CutoffSpecificationFixture : CoreTest
+ public class CutoffSpecificationFixture : CoreTest
{
private CustomFormat _customFormat;
+ private RemoteMovie _remoteMovie;
[SetUp]
public void Setup()
{
+ Mocker.SetConstant(Mocker.Resolve());
+
+ _remoteMovie = new RemoteMovie()
+ {
+ Movie = Builder.CreateNew().Build(),
+ ParsedMovieInfo = Builder.CreateNew().With(x => x.Quality = null).Build()
+ };
+
+ GivenOldCustomFormats(new List());
+ }
+
+ private void GivenProfile(Profile profile)
+ {
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None);
+ profile.FormatItems = CustomFormatsFixture.GetSampleFormatItems("None");
+ profile.FormatCutoff = CustomFormat.None.Id;
+ _remoteMovie.Movie.Profile = profile;
+
+ Console.WriteLine(profile.ToJson());
+ }
+
+ private void GivenFileQuality(QualityModel quality)
+ {
+ _remoteMovie.Movie.MovieFile = Builder.CreateNew().With(x => x.Quality = quality).Build();
+ }
+
+ private void GivenNewQuality(QualityModel quality)
+ {
+ _remoteMovie.ParsedMovieInfo.Quality = quality;
+ }
+
+ private void GivenOldCustomFormats(List formats)
+ {
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(formats);
+ }
+
+ private void GivenNewCustomFormats(List formats)
+ {
+ _remoteMovie.CustomFormats = formats;
}
private void GivenCustomFormatHigher()
@@ -30,73 +79,80 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_true_if_current_episode_is_less_than_cutoff()
{
- Subject.CutoffNotMet(new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() },
- new QualityModel(Quality.DVD, new Revision(version: 2))).Should().BeTrue();
+ GivenProfile(new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
+ 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()
{
- Subject.CutoffNotMet(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() },
- new QualityModel(Quality.HDTV720p, new Revision(version: 2))).Should().BeFalse();
+ GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
+ 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()
{
- Subject.CutoffNotMet(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() },
- new QualityModel(Quality.Bluray1080p, new Revision(version: 2))).Should().BeFalse();
+ GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
+ 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()
{
- Subject.CutoffNotMet(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() },
- new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
- new QualityModel(Quality.HDTV720p, new Revision(version: 2))).Should().BeTrue();
+ GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
+ 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()
{
- Subject.CutoffNotMet(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() },
- new QualityModel(Quality.HDTV720p, new Revision(version: 2)),
- new QualityModel(Quality.Bluray1080p, new Revision(version: 2))).Should().BeFalse();
+ GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
+ 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 Profile
+ {
+ Cutoff = Quality.HDTV720p.Id,
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ FormatCutoff = CustomFormat.None.Id,
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None", "My Format")
+ });
+
+ GivenFileQuality(new QualityModel(Quality.HDTV720p));
+ GivenNewQuality(new QualityModel(Quality.Bluray1080p));
+
GivenCustomFormatHigher();
- var old = new QualityModel(Quality.HDTV720p);
- old.CustomFormats = new List { CustomFormat.None };
- var newQ = new QualityModel(Quality.Bluray1080p);
- newQ.CustomFormats = new List { _customFormat };
- Subject.CutoffNotMet(
- new Profile
- {
- Cutoff = Quality.HDTV720p.Id,
- Items = Qualities.QualityFixture.GetDefaultQualities(),
- FormatCutoff = CustomFormat.None.Id,
- FormatItems = CustomFormatsFixture.GetSampleFormatItems("None", "My Format")
- },
- old,
- newQ).Should().BeFalse();
+
+ GivenOldCustomFormats(new List { CustomFormat.None });
+ GivenNewCustomFormats(new List { _customFormat });
+
+ Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
[Test]
public void should_return_true_if_cutoffs_are_met_but_is_a_revision_upgrade()
{
- Profile profile = new Profile
+ GivenProfile(new Profile
{
Cutoff = Quality.HDTV1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
- };
+ });
+
+ GivenFileQuality(new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)));
+ GivenNewQuality(new QualityModel(Quality.WEBDL1080p, new Revision(version: 2)));
- Subject.CutoffNotMet(
- profile,
- new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)),
- new QualityModel(Quality.WEBDL1080p, new Revision(version: 2))).Should().BeTrue();
+ Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
}
}
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs
index 128e42b76..517fa6a31 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs
@@ -1,9 +1,11 @@
using System;
+using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
+using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
using NzbDrone.Core.History;
@@ -12,6 +14,7 @@ using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
+using NzbDrone.Core.Test.CustomFormats;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
@@ -35,14 +38,23 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.Resolve();
_upgradeHistory = Mocker.Resolve();
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None);
+
_fakeMovie = Builder.CreateNew()
- .With(c => c.Profile = new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() })
- .Build();
+ .With(c => c.Profile = new Profile
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ Cutoff = Quality.Bluray1080p.Id,
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id
+ })
+ .Build();
_parseResultSingle = new RemoteMovie
{
Movie = _fakeMovie,
- ParsedMovieInfo = new ParsedMovieInfo { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) }
+ ParsedMovieInfo = new ParsedMovieInfo { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) },
+ CustomFormats = new List()
};
_upgradableQuality = new QualityModel(Quality.SDTV, new Revision(version: 1));
@@ -51,6 +63,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.GetMock()
.SetupGet(s => s.EnableCompletedDownloadHandling)
.Returns(true);
+
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(new List());
}
private void GivenMostRecentForEpisode(int episodeId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType)
@@ -142,10 +158,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
{
- _fakeMovie.Profile = new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
+ _fakeMovie.Profile = new Profile
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ Cutoff = Quality.Bluray1080p.Id,
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id
+ };
+
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(new List());
+
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
@@ -154,7 +181,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_not_be_upgradable_if_cutoff_already_met()
{
- _fakeMovie.Profile = new Profile { Cutoff = Quality.WEBDL1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
+ _fakeMovie.Profile = new Profile
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ Cutoff = Quality.WEBDL1080p.Id,
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id
+ };
+
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
_upgradableQuality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
@@ -182,7 +216,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_return_false_if_cutoff_already_met_and_cdh_is_disabled()
{
GivenCdhDisabled();
- _fakeMovie.Profile = new Profile { Cutoff = Quality.WEBDL1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
+ _fakeMovie.Profile = new Profile
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ Cutoff = Quality.WEBDL1080p.Id,
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id
+ };
+
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs
index 9eb60553e..c64a2602a 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs
@@ -60,6 +60,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
remoteMovie.Release.DownloadProtocol = downloadProtocol;
remoteMovie.Release.Title = "A Movie 1998";
+ remoteMovie.CustomFormats = new List();
+
return remoteMovie;
}
@@ -324,12 +326,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_prefer_better_custom_format()
{
var quality1 = new QualityModel(Quality.Bluray720p);
- quality1.CustomFormats.Add(CustomFormat.None);
var remoteMovie1 = GivenRemoteMovie(quality1);
+ remoteMovie1.CustomFormats.Add(CustomFormat.None);
var quality2 = new QualityModel(Quality.Bluray720p);
- quality2.CustomFormats.Add(_customFormat1);
var remoteMovie2 = GivenRemoteMovie(quality2);
+ remoteMovie2.CustomFormats.Add(_customFormat1);
var decisions = new List();
decisions.Add(new DownloadDecision(remoteMovie1));
@@ -343,12 +345,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_prefer_better_custom_format2()
{
var quality1 = new QualityModel(Quality.Bluray720p);
- quality1.CustomFormats.Add(_customFormat1);
var remoteMovie1 = GivenRemoteMovie(quality1);
+ remoteMovie1.CustomFormats.Add(_customFormat1);
var quality2 = new QualityModel(Quality.Bluray720p);
- quality2.CustomFormats.Add(_customFormat2);
var remoteMovie2 = GivenRemoteMovie(quality2);
+ remoteMovie2.CustomFormats.Add(_customFormat2);
var decisions = new List();
decisions.Add(new DownloadDecision(remoteMovie1));
@@ -362,12 +364,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_prefer_2_custom_formats()
{
var quality1 = new QualityModel(Quality.Bluray720p);
- quality1.CustomFormats.Add(_customFormat1);
var remoteMovie1 = GivenRemoteMovie(quality1);
+ remoteMovie1.CustomFormats.Add(_customFormat1);
var quality2 = new QualityModel(Quality.Bluray720p);
- quality2.CustomFormats.AddRange(new List { _customFormat1, _customFormat2 });
var remoteMovie2 = GivenRemoteMovie(quality2);
+ remoteMovie2.CustomFormats.AddRange(new List { _customFormat1, _customFormat2 });
var decisions = new List();
decisions.Add(new DownloadDecision(remoteMovie1));
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/QualityUpgradeSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/QualityUpgradeSpecificationFixture.cs
index 907595566..bdacb0fec 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/QualityUpgradeSpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/QualityUpgradeSpecificationFixture.cs
@@ -1,9 +1,12 @@
-using FluentAssertions;
+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;
using NzbDrone.Core.Qualities;
+using NzbDrone.Core.Test.CustomFormats;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
@@ -12,20 +15,39 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public class QualityUpgradeSpecificationFixture : CoreTest
{
+ private static CustomFormat _customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
+ private static CustomFormat _customFormat2 = new CustomFormat("My Format 2", "L_FRENCH") { Id = 2 };
+
public static object[] IsUpgradeTestCases =
{
- new object[] { Quality.SDTV, 1, Quality.SDTV, 2, Quality.SDTV, true },
- new object[] { Quality.WEBDL720p, 1, Quality.WEBDL720p, 2, Quality.WEBDL720p, true },
- new object[] { Quality.SDTV, 1, Quality.SDTV, 1, Quality.SDTV, false },
- new object[] { Quality.WEBDL720p, 1, Quality.HDTV720p, 2, Quality.Bluray720p, false },
- new object[] { Quality.WEBDL720p, 1, Quality.HDTV720p, 2, Quality.WEBDL720p, false },
- new object[] { Quality.WEBDL720p, 1, Quality.WEBDL720p, 1, Quality.WEBDL720p, false },
- new object[] { Quality.WEBDL1080p, 1, Quality.WEBDL1080p, 1, Quality.WEBDL1080p, false }
+ // Quality upgrade trumps custom format
+ new object[] { Quality.SDTV, 1, new List(), Quality.SDTV, 2, new List(), true },
+ new object[] { Quality.SDTV, 1, new List { _customFormat1 }, Quality.SDTV, 2, new List { _customFormat1 }, true },
+ new object[] { Quality.SDTV, 1, new List { _customFormat1 }, Quality.SDTV, 2, new List { _customFormat2 }, true },
+ new object[] { Quality.SDTV, 1, new List { _customFormat2 }, Quality.SDTV, 2, new List { _customFormat1 }, true },
+
+ // Revision upgrade trumps custom format
+ new object[] { Quality.WEBDL720p, 1, new List(), Quality.WEBDL720p, 2, new List(), true },
+ new object[] { Quality.WEBDL720p, 1, new List { _customFormat1 }, Quality.WEBDL720p, 2, new List { _customFormat1 }, true },
+ new object[] { Quality.WEBDL720p, 1, new List { _customFormat1 }, Quality.WEBDL720p, 2, new List { _customFormat2 }, true },
+ new object[] { Quality.WEBDL720p, 1, new List { _customFormat2 }, Quality.WEBDL720p, 2, new List { _customFormat1 }, true },
+
+ // Custom formats apply if quality same
+ new object[] { Quality.SDTV, 1, new List(), Quality.SDTV, 1, new List(), false },
+ new object[] { Quality.SDTV, 1, new List { _customFormat1 }, Quality.SDTV, 1, new List { _customFormat1 }, false },
+ new object[] { Quality.SDTV, 1, new List { _customFormat1 }, Quality.SDTV, 1, new List { _customFormat2 }, true },
+ new object[] { Quality.SDTV, 1, new List { _customFormat2 }, Quality.SDTV, 1, new List { _customFormat1 }, false },
+
+ new object[] { Quality.WEBDL720p, 1, new List(), Quality.HDTV720p, 2, new List(), false },
+ new object[] { Quality.WEBDL720p, 1, new List(), Quality.HDTV720p, 2, new List(), false },
+ new object[] { Quality.WEBDL720p, 1, new List(), Quality.WEBDL720p, 1, new List(), false },
+ new object[] { Quality.WEBDL1080p, 1, new List(), Quality.WEBDL1080p, 1, new List(), false }
};
[SetUp]
public void Setup()
{
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None, _customFormat1, _customFormat2);
}
private void GivenAutoDownloadPropers(bool autoDownloadPropers)
@@ -37,13 +59,27 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
[TestCaseSource("IsUpgradeTestCases")]
- public void IsUpgradeTest(Quality current, int currentVersion, Quality newQuality, int newVersion, Quality cutoff, bool expected)
+ public void IsUpgradeTest(Quality current,
+ int currentVersion,
+ List currentFormats,
+ Quality newQuality,
+ int newVersion,
+ List newFormats,
+ bool expected)
{
GivenAutoDownloadPropers(true);
- var profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() };
+ var profile = new Profile
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(),
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems()
+ };
- Subject.IsUpgradable(profile, new QualityModel(current, new Revision(version: currentVersion)), new QualityModel(newQuality, new Revision(version: newVersion)))
+ Subject.IsUpgradable(profile,
+ new QualityModel(current, new Revision(version: currentVersion)),
+ currentFormats,
+ new QualityModel(newQuality, new Revision(version: newVersion)),
+ newFormats)
.Should().Be(expected);
}
@@ -54,7 +90,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
var profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() };
- Subject.IsUpgradable(profile, new QualityModel(Quality.DVD, new Revision(version: 2)), new QualityModel(Quality.DVD, new Revision(version: 1)))
+ Subject.IsUpgradable(profile,
+ new QualityModel(Quality.DVD, new Revision(version: 2)),
+ new List(),
+ new QualityModel(Quality.DVD, new Revision(version: 1)),
+ new List())
.Should().BeFalse();
}
@@ -69,7 +109,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Subject.IsUpgradable(
profile,
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
- new QualityModel(Quality.HDTV720p, new Revision(version: 1)))
+ new List(),
+ new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
+ new List())
.Should().BeFalse();
}
}
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/QueueSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/QueueSpecificationFixture.cs
index 7d9c2f0fc..074f587d1 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/QueueSpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/QueueSpecificationFixture.cs
@@ -2,13 +2,16 @@ using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
+using Moq;
using NUnit.Framework;
+using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Queue;
+using NzbDrone.Core.Test.CustomFormats;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
@@ -26,10 +29,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Mocker.Resolve();
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None);
+
_movie = Builder.CreateNew()
.With(e => e.Profile = new Profile
{
Items = Qualities.QualityFixture.GetDefaultQualities(),
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id,
UpgradeAllowed = true
})
.Build();
@@ -39,9 +46,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
.Build();
_remoteMovie = Builder.CreateNew()
- .With(r => r.Movie = _movie)
- .With(r => r.ParsedMovieInfo = new ParsedMovieInfo { Quality = new QualityModel(Quality.DVD) })
- .Build();
+ .With(r => r.Movie = _movie)
+ .With(r => r.ParsedMovieInfo = new ParsedMovieInfo { Quality = new QualityModel(Quality.DVD) })
+ .With(x => x.CustomFormats = new List { CustomFormat.None })
+ .Build();
+
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(new List());
}
private void GivenEmptyQueue()
@@ -87,12 +99,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_movie.Profile.Cutoff = Quality.Bluray1080p.Id;
var remoteMovie = Builder.CreateNew()
- .With(r => r.Movie = _movie)
- .With(r => r.ParsedMovieInfo = new ParsedMovieInfo
- {
- Quality = new QualityModel(Quality.SDTV)
- })
- .Build();
+ .With(r => r.Movie = _movie)
+ .With(r => r.ParsedMovieInfo = new ParsedMovieInfo
+ {
+ Quality = new QualityModel(Quality.SDTV)
+ })
+ .With(x => x.CustomFormats = new List { CustomFormat.None })
+ .Build();
GivenQueue(new List { remoteMovie });
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/RssSync/DelaySpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/RssSync/DelaySpecificationFixture.cs
index 74aa8b901..fa401ee29 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/RssSync/DelaySpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/RssSync/DelaySpecificationFixture.cs
@@ -4,6 +4,7 @@ using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
+using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
using NzbDrone.Core.Download.Pending;
@@ -75,7 +76,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
private void GivenUpgradeForExistingFile()
{
Mocker.GetMock()
- .Setup(s => s.IsUpgradable(It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(s => s.IsUpgradable(It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny>()))
.Returns(true);
}
diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs
index 4882e69b0..e86cc229c 100644
--- a/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs
+++ b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs
@@ -1,13 +1,17 @@
using System;
+using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
+using Moq;
using NUnit.Framework;
+using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
+using NzbDrone.Core.Test.CustomFormats;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
@@ -27,18 +31,30 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.Resolve();
_upgradeDisk = Mocker.Resolve();
+ CustomFormatsFixture.GivenCustomFormats(CustomFormat.None);
+
_firstFile = new MovieFile { Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 2)), DateAdded = DateTime.Now };
var fakeSeries = Builder.CreateNew()
- .With(c => c.Profile = new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() })
- .With(e => e.MovieFile = _firstFile)
- .Build();
+ .With(c => c.Profile = new Profile
+ {
+ Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities(),
+ FormatItems = CustomFormatsFixture.GetSampleFormatItems("None"),
+ FormatCutoff = CustomFormat.None.Id
+ })
+ .With(e => e.MovieFile = _firstFile)
+ .Build();
_parseResultSingle = new RemoteMovie
{
Movie = fakeSeries,
ParsedMovieInfo = new ParsedMovieInfo() { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) },
+ CustomFormats = new List()
};
+
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(new List());
}
private void WithFirstFileUpgradable()
@@ -63,6 +79,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_not_be_upgradable_if_qualities_are_the_same()
{
+ Mocker.GetMock()
+ .Setup(x => x.ParseCustomFormat(It.IsAny()))
+ .Returns(new List());
+
_firstFile.Quality = new QualityModel(Quality.WEBDL1080p);
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p);
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
diff --git a/src/NzbDrone.Core.Test/Framework/MigrationTest.cs b/src/NzbDrone.Core.Test/Framework/MigrationTest.cs
index c751bbf55..f738b8240 100644
--- a/src/NzbDrone.Core.Test/Framework/MigrationTest.cs
+++ b/src/NzbDrone.Core.Test/Framework/MigrationTest.cs
@@ -1,4 +1,5 @@
using System;
+using System.Data;
using FluentMigrator;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
@@ -11,18 +12,32 @@ namespace NzbDrone.Core.Test.Framework
public abstract class MigrationTest : DbTest
where TMigration : NzbDroneMigrationBase
{
- protected long MigrationVersion
+ protected long MigrationVersion => ((MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute))).Version;
+
+ [SetUp]
+ public override void SetupDb()
{
- get
- {
- var attrib = (MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute));
- return attrib.Version;
- }
+ SetupContainer();
}
protected virtual IDirectDataMapper WithMigrationTestDb(Action beforeMigration = null)
{
- var db = WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
+ return WithMigrationAction(beforeMigration).GetDirectDataMapper();
+ }
+
+ protected virtual IDbConnection WithDapperMigrationTestDb(Action beforeMigration = null)
+ {
+ return WithMigrationAction(beforeMigration).OpenConnection();
+ }
+
+ protected override void SetupLogging()
+ {
+ Mocker.SetConstant(Mocker.Resolve());
+ }
+
+ private ITestDatabase WithMigrationAction(Action beforeMigration = null)
+ {
+ return WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
{
BeforeMigration = m =>
{
@@ -33,19 +48,6 @@ namespace NzbDrone.Core.Test.Framework
}
}
});
-
- return db.GetDirectDataMapper();
- }
-
- protected override void SetupLogging()
- {
- Mocker.SetConstant(Mocker.Resolve());
- }
-
- [SetUp]
- public override void SetupDb()
- {
- SetupContainer();
}
}
}
diff --git a/src/NzbDrone.Core.Test/Framework/TestDatabase.cs b/src/NzbDrone.Core.Test/Framework/TestDatabase.cs
index 4215a66c6..3fbfdf028 100644
--- a/src/NzbDrone.Core.Test/Framework/TestDatabase.cs
+++ b/src/NzbDrone.Core.Test/Framework/TestDatabase.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using Moq;
using NzbDrone.Core.Datastore;
@@ -21,6 +22,7 @@ namespace NzbDrone.Core.Test.Framework
void Delete(T childModel)
where T : ModelBase, new();
IDirectDataMapper GetDirectDataMapper();
+ IDbConnection OpenConnection();
}
public class TestDatabase : ITestDatabase
@@ -74,5 +76,10 @@ namespace NzbDrone.Core.Test.Framework
{
return new DirectDataMapper(_dbConnection);
}
+
+ public IDbConnection OpenConnection()
+ {
+ return _dbConnection.OpenConnection();
+ }
}
}
diff --git a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs
index 19377d08f..0427b750a 100644
--- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs
+++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs
@@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
+using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.MediaFiles.MovieImport;
@@ -58,6 +59,10 @@ namespace NzbDrone.Core.Test.MediaFiles
.Setup(s => s.UpgradeMovieFile(It.IsAny(), It.IsAny(), It.IsAny()))
.Returns(new MovieFileMoveResult());
+ Mocker.GetMock()
+ .Setup(x => x.FindByDownloadId(It.IsAny()))
+ .Returns(new List());
+
_downloadClientItem = Builder.CreateNew().Build();
}
diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs
index 993ed6eb8..5b75147dd 100644
--- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs
+++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs
@@ -31,10 +31,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
.Returns(AugmentQualityResult.ResolutionOnly((int)Resolution.R1080p, Confidence.MediaInfo));
_fileExtensionAugmenter.Setup(s => s.AugmentQuality(It.IsAny()))
- .Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, (int)Resolution.R720p, Confidence.Fallback, Modifier.NONE, Confidence.Fallback, new Revision(), new List()));
+ .Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, (int)Resolution.R720p, Confidence.Fallback, Modifier.NONE, Confidence.Fallback, new Revision()));
_nameAugmenter.Setup(s => s.AugmentQuality(It.IsAny()))
- .Returns(new AugmentQualityResult(Source.TV, Confidence.Default, (int)Resolution.R480p, Confidence.Default, Modifier.NONE, Confidence.Default, new Revision(), new List()));
+ .Returns(new AugmentQualityResult(Source.TV, Confidence.Default, (int)Resolution.R480p, Confidence.Default, Modifier.NONE, Confidence.Default, new Revision()));
}
private void GivenAugmenters(params Mock[] mocks)
diff --git a/src/NzbDrone.Core.Test/MediaFiles/UpdateMovieFileQualityServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/UpdateMovieFileQualityServiceFixture.cs
deleted file mode 100644
index f2744f326..000000000
--- a/src/NzbDrone.Core.Test/MediaFiles/UpdateMovieFileQualityServiceFixture.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using System.Collections.Generic;
-using FizzWare.NBuilder;
-using Moq;
-using NUnit.Framework;
-using NzbDrone.Common.Extensions;
-using NzbDrone.Core.CustomFormats;
-using NzbDrone.Core.History;
-using NzbDrone.Core.MediaFiles;
-using NzbDrone.Core.MediaFiles.Commands;
-using NzbDrone.Core.Parser;
-using NzbDrone.Core.Parser.Model;
-using NzbDrone.Core.Qualities;
-using NzbDrone.Core.Test.Framework;
-using NzbDrone.Test.Common;
-
-namespace NzbDrone.Core.Test.MediaFiles
-{
- [TestFixture]
- public class UpdateMovieFileQualityServiceFixture : CoreTest
- {
- private MovieFile _movieFile;
- private QualityModel _oldQuality;
- private QualityModel _newQuality;
-
- private ParsedMovieInfo _newInfo;
-
- [SetUp]
- public void Setup()
- {
- _movieFile = Builder.CreateNew().With(m => m.MovieId = 0).Build();
-
- _oldQuality = new QualityModel(Quality.Bluray720p);
-
- _movieFile.Quality = _oldQuality;
-
- _newQuality = _oldQuality.JsonClone();
- var format = new CustomFormat("Awesome Format");
- format.Id = 1;
- _newQuality.CustomFormats = new List { format };
-
- _newInfo = new ParsedMovieInfo
- {
- Quality = _newQuality
- };
-
- Mocker.GetMock().Setup(s => s.GetMovies(It.IsAny>()))
- .Returns(new List { _movieFile });
-
- Mocker.GetMock().Setup(s => s.GetByMovieId(It.IsAny(), null))
- .Returns(new List());
- }
-
- private void ExecuteCommand()
- {
- Subject.Execute(new UpdateMovieFileQualityCommand(new List { 0 }));
- }
-
- [Test]
- public void should_not_update_if_unable_to_parse()
- {
- ExecuteCommand();
-
- ExceptionVerification.ExpectedWarns(1);
-
- Mocker.GetMock().Verify(s => s.Update(It.IsAny()), Times.Never());
- }
-
- [Test]
- public void should_update_with_new_formats()
- {
- Mocker.GetMock().Setup(s => s.ParseMovieInfo(It.IsAny(), It.IsAny>()))
- .Returns(_newInfo);
-
- ExecuteCommand();
-
- Mocker.GetMock().Verify(s => s.Update(It.Is(f => f.Quality.CustomFormats == _newQuality.CustomFormats)), Times.Once());
- }
-
- [Test]
- public void should_use_imported_history_title()
- {
- var imported = Builder.CreateNew()
- .With(h => h.EventType = HistoryEventType.DownloadFolderImported)
- .With(h => h.SourceTitle = "My Movie 2018.mkv").Build();
-
- Mocker.GetMock().Setup(s => s.GetByMovieId(It.IsAny(), null))
- .Returns(new List { imported });
-
- Mocker.GetMock().Setup(s => s.ParseMovieInfo("My Movie 2018.mkv", It.IsAny>()))
- .Returns(_newInfo);
-
- ExecuteCommand();
-
- Mocker.GetMock().Verify(s => s.ParseMovieInfo("My Movie 2018.mkv", It.IsAny>()));
- }
- }
-}
diff --git a/src/NzbDrone.Core.Test/MovieTests/MovieRepositoryTests/MovieRepositoryFixture.cs b/src/NzbDrone.Core.Test/MovieTests/MovieRepositoryTests/MovieRepositoryFixture.cs
index 8d5cc30cb..dac3df416 100644
--- a/src/NzbDrone.Core.Test/MovieTests/MovieRepositoryTests/MovieRepositoryFixture.cs
+++ b/src/NzbDrone.Core.Test/MovieTests/MovieRepositoryTests/MovieRepositoryFixture.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
@@ -22,19 +23,23 @@ namespace NzbDrone.Core.Test.MovieTests.MovieRepositoryTests
{
_profileRepository = Mocker.Resolve();
Mocker.SetConstant(_profileRepository);
+
+ Mocker.GetMock()
+ .Setup(x => x.All())
+ .Returns(new List());
}
[Test]
public void should_load_quality_profile()
{
var profile = new Profile
- {
- Items = Qualities.QualityFixture.GetDefaultQualities(Quality.Bluray1080p, Quality.DVD, Quality.HDTV720p),
- FormatItems = CustomFormatsFixture.GetDefaultFormatItems(),
- FormatCutoff = CustomFormat.None.Id,
- Cutoff = Quality.Bluray1080p.Id,
- Name = "TestProfile"
- };
+ {
+ Items = Qualities.QualityFixture.GetDefaultQualities(Quality.Bluray1080p, Quality.DVD, Quality.HDTV720p),
+ FormatItems = CustomFormatsFixture.GetDefaultFormatItems(),
+ FormatCutoff = CustomFormat.None.Id,
+ Cutoff = Quality.Bluray1080p.Id,
+ Name = "TestProfile"
+ };
_profileRepository.Insert(profile);
diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/AugmentersTests/AugmentWithParsedMovieInfo.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/AugmentersTests/AugmentWithParsedMovieInfo.cs
index 203c99b6e..d428345da 100644
--- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/AugmentersTests/AugmentWithParsedMovieInfo.cs
+++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/AugmentersTests/AugmentWithParsedMovieInfo.cs
@@ -1,11 +1,9 @@
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;
-using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Parser.Augmenters;
using NzbDrone.Core.Parser.Model;
-using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests.AugmentersTests
{
@@ -61,37 +59,6 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests.AugmentersTests
result.Languages.Should().BeEquivalentTo(Language.English, Language.French);
}
- [Test]
- public void should_combine_formats()
- {
- var folderInfo = new ParsedMovieInfo
- {
- Quality = new QualityModel(Quality.Bluray1080p)
- };
-
- var format1 = new CustomFormat("Awesome Format");
- format1.Id = 1;
-
- var format2 = new CustomFormat("Cool Format");
- format2.Id = 2;
-
- folderInfo.Quality.CustomFormats = new List { format1 };
-
- MovieInfo.Quality.CustomFormats = new List { format2 };
-
- var result = Subject.AugmentMovieInfo(MovieInfo, folderInfo);
-
- result.Quality.CustomFormats.Count.Should().Be(2);
- result.Quality.CustomFormats.Should().BeEquivalentTo(format2, format1);
-
- folderInfo.Quality.CustomFormats = new List { format1, format2 };
-
- result = Subject.AugmentMovieInfo(MovieInfo, folderInfo);
-
- result.Quality.CustomFormats.Count.Should().Be(2);
- result.Quality.CustomFormats.Should().BeEquivalentTo(format2, format1);
- }
-
[Test]
public void should_use_folder_release_group()
{
diff --git a/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs b/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs
index 1fe68807c..b4a7cf9f2 100644
--- a/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs
+++ b/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs
@@ -1,10 +1,8 @@
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;
-using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
-using NzbDrone.Core.Test.CustomFormats;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Qualities
@@ -14,11 +12,6 @@ namespace NzbDrone.Core.Test.Qualities
{
public QualityModelComparer Subject { get; set; }
- private CustomFormat _customFormat1;
- private CustomFormat _customFormat2;
- private CustomFormat _customFormat3;
- private CustomFormat _customFormat4;
-
[SetUp]
public void Setup()
{
@@ -78,18 +71,6 @@ namespace NzbDrone.Core.Test.Qualities
Subject = new QualityModelComparer(profile);
}
- private void GivenDefaultProfileWithFormats()
- {
- _customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
- _customFormat2 = new CustomFormat("My Format 2", "L_FRENCH") { Id = 2 };
- _customFormat3 = new CustomFormat("My Format 3", "L_SPANISH") { Id = 3 };
- _customFormat4 = new CustomFormat("My Format 4", "L_ITALIAN") { Id = 4 };
-
- CustomFormatsFixture.GivenCustomFormats(CustomFormat.None, _customFormat1, _customFormat2, _customFormat3, _customFormat4);
-
- Subject = new QualityModelComparer(new Profile { Items = QualityFixture.GetDefaultQualities(), FormatItems = CustomFormatsFixture.GetSampleFormatItems(), FormatCutoff = _customFormat2.Id });
- }
-
[Test]
public void should_be_greater_when_first_quality_is_greater_than_second()
{
@@ -142,32 +123,6 @@ namespace NzbDrone.Core.Test.Qualities
compare.Should().BeGreaterThan(0);
}
- [Test]
- public void should_be_lesser_when_first_quality_is_worse_format()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new QualityModel(Quality.DVD) { CustomFormats = new List { _customFormat1 } };
- var second = new QualityModel(Quality.DVD) { CustomFormats = new List { _customFormat2 } };
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().BeLessThan(0);
- }
-
- [Test]
- public void should_be_greater_when_first_quality_is_better_format()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new QualityModel(Quality.DVD) { CustomFormats = new List { _customFormat2 } };
- var second = new QualityModel(Quality.DVD) { CustomFormats = new List { _customFormat1 } };
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().BeGreaterThan(0);
- }
-
[Test]
public void should_ignore_group_order_by_default()
{
@@ -193,57 +148,5 @@ namespace NzbDrone.Core.Test.Qualities
compare.Should().BeLessThan(0);
}
-
- [Test]
- public void should_be_greater_when_one_format_over_cutoff()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new List { _customFormat3 };
- var second = _customFormat2.Id;
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().BeGreaterThan(0);
- }
-
- [Test]
- public void should_be_greater_when_multiple_formats_over_cutoff()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new List { _customFormat3, _customFormat4 };
- var second = _customFormat2.Id;
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().BeGreaterThan(0);
- }
-
- [Test]
- public void should_be_greater_when_one_better_one_worse_than_cutoff()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new List { _customFormat1, _customFormat3 };
- var second = _customFormat2.Id;
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().BeGreaterThan(0);
- }
-
- [Test]
- public void should_be_zero_when_one_worse_one_equal_to_cutoff()
- {
- GivenDefaultProfileWithFormats();
-
- var first = new List { _customFormat1, _customFormat2 };
- var second = _customFormat2.Id;
-
- var compare = Subject.Compare(first, second);
-
- compare.Should().Be(0);
- }
}
}
diff --git a/src/NzbDrone.Core/Blacklisting/Blacklist.cs b/src/NzbDrone.Core/Blacklisting/Blacklist.cs
index c041126cf..2a3496cce 100644
--- a/src/NzbDrone.Core/Blacklisting/Blacklist.cs
+++ b/src/NzbDrone.Core/Blacklisting/Blacklist.cs
@@ -4,6 +4,7 @@ using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Movies;
+using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Blacklisting
@@ -19,6 +20,7 @@ namespace NzbDrone.Core.Blacklisting
public long? Size { get; set; }
public DownloadProtocol Protocol { get; set; }
public string Indexer { get; set; }
+ public IndexerFlags IndexerFlags { get; set; }
public string Message { get; set; }
public string TorrentInfoHash { get; set; }
public List Languages { get; set; }
diff --git a/src/NzbDrone.Core/Blacklisting/BlacklistService.cs b/src/NzbDrone.Core/Blacklisting/BlacklistService.cs
index fb9bd3ad6..97e917d65 100644
--- a/src/NzbDrone.Core/Blacklisting/BlacklistService.cs
+++ b/src/NzbDrone.Core/Blacklisting/BlacklistService.cs
@@ -152,6 +152,11 @@ namespace NzbDrone.Core.Blacklisting
Languages = message.Languages
};
+ if (Enum.TryParse(message.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags))
+ {
+ blacklist.IndexerFlags = flags;
+ }
+
_blacklistRepository.Insert(blacklist);
}
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormat.cs b/src/NzbDrone.Core/CustomFormats/CustomFormat.cs
index 5d9c0a62e..68fb488d7 100644
--- a/src/NzbDrone.Core/CustomFormats/CustomFormat.cs
+++ b/src/NzbDrone.Core/CustomFormats/CustomFormat.cs
@@ -7,10 +7,6 @@ namespace NzbDrone.Core.CustomFormats
{
public class CustomFormat : ModelBase, IEquatable
{
- public string Name { get; set; }
-
- public List FormatTags { get; set; }
-
public CustomFormat()
{
}
@@ -21,18 +17,25 @@ namespace NzbDrone.Core.CustomFormats
FormatTags = tags.Select(t => new FormatTag(t)).ToList();
}
- public static implicit operator CustomFormatDefinition(CustomFormat format) => new CustomFormatDefinition { Id = format.Id, Name = format.Name, FormatTags = format.FormatTags };
+ public static CustomFormat None => new CustomFormat
+ {
+ Id = 0,
+ Name = "None",
+ FormatTags = new List()
+ };
+
+ public string Name { get; set; }
+
+ public List FormatTags { get; set; }
public override string ToString()
{
return Name;
}
- public static CustomFormat None => new CustomFormat("None");
-
public bool Equals(CustomFormat other)
{
- if (ReferenceEquals(null, other))
+ if (other is null)
{
return false;
}
@@ -47,7 +50,7 @@ namespace NzbDrone.Core.CustomFormats
public override bool Equals(object obj)
{
- if (ReferenceEquals(null, obj))
+ if (obj is null)
{
return false;
}
@@ -67,26 +70,7 @@ namespace NzbDrone.Core.CustomFormats
public override int GetHashCode()
{
- return Id.GetHashCode();
- }
- }
-
- public static class CustomFormatExtensions
- {
- public static string ToExtendedString(this IEnumerable formats)
- {
- return string.Join(", ", formats.Select(f => f.ToString()));
- }
-
- public static List WithNone(this IEnumerable formats)
- {
- var list = formats.ToList();
- if (list.Any())
- {
- return list;
- }
-
- return new List { CustomFormat.None };
+ return Id;
}
}
}
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormatCalculationService.cs b/src/NzbDrone.Core/CustomFormats/CustomFormatCalculationService.cs
new file mode 100644
index 000000000..9bd848d0f
--- /dev/null
+++ b/src/NzbDrone.Core/CustomFormats/CustomFormatCalculationService.cs
@@ -0,0 +1,171 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NzbDrone.Common.Extensions;
+using NzbDrone.Core.Blacklisting;
+using NzbDrone.Core.MediaFiles;
+using NzbDrone.Core.Movies;
+using NzbDrone.Core.Parser;
+using NzbDrone.Core.Parser.Model;
+
+namespace NzbDrone.Core.CustomFormats
+{
+ public interface ICustomFormatCalculationService
+ {
+ List ParseCustomFormat(ParsedMovieInfo movieInfo);
+ List ParseCustomFormat(MovieFile movieFile);
+ List ParseCustomFormat(Blacklist blacklist);
+ List ParseCustomFormat(History.History history);
+ List MatchFormatTags(ParsedMovieInfo movieInfo);
+ }
+
+ public class CustomFormatCalculationService : ICustomFormatCalculationService
+ {
+ private readonly ICustomFormatService _formatService;
+ private readonly IParsingService _parsingService;
+ private readonly IMovieService _movieService;
+
+ public CustomFormatCalculationService(ICustomFormatService formatService,
+ IParsingService parsingService,
+ IMovieService movieService)
+ {
+ _formatService = formatService;
+ _parsingService = parsingService;
+ _movieService = movieService;
+ }
+
+ public List ParseCustomFormat(ParsedMovieInfo movieInfo)
+ {
+ return MatchFormatTags(movieInfo)
+ .Where(m => m.GoodMatch)
+ .Select(r => r.CustomFormat)
+ .ToList();
+ }
+
+ public List ParseCustomFormat(MovieFile movieFile)
+ {
+ return MatchFormatTags(movieFile)
+ .Where(m => m.GoodMatch)
+ .Select(r => r.CustomFormat)
+ .ToList();
+ }
+
+ public List ParseCustomFormat(Blacklist blacklist)
+ {
+ return MatchFormatTags(blacklist)
+ .Where(m => m.GoodMatch)
+ .Select(r => r.CustomFormat)
+ .ToList();
+ }
+
+ public List ParseCustomFormat(History.History history)
+ {
+ return MatchFormatTags(history)
+ .Where(m => m.GoodMatch)
+ .Select(r => r.CustomFormat)
+ .ToList();
+ }
+
+ public List MatchFormatTags(ParsedMovieInfo movieInfo)
+ {
+ var formats = _formatService.All();
+
+ var matches = new List();
+
+ foreach (var customFormat in formats)
+ {
+ var tagTypeMatches = customFormat.FormatTags
+ .GroupBy(t => t.TagType)
+ .Select(g => new FormatTagMatchesGroup
+ {
+ Type = g.Key,
+ Matches = g.ToDictionary(t => t, t => t.DoesItMatch(movieInfo))
+ })
+ .ToList();
+
+ matches.Add(new CustomFormatMatchResult
+ {
+ CustomFormat = customFormat,
+ GroupMatches = tagTypeMatches
+ });
+ }
+
+ return matches;
+ }
+
+ private List MatchFormatTags(MovieFile file)
+ {
+ var info = new ParsedMovieInfo
+ {
+ MovieTitle = file.Movie.Title,
+ SimpleReleaseTitle = file.GetSceneOrFileName().SimplifyReleaseTitle(),
+ Quality = file.Quality,
+ Languages = file.Languages,
+ ReleaseGroup = file.ReleaseGroup,
+ Edition = file.Edition,
+ Year = file.Movie.Year,
+ ImdbId = file.Movie.ImdbId,
+ ExtraInfo = new Dictionary
+ {
+ { "IndexerFlags", file.IndexerFlags },
+ { "Size", file.Size },
+ { "Filename", System.IO.Path.GetFileName(file.RelativePath) }
+ }
+ };
+
+ return MatchFormatTags(info);
+ }
+
+ private List MatchFormatTags(Blacklist blacklist)
+ {
+ var parsed = _parsingService.ParseMovieInfo(blacklist.SourceTitle, null);
+
+ var info = new ParsedMovieInfo
+ {
+ MovieTitle = blacklist.Movie.Title,
+ SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? blacklist.SourceTitle.SimplifyReleaseTitle(),
+ Quality = blacklist.Quality,
+ Languages = blacklist.Languages,
+ ReleaseGroup = parsed?.ReleaseGroup,
+ Edition = parsed?.Edition,
+ Year = blacklist.Movie.Year,
+ ImdbId = blacklist.Movie.ImdbId,
+ ExtraInfo = new Dictionary
+ {
+ { "IndexerFlags", blacklist.IndexerFlags },
+ { "Size", blacklist.Size }
+ }
+ };
+
+ return MatchFormatTags(info);
+ }
+
+ private List MatchFormatTags(History.History history)
+ {
+ var movie = _movieService.GetMovie(history.MovieId);
+ var parsed = _parsingService.ParseMovieInfo(history.SourceTitle, null);
+
+ Enum.TryParse(history.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags);
+ int.TryParse(history.Data.GetValueOrDefault("size"), out var size);
+
+ var info = new ParsedMovieInfo
+ {
+ MovieTitle = movie.Title,
+ SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? history.SourceTitle.SimplifyReleaseTitle(),
+ Quality = history.Quality,
+ Languages = history.Languages,
+ ReleaseGroup = parsed?.ReleaseGroup,
+ Edition = parsed?.Edition,
+ Year = movie.Year,
+ ImdbId = movie.ImdbId,
+ ExtraInfo = new Dictionary
+ {
+ { "IndexerFlags", flags },
+ { "Size", size }
+ }
+ };
+
+ return MatchFormatTags(info);
+ }
+ }
+}
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormatDefinition.cs b/src/NzbDrone.Core/CustomFormats/CustomFormatDefinition.cs
deleted file mode 100644
index 029699c68..000000000
--- a/src/NzbDrone.Core/CustomFormats/CustomFormatDefinition.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System.Collections.Generic;
-using NzbDrone.Core.Datastore;
-
-namespace NzbDrone.Core.CustomFormats
-{
- public class CustomFormatDefinition : ModelBase
- {
- public string Name { get; set; }
-
- public List FormatTags { get; set; }
-
- public static implicit operator CustomFormat(CustomFormatDefinition def) => new CustomFormat { Id = def.Id, Name = def.Name, FormatTags = def.FormatTags };
- }
-}
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormatMatchResult.cs b/src/NzbDrone.Core/CustomFormats/CustomFormatMatchResult.cs
new file mode 100644
index 000000000..74df54381
--- /dev/null
+++ b/src/NzbDrone.Core/CustomFormats/CustomFormatMatchResult.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace NzbDrone.Core.CustomFormats
+{
+ public class CustomFormatMatchResult
+ {
+ public CustomFormat CustomFormat { get; set; }
+
+ public List GroupMatches { get; set; }
+
+ public bool GoodMatch => GroupMatches.All(g => g.DidMatch);
+ }
+}
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormatRepository.cs b/src/NzbDrone.Core/CustomFormats/CustomFormatRepository.cs
index 01ec3d00e..0a8e868d9 100644
--- a/src/NzbDrone.Core/CustomFormats/CustomFormatRepository.cs
+++ b/src/NzbDrone.Core/CustomFormats/CustomFormatRepository.cs
@@ -3,11 +3,11 @@ using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.CustomFormats
{
- public interface ICustomFormatRepository : IBasicRepository
+ public interface ICustomFormatRepository : IBasicRepository
{
}
- public class CustomFormatRepository : BasicRepository, ICustomFormatRepository
+ public class CustomFormatRepository : BasicRepository, ICustomFormatRepository
{
public CustomFormatRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
diff --git a/src/NzbDrone.Core/CustomFormats/CustomFormatService.cs b/src/NzbDrone.Core/CustomFormats/CustomFormatService.cs
index ce85b69eb..7e0df81d6 100644
--- a/src/NzbDrone.Core/CustomFormats/CustomFormatService.cs
+++ b/src/NzbDrone.Core/CustomFormats/CustomFormatService.cs
@@ -1,14 +1,9 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using NLog;
using NzbDrone.Common.Cache;
-using NzbDrone.Common.Composition;
-using NzbDrone.Core.Blacklisting;
+using NzbDrone.Core.CustomFormats.Events;
using NzbDrone.Core.Datastore;
-using NzbDrone.Core.History;
-using NzbDrone.Core.MediaFiles;
-using NzbDrone.Core.Profiles;
+using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.CustomFormats
{
@@ -24,162 +19,62 @@ namespace NzbDrone.Core.CustomFormats
public class CustomFormatService : ICustomFormatService
{
private readonly ICustomFormatRepository _formatRepository;
- private readonly IHistoryService _historyService;
- private IProfileService _profileService;
-
- public IProfileService ProfileService
- {
- get
- {
- if (_profileService == null)
- {
- _profileService = _container.Resolve();
- }
-
- return _profileService;
- }
- }
-
- private readonly IContainer _container;
+ private readonly IEventAggregator _eventAggregator;
private readonly ICached> _cache;
- private readonly Logger _logger;
-
- public static Dictionary AllCustomFormats;
public CustomFormatService(ICustomFormatRepository formatRepository,
- ICacheManager cacheManager,
- IContainer container,
- IHistoryService historyService,
- Logger logger)
+ ICacheManager cacheManager,
+ IEventAggregator eventAggregator)
{
_formatRepository = formatRepository;
- _container = container;
+ _eventAggregator = eventAggregator;
_cache = cacheManager.GetCache>(typeof(CustomFormat), "formats");
- _historyService = historyService;
- _logger = logger;
-
- // Fill up the cache for subsequent DB lookups
- All();
}
- public void Update(CustomFormat customFormat)
+ private Dictionary AllDictionary()
{
- _formatRepository.Update(customFormat);
- _cache.Clear();
+ return _cache.Get("all", () => _formatRepository.All().ToDictionary(m => m.Id));
}
- public CustomFormat Insert(CustomFormat customFormat)
+ public List All()
{
- var ret = _formatRepository.Insert(customFormat);
- try
- {
- ProfileService.AddCustomFormat(ret);
- }
- catch (Exception e)
- {
- _logger.Error(e, "Failure while trying to add the new custom format to all profiles. Deleting again!");
- _formatRepository.Delete(ret);
- throw;
- }
-
- _cache.Clear();
- return ret;
+ return AllDictionary().Values.ToList();
}
- public void Delete(int id)
+ public CustomFormat GetById(int id)
{
- _cache.Clear();
- try
- {
- //First history:
- var historyRepo = _container.Resolve();
- DeleteInRepo(historyRepo,
- h => h.Quality.CustomFormats,
- (h, f) =>
- {
- h.Quality.CustomFormats = f;
- return h;
- },
- id);
-
- //Then Blacklist:
- var blacklistRepo = _container.Resolve();
- DeleteInRepo(blacklistRepo,
- h => h.Quality.CustomFormats,
- (h, f) =>
- {
- h.Quality.CustomFormats = f;
- return h;
- },
- id);
-
- //Then MovieFiles:
- var moviefileRepo = _container.Resolve();
- DeleteInRepo(moviefileRepo,
- h => h.Quality.CustomFormats,
- (h, f) =>
- {
- h.Quality.CustomFormats = f;
- return h;
- },
- id);
-
- //Then Profiles
- ProfileService.DeleteCustomFormat(id);
- }
- catch (Exception e)
- {
- _logger.Error(e, "Failed to delete format with id {} from other repositories! Format will not be deleted!", id);
- throw;
- }
-
- //Finally delete the format for real!
- _formatRepository.Delete(id);
+ return AllDictionary()[id];
+ }
+ public void Update(CustomFormat customFormat)
+ {
+ _formatRepository.Update(customFormat);
_cache.Clear();
}
- private void DeleteInRepo(IBasicRepository repository,
- Func> queryFunc,
- Func, TModel> updateFunc,
- int customFormatId)
- where TModel : ModelBase, new()
+ public CustomFormat Insert(CustomFormat customFormat)
{
- var allItems = repository.All();
+ // Add to DB then insert into profiles
+ var result = _formatRepository.Insert(customFormat);
+ _cache.Clear();
- var toUpdate = allItems.Where(r => queryFunc(r).Exists(c => c.Id == customFormatId)).Select(r =>
- {
- return updateFunc(r, queryFunc(r).Where(c => c.Id != customFormatId).ToList());
- });
+ _eventAggregator.PublishEvent(new CustomFormatAddedEvent(result));
- repository.UpdateMany(toUpdate.ToList());
+ return result;
}
- private Dictionary AllDictionary()
+ public void Delete(int id)
{
- return _cache.Get("all", () =>
- {
- var all = _formatRepository.All().Select(x => (CustomFormat)x).ToDictionary(m => m.Id);
- AllCustomFormats = all;
- return all;
- });
- }
+ var format = _formatRepository.Get(id);
- public List All()
- {
- return AllDictionary().Values.ToList();
- }
+ // Remove from profiles before removing from DB
+ _eventAggregator.PublishEvent(new CustomFormatDeletedEvent(format));
- public CustomFormat GetById(int id)
- {
- return AllDictionary()[id];
+ _formatRepository.Delete(id);
+ _cache.Clear();
}
- public static Dictionary> Templates
- {
- get
- {
- return new Dictionary