mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-25 22:36:59 -04:00
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using FizzWare.NBuilder;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Common.Disk;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
@@ -21,11 +21,12 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
public static class TestCaseFactory
|
||||
{
|
||||
private static readonly string[] MediaFiles = new [] { "nin.mp2", "nin.mp3", "nin.flac", "nin.m4a", "nin.wma", "nin.ape", "nin.opus" };
|
||||
private static readonly string[] MediaFiles = new[] { "nin.mp2", "nin.mp3", "nin.flac", "nin.m4a", "nin.wma", "nin.ape", "nin.opus" };
|
||||
|
||||
private static readonly string[] SkipProperties = new [] { "IsValid", "Duration", "Quality", "MediaInfo", "ImageFile" };
|
||||
private static readonly Dictionary<string, string[]> SkipPropertiesByFile = new Dictionary<string, string[]> {
|
||||
{ "nin.mp2", new [] {"OriginalReleaseDate"} }
|
||||
private static readonly string[] SkipProperties = new[] { "IsValid", "Duration", "Quality", "MediaInfo", "ImageFile" };
|
||||
private static readonly Dictionary<string, string[]> SkipPropertiesByFile = new Dictionary<string, string[]>
|
||||
{
|
||||
{ "nin.mp2", new[] { "OriginalReleaseDate" } }
|
||||
};
|
||||
|
||||
public static IEnumerable TestCases
|
||||
@@ -39,33 +40,34 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
toSkip = toSkip.Union(SkipPropertiesByFile[file]).ToArray();
|
||||
}
|
||||
|
||||
yield return new TestCaseData(file, toSkip).SetName($"{{m}}_{file.Replace("nin.", "")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string testdir = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media");
|
||||
private string copiedFile;
|
||||
private AudioTag testTags;
|
||||
private readonly string _testdir = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media");
|
||||
private string _copiedFile;
|
||||
private AudioTag _testTags;
|
||||
private IDiskProvider _diskProvider;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_diskProvider = Mocker.Resolve<IDiskProvider>("ActualDiskProvider");
|
||||
|
||||
Mocker.SetConstant<IDiskProvider>(_diskProvider);
|
||||
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(x => x.WriteAudioTags)
|
||||
.Returns(WriteAudioTagsType.Sync);
|
||||
|
||||
var imageFile = Path.Combine(testdir, "nin.png");
|
||||
var imageFile = Path.Combine(_testdir, "nin.png");
|
||||
var imageSize = _diskProvider.GetFileSize(imageFile);
|
||||
|
||||
// have to manually set the arrays of string parameters and integers to values > 1
|
||||
testTags = Builder<AudioTag>.CreateNew()
|
||||
_testTags = Builder<AudioTag>.CreateNew()
|
||||
.With(x => x.Track = 2)
|
||||
.With(x => x.TrackCount = 33)
|
||||
.With(x => x.Disc = 44)
|
||||
@@ -74,9 +76,9 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
.With(x => x.Year = 2019)
|
||||
.With(x => x.OriginalReleaseDate = new DateTime(2009, 4, 1))
|
||||
.With(x => x.OriginalYear = 2009)
|
||||
.With(x => x.Performers = new [] { "Performer1" })
|
||||
.With(x => x.AlbumArtists = new [] { "방탄소년단" })
|
||||
.With(x => x.Genres = new [] { "Genre1", "Genre2" })
|
||||
.With(x => x.Performers = new[] { "Performer1" })
|
||||
.With(x => x.AlbumArtists = new[] { "방탄소년단" })
|
||||
.With(x => x.Genres = new[] { "Genre1", "Genre2" })
|
||||
.With(x => x.ImageFile = imageFile)
|
||||
.With(x => x.ImageSize = imageSize)
|
||||
.Build();
|
||||
@@ -85,19 +87,19 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
[TearDown]
|
||||
public void Cleanup()
|
||||
{
|
||||
if (File.Exists(copiedFile))
|
||||
if (File.Exists(_copiedFile))
|
||||
{
|
||||
File.Delete(copiedFile);
|
||||
File.Delete(_copiedFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void GivenFileCopy(string filename)
|
||||
{
|
||||
var original = Path.Combine(testdir, filename);
|
||||
var original = Path.Combine(_testdir, filename);
|
||||
var tempname = $"temp_{Path.GetRandomFileName()}{Path.GetExtension(filename)}";
|
||||
copiedFile = Path.Combine(testdir, tempname);
|
||||
_copiedFile = Path.Combine(_testdir, tempname);
|
||||
|
||||
File.Copy(original, copiedFile);
|
||||
File.Copy(original, _copiedFile);
|
||||
}
|
||||
|
||||
private void VerifyDifferent(AudioTag a, AudioTag b, string[] skipProperties)
|
||||
@@ -108,7 +110,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (property.CanRead)
|
||||
{
|
||||
if (property.PropertyType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEquatable<>)) ||
|
||||
@@ -120,8 +122,8 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
}
|
||||
else if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
|
||||
{
|
||||
var val1 = (IEnumerable) property.GetValue(a, null);
|
||||
var val2 = (IEnumerable) property.GetValue(b, null);
|
||||
var val1 = (IEnumerable)property.GetValue(a, null);
|
||||
var val2 = (IEnumerable)property.GetValue(b, null);
|
||||
|
||||
if (val1 != null && val2 != null)
|
||||
{
|
||||
@@ -152,9 +154,9 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
}
|
||||
else if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
|
||||
{
|
||||
var val1 = (IEnumerable) property.GetValue(a, null);
|
||||
var val2 = (IEnumerable) property.GetValue(b, null);
|
||||
|
||||
var val1 = (IEnumerable)property.GetValue(a, null);
|
||||
var val2 = (IEnumerable)property.GetValue(b, null);
|
||||
|
||||
if (val1 != null || val2 != null)
|
||||
{
|
||||
val1.Should().BeEquivalentTo(val2, $"{property.Name} should be equal");
|
||||
@@ -164,48 +166,52 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
}
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_read_duration(string filename, string[] ignored)
|
||||
{
|
||||
var path = Path.Combine(testdir, filename);
|
||||
var path = Path.Combine(_testdir, filename);
|
||||
|
||||
var tags = Subject.ReadTags(path);
|
||||
|
||||
tags.Duration.Should().BeCloseTo(new TimeSpan(0, 0, 1, 25, 130), 100);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_read_write_tags(string filename, string[] skipProperties)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
var path = _copiedFile;
|
||||
|
||||
var initialtags = Subject.ReadAudioTag(path);
|
||||
|
||||
VerifyDifferent(initialtags, testTags, skipProperties);
|
||||
VerifyDifferent(initialtags, _testTags, skipProperties);
|
||||
|
||||
testTags.Write(path);
|
||||
_testTags.Write(path);
|
||||
|
||||
var writtentags = Subject.ReadAudioTag(path);
|
||||
|
||||
VerifySame(writtentags, testTags, skipProperties);
|
||||
VerifySame(writtentags, _testTags, skipProperties);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_remove_mb_tags(string filename, string[] skipProperties)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
var path = _copiedFile;
|
||||
|
||||
var track = new TrackFile {
|
||||
var track = new TrackFile
|
||||
{
|
||||
Path = path
|
||||
};
|
||||
|
||||
testTags.Write(path);
|
||||
_testTags.Write(path);
|
||||
|
||||
var withmb = Subject.ReadAudioTag(path);
|
||||
|
||||
VerifySame(withmb, testTags, skipProperties);
|
||||
VerifySame(withmb, _testTags, skipProperties);
|
||||
|
||||
Subject.RemoveMusicBrainzTags(track);
|
||||
|
||||
@@ -222,17 +228,19 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
tag.MusicBrainzAlbumComment.Should().BeNull();
|
||||
tag.MusicBrainzReleaseTrackId.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_read_audiotag_from_file_with_no_tags(string filename, string[] skipProperties)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
var path = _copiedFile;
|
||||
|
||||
Subject.RemoveAllTags(path);
|
||||
|
||||
var tag = Subject.ReadAudioTag(path);
|
||||
var expected = new AudioTag() {
|
||||
var expected = new AudioTag()
|
||||
{
|
||||
Performers = new string[0],
|
||||
AlbumArtists = new string[0],
|
||||
Genres = new string[0]
|
||||
@@ -242,12 +250,13 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
tag.Quality.Should().NotBeNull();
|
||||
tag.MediaInfo.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_read_parsedtrackinfo_from_file_with_no_tags(string filename, string[] skipProperties)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
var path = _copiedFile;
|
||||
|
||||
Subject.RemoveAllTags(path);
|
||||
|
||||
@@ -256,8 +265,9 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
tag.Quality.Should().NotBeNull();
|
||||
tag.MediaInfo.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_set_quality_and_mediainfo_for_corrupt_file(string filename, string[] skipProperties)
|
||||
{
|
||||
// use missing to simulate corrupt
|
||||
@@ -267,44 +277,46 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
VerifySame(tag, expected, skipProperties);
|
||||
tag.Quality.Should().NotBeNull();
|
||||
tag.MediaInfo.Should().NotBeNull();
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_read_file_with_only_title_tag(string filename, string[] ignored)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
var path = _copiedFile;
|
||||
|
||||
Subject.RemoveAllTags(path);
|
||||
|
||||
|
||||
var nametag = new AudioTag();
|
||||
nametag.Title = "test";
|
||||
nametag.Write(path);
|
||||
|
||||
var tag = Subject.ReadTags(path);
|
||||
tag.Title.Should().Be("test");
|
||||
|
||||
|
||||
tag.Quality.Should().NotBeNull();
|
||||
tag.MediaInfo.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_remove_date_from_tags_when_not_in_metadata(string filename, string[] ignored)
|
||||
{
|
||||
GivenFileCopy(filename);
|
||||
var path = copiedFile;
|
||||
|
||||
testTags.Write(path);
|
||||
|
||||
testTags.Date = null;
|
||||
testTags.OriginalReleaseDate = null;
|
||||
|
||||
testTags.Write(path);
|
||||
|
||||
var path = _copiedFile;
|
||||
|
||||
_testTags.Write(path);
|
||||
|
||||
_testTags.Date = null;
|
||||
_testTags.OriginalReleaseDate = null;
|
||||
|
||||
_testTags.Write(path);
|
||||
|
||||
var onDisk = Subject.ReadAudioTag(path);
|
||||
|
||||
|
||||
onDisk.Date.HasValue.Should().BeFalse();
|
||||
onDisk.OriginalReleaseDate.HasValue.Should().BeFalse();
|
||||
}
|
||||
@@ -314,14 +326,14 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
GivenFileCopy("nin.mp2");
|
||||
|
||||
using(var file = TagLib.File.Create(copiedFile))
|
||||
using (var file = TagLib.File.Create(_copiedFile))
|
||||
{
|
||||
var id3tag = (TagLib.Id3v2.Tag) file.GetTag(TagLib.TagTypes.Id3v2);
|
||||
var id3tag = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
|
||||
id3tag.SetTextFrame("TORY", "0");
|
||||
file.Save();
|
||||
}
|
||||
|
||||
var tag = Subject.ReadAudioTag(copiedFile);
|
||||
var tag = Subject.ReadAudioTag(_copiedFile);
|
||||
tag.OriginalReleaseDate.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
@@ -331,7 +343,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
var artist = Builder<Artist>.CreateNew()
|
||||
.With(x => x.Metadata = meta)
|
||||
.Build();
|
||||
|
||||
|
||||
var album = Builder<Album>.CreateNew()
|
||||
.With(x => x.Artist = artist)
|
||||
.Build();
|
||||
@@ -345,7 +357,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
.With(x => x.Country = new List<string>())
|
||||
.With(x => x.Label = new List<string>())
|
||||
.Build();
|
||||
|
||||
|
||||
var tracks = Builder<Track>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(x => x.AlbumRelease = release)
|
||||
@@ -370,7 +382,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
var file = GivenPopulatedTrackfile(0);
|
||||
var tag = Subject.GetTrackMetadata(file);
|
||||
|
||||
|
||||
tag.MusicBrainzReleaseCountry.Should().BeNull();
|
||||
}
|
||||
|
||||
@@ -379,7 +391,6 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
{
|
||||
// make sure that we aren't relying on index of items in
|
||||
// Media being the same as the medium number
|
||||
|
||||
var file = GivenPopulatedTrackfile(100);
|
||||
var tag = Subject.GetTrackMetadata(file);
|
||||
|
||||
@@ -397,7 +408,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
|
||||
|
||||
var file = GivenPopulatedTrackfile(0);
|
||||
|
||||
file.Path = copiedFile;
|
||||
file.Path = _copiedFile;
|
||||
Subject.WriteTags(file, false, true);
|
||||
|
||||
var fileInfo = _diskProvider.GetFileInfo(file.Path);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using FluentAssertions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using System;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
{
|
||||
@@ -102,10 +102,11 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(x => x.GetFilesWithBasePath(_artist.Path))
|
||||
.Returns(files.Select(x => new TrackFile {
|
||||
Path = x,
|
||||
Modified = lastWrite.Value.UtcDateTime
|
||||
}).ToList());
|
||||
.Returns(files.Select(x => new TrackFile
|
||||
{
|
||||
Path = x,
|
||||
Modified = lastWrite.Value.UtcDateTime
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -412,12 +413,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Setup(x => x.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>(), It.IsAny<bool>()))
|
||||
.Returns((List<IFileInfo> fileList, Artist artist, FilterFilesType filter, bool includeExisting) =>
|
||||
fileList.Select(x => new LocalTrack {
|
||||
Artist = artist,
|
||||
Path = x.FullName,
|
||||
Modified = x.LastWriteTimeUtc,
|
||||
FileTrackInfo = new ParsedTrackInfo()
|
||||
})
|
||||
fileList.Select(x => new LocalTrack
|
||||
{
|
||||
Artist = artist,
|
||||
Path = x.FullName,
|
||||
Modified = x.LastWriteTimeUtc,
|
||||
FileTrackInfo = new ParsedTrackInfo()
|
||||
})
|
||||
.Select(x => new ImportDecision<LocalTrack>(x, new Rejection("Reject")))
|
||||
.ToList());
|
||||
}
|
||||
@@ -425,7 +427,8 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
[Test]
|
||||
public void should_insert_new_unmatched_files_when_all_new()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
@@ -444,7 +447,8 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
[Test]
|
||||
public void should_insert_new_unmatched_files_when_some_known()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
@@ -463,7 +467,8 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
[Test]
|
||||
public void should_not_insert_files_when_all_known()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
@@ -486,7 +491,8 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
[Test]
|
||||
public void should_not_update_info_for_unchanged_known_files()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
@@ -504,13 +510,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.Update(It.Is<List<TrackFile>>(l => l.Count > 0)),
|
||||
Times.Never());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_info_for_changed_known_files()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
@@ -529,7 +535,8 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
[Test]
|
||||
public void should_update_fields_for_updated_files()
|
||||
{
|
||||
var files = new List<string> {
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
};
|
||||
|
||||
@@ -542,9 +549,10 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
.With(x => x.Modified = new DateTime(2019, 2, 1))
|
||||
.With(x => x.Size = 100)
|
||||
.With(x => x.Quality = new QualityModel(Quality.FLAC))
|
||||
.With(x => x.FileTrackInfo = new ParsedTrackInfo {
|
||||
MediaInfo = Builder<MediaInfoModel>.CreateNew().Build()
|
||||
})
|
||||
.With(x => x.FileTrackInfo = new ParsedTrackInfo
|
||||
{
|
||||
MediaInfo = Builder<MediaInfoModel>.CreateNew().Build()
|
||||
})
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
@@ -555,13 +563,12 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.Update(It.Is<List<TrackFile>>(
|
||||
l => l.Count == 1 &&
|
||||
l => l.Count == 1 &&
|
||||
l[0].Path == localTrack.Path &&
|
||||
l[0].Modified == localTrack.Modified &&
|
||||
l[0].Size == localTrack.Size &&
|
||||
l[0].Quality.Equals(localTrack.Quality) &&
|
||||
l[0].MediaInfo.AudioFormat == localTrack.FileTrackInfo.MediaInfo.AudioFormat
|
||||
)),
|
||||
l[0].MediaInfo.AudioFormat == localTrack.FileTrackInfo.MediaInfo.AudioFormat)),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -9,11 +10,10 @@ using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
@@ -28,7 +28,6 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
Mocker.GetMock<IDownloadedTracksImportService>()
|
||||
.Setup(v => v.ProcessRootFolder(It.IsAny<IDirectoryInfo>()))
|
||||
.Returns(new List<ImportResult>());
|
||||
@@ -47,11 +46,11 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.Build();
|
||||
|
||||
_trackedDownload = new TrackedDownload
|
||||
{
|
||||
DownloadItem = downloadItem,
|
||||
RemoteAlbum = remoteAlbum,
|
||||
State = TrackedDownloadStage.Downloading
|
||||
};
|
||||
{
|
||||
DownloadItem = downloadItem,
|
||||
RemoteAlbum = remoteAlbum,
|
||||
State = TrackedDownloadStage.Downloading
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenExistingFolder(string path)
|
||||
@@ -77,10 +76,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
Assert.Throws<ArgumentException>(() => Subject.Execute(new DownloadedAlbumsScanCommand()));
|
||||
|
||||
Mocker.GetMock<IDownloadedTracksImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<IDirectoryInfo>()), Times.Never());
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_process_folder_if_downloadclientid_is_not_specified()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
@@ -10,13 +12,11 @@ using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.IO;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
@@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void Setup()
|
||||
{
|
||||
GivenAudioFiles(_audioFiles, 10);
|
||||
|
||||
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_audioFiles.Select(x => DiskProvider.GetFileInfo(x)).ToArray());
|
||||
|
||||
@@ -54,12 +54,11 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.Build();
|
||||
|
||||
_trackedDownload = new TrackedDownload
|
||||
|
||||
{
|
||||
DownloadItem = downloadItem,
|
||||
RemoteAlbum = remoteAlbum,
|
||||
State = TrackedDownloadStage.Downloading
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenAudioFiles(string[] files, long filesize)
|
||||
@@ -246,7 +245,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
|
||||
.Returns(imported.Select(i => new ImportResult(i)).ToList());
|
||||
|
||||
GivenAudioFiles(new []{ _audioFiles.First().Replace(".ext", ".rar") }, 15.Megabytes());
|
||||
GivenAudioFiles(new[] { _audioFiles.First().Replace(".ext", ".rar") }, 15.Megabytes());
|
||||
|
||||
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
|
||||
|
||||
@@ -288,7 +287,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
|
||||
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
|
||||
|
||||
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
|
||||
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
|
||||
|
||||
@@ -8,14 +8,14 @@ using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
@@ -59,8 +59,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
|
||||
foreach (var track in tracks)
|
||||
{
|
||||
_approvedDecisions.Add(new ImportDecision<LocalTrack>
|
||||
(
|
||||
_approvedDecisions.Add(new ImportDecision<LocalTrack>(
|
||||
new LocalTrack
|
||||
{
|
||||
Artist = artist,
|
||||
@@ -85,7 +84,6 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesByAlbum(It.IsAny<int>()))
|
||||
.Returns(new List<TrackFile>());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -164,8 +162,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
var fileDecision = _approvedDecisions.First();
|
||||
fileDecision.Item.Size = 1.Gigabytes();
|
||||
|
||||
var sampleDecision = new ImportDecision<LocalTrack>
|
||||
(new LocalTrack
|
||||
var sampleDecision = new ImportDecision<LocalTrack>(
|
||||
new LocalTrack
|
||||
{
|
||||
Artist = fileDecision.Item.Artist,
|
||||
Album = fileDecision.Item.Album,
|
||||
@@ -175,7 +173,6 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
Size = 80.Megabytes()
|
||||
});
|
||||
|
||||
|
||||
var all = new List<ImportDecision<LocalTrack>>();
|
||||
all.Add(fileDecision);
|
||||
all.Add(sampleDecision);
|
||||
@@ -219,6 +216,5 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.Delete(It.IsAny<TrackFile>(), DeleteMediaFileReason.ManualOverride), Times.Once());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@ using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
@@ -14,10 +14,10 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
[TestFixture]
|
||||
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, TrackFile>
|
||||
{
|
||||
private Artist artist;
|
||||
private Album album;
|
||||
private List<AlbumRelease> releases;
|
||||
|
||||
private Artist _artist;
|
||||
private Album _album;
|
||||
private List<AlbumRelease> _releases;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -25,48 +25,48 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.With(a => a.Id = 0)
|
||||
.Build();
|
||||
Db.Insert(meta);
|
||||
|
||||
artist = Builder<Artist>.CreateNew()
|
||||
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
.With(a => a.ArtistMetadataId = meta.Id)
|
||||
.With(a => a.Id = 0)
|
||||
.Build();
|
||||
Db.Insert(artist);
|
||||
Db.Insert(_artist);
|
||||
|
||||
album = Builder<Album>.CreateNew()
|
||||
_album = Builder<Album>.CreateNew()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.ArtistMetadataId = artist.ArtistMetadataId)
|
||||
.With(a => a.ArtistMetadataId = _artist.ArtistMetadataId)
|
||||
.Build();
|
||||
Db.Insert(album);
|
||||
|
||||
releases = Builder<AlbumRelease>.CreateListOfSize(2)
|
||||
Db.Insert(_album);
|
||||
|
||||
_releases = Builder<AlbumRelease>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.AlbumId = album.Id)
|
||||
.With(a => a.AlbumId = _album.Id)
|
||||
.TheFirst(1)
|
||||
.With(a => a.Monitored = true)
|
||||
.TheNext(1)
|
||||
.With(a => a.Monitored = false)
|
||||
.Build().ToList();
|
||||
Db.InsertMany(releases);
|
||||
|
||||
Db.InsertMany(_releases);
|
||||
|
||||
var files = Builder<TrackFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Quality =new QualityModel(Quality.MP3_192))
|
||||
.With(c => c.Quality = new QualityModel(Quality.MP3_192))
|
||||
.TheFirst(5)
|
||||
.With(c => c.AlbumId = album.Id)
|
||||
.With(c => c.AlbumId = _album.Id)
|
||||
.TheFirst(1)
|
||||
.With(c => c.Path = @"C:\Test\Path\Artist\somefile1.flac".AsOsAgnostic())
|
||||
.TheNext(1)
|
||||
.With(c => c.Path = @"C:\Test\Path\Artist\somefile2.flac".AsOsAgnostic())
|
||||
.BuildListOfNew();
|
||||
Db.InsertMany(files);
|
||||
|
||||
|
||||
var track = Builder<Track>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(a => a.Id = 0)
|
||||
.TheFirst(4)
|
||||
.With(a => a.AlbumReleaseId = releases[0].Id)
|
||||
.With(a => a.AlbumReleaseId = _releases[0].Id)
|
||||
.TheFirst(1)
|
||||
.With(a => a.TrackFileId = files[0].Id)
|
||||
.TheNext(1)
|
||||
@@ -77,21 +77,21 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.With(a => a.TrackFileId = files[3].Id)
|
||||
.TheNext(1)
|
||||
.With(a => a.TrackFileId = files[4].Id)
|
||||
.With(a => a.AlbumReleaseId = releases[1].Id)
|
||||
.With(a => a.AlbumReleaseId = _releases[1].Id)
|
||||
.TheNext(5)
|
||||
.With(a => a.TrackFileId = 0)
|
||||
.Build();
|
||||
Db.InsertMany(track);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void get_files_by_artist()
|
||||
{
|
||||
VerifyData();
|
||||
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
||||
var artistFiles = Subject.GetFilesByArtist(_artist.Id);
|
||||
VerifyEagerLoaded(artistFiles);
|
||||
|
||||
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == artist.Id);
|
||||
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == _artist.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -108,8 +108,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_release()
|
||||
{
|
||||
VerifyData();
|
||||
var firstReleaseFiles = Subject.GetFilesByRelease(releases[0].Id);
|
||||
var secondReleaseFiles = Subject.GetFilesByRelease(releases[1].Id);
|
||||
var firstReleaseFiles = Subject.GetFilesByRelease(_releases[0].Id);
|
||||
var secondReleaseFiles = Subject.GetFilesByRelease(_releases[1].Id);
|
||||
VerifyEagerLoaded(firstReleaseFiles);
|
||||
VerifyEagerLoaded(secondReleaseFiles);
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
var files = Builder<TrackFile>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Quality =new QualityModel(Quality.MP3_192))
|
||||
.With(c => c.Quality = new QualityModel(Quality.MP3_192))
|
||||
.TheFirst(1)
|
||||
.With(c => c.Path = @"C:\Test\Path2\Artist\somefile1.flac".AsOsAgnostic())
|
||||
.TheNext(1)
|
||||
@@ -169,7 +169,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_artist_should_only_return_tracks_for_monitored_releases()
|
||||
{
|
||||
VerifyData();
|
||||
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
||||
var artistFiles = Subject.GetFilesByArtist(_artist.Id);
|
||||
VerifyEagerLoaded(artistFiles);
|
||||
|
||||
artistFiles.Should().HaveCount(4);
|
||||
@@ -179,19 +179,19 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_album()
|
||||
{
|
||||
VerifyData();
|
||||
var files = Subject.GetFilesByAlbum(album.Id);
|
||||
var files = Subject.GetFilesByAlbum(_album.Id);
|
||||
VerifyEagerLoaded(files);
|
||||
|
||||
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
||||
files.Should().OnlyContain(c => c.AlbumId == _album.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_files_by_album_should_only_return_tracks_for_monitored_releases()
|
||||
{
|
||||
VerifyData();
|
||||
var files = Subject.GetFilesByAlbum(album.Id);
|
||||
var files = Subject.GetFilesByAlbum(_album.Id);
|
||||
VerifyEagerLoaded(files);
|
||||
|
||||
|
||||
files.Should().HaveCount(4);
|
||||
}
|
||||
|
||||
@@ -236,10 +236,10 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
[Test]
|
||||
public void delete_files_by_album_should_work_if_join_fails()
|
||||
{
|
||||
Db.Delete(album);
|
||||
Subject.DeleteFilesByAlbum(album.Id);
|
||||
|
||||
Db.All<TrackFile>().Where(x => x.AlbumId == album.Id).Should().HaveCount(0);
|
||||
Db.Delete(_album);
|
||||
Subject.DeleteFilesByAlbum(_album.Id);
|
||||
|
||||
Db.All<TrackFile>().Where(x => x.AlbumId == _album.Id).Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.IO.Abstractions;
|
||||
using System;
|
||||
using FizzWare.NBuilder;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
{
|
||||
@@ -24,10 +24,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
public void Setup()
|
||||
{
|
||||
_artist = new Artist
|
||||
{
|
||||
Id = 10,
|
||||
Path = @"C:\".AsOsAgnostic()
|
||||
};
|
||||
{
|
||||
Id = 10,
|
||||
Path = @"C:\".AsOsAgnostic()
|
||||
};
|
||||
}
|
||||
|
||||
private List<IFileInfo> GivenFiles(string[] files)
|
||||
@@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
{
|
||||
FileSystem.AddFile(file, new MockFileData(string.Empty) { LastWriteTime = _lastWrite });
|
||||
}
|
||||
|
||||
|
||||
return files.Select(x => DiskProvider.GetFileInfo(x)).ToList();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_return_all_files_if_no_existing_files(FilterFilesType filter)
|
||||
{
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\file1.avi".AsOsAgnostic(),
|
||||
"C:\\file2.avi".AsOsAgnostic(),
|
||||
@@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_return_nothing_if_all_files_exist(FilterFilesType filter)
|
||||
{
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\file1.avi".AsOsAgnostic(),
|
||||
"C:\\file2.avi".AsOsAgnostic(),
|
||||
@@ -71,10 +71,11 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(files.Select(f => new TrackFile {
|
||||
Path = f.FullName,
|
||||
Modified = _lastWrite
|
||||
}).ToList());
|
||||
.Returns(files.Select(f => new TrackFile
|
||||
{
|
||||
Path = f.FullName,
|
||||
Modified = _lastWrite
|
||||
}).ToList());
|
||||
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Should().BeEmpty();
|
||||
}
|
||||
@@ -83,7 +84,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_not_return_existing_files(FilterFilesType filter)
|
||||
{
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\file1.avi".AsOsAgnostic(),
|
||||
"C:\\file2.avi".AsOsAgnostic(),
|
||||
@@ -94,7 +95,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Modified = _lastWrite
|
||||
}
|
||||
@@ -110,7 +112,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\file1.avi".AsOsAgnostic(),
|
||||
"C:\\FILE2.avi".AsOsAgnostic(),
|
||||
@@ -121,25 +123,24 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Modified = _lastWrite
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(2);
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Select(x => x.FullName).Should().NotContain("C:\\file2.avi".AsOsAgnostic());
|
||||
}
|
||||
|
||||
|
||||
[TestCase(FilterFilesType.Known)]
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_return_none_existing_files_not_ignoring_case(FilterFilesType filter)
|
||||
{
|
||||
PosixOnly();
|
||||
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\file1.avi".AsOsAgnostic(),
|
||||
"C:\\FILE2.avi".AsOsAgnostic(),
|
||||
@@ -150,7 +151,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Modified = _lastWrite
|
||||
}
|
||||
@@ -163,7 +165,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_not_change_casing(FilterFilesType filter)
|
||||
{
|
||||
var files = GivenFiles(new []
|
||||
var files = GivenFiles(new[]
|
||||
{
|
||||
"C:\\FILE1.avi".AsOsAgnostic()
|
||||
});
|
||||
@@ -177,7 +179,6 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Should().Contain(files.First());
|
||||
}
|
||||
|
||||
|
||||
[TestCase(FilterFilesType.Known)]
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_should_not_return_existing_file_if_size_unchanged(FilterFilesType filter)
|
||||
@@ -192,7 +193,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Size = 10,
|
||||
Modified = _lastWrite
|
||||
@@ -216,7 +218,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Size = 10,
|
||||
Modified = _lastWrite,
|
||||
@@ -227,7 +230,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(3);
|
||||
Subject.FilterUnchangedFiles(files, _artist, filter).Select(x => x.FullName).Should().Contain("C:\\file2.avi".AsOsAgnostic());
|
||||
}
|
||||
|
||||
|
||||
[TestCase(FilterFilesType.Matched)]
|
||||
public void filter_unmatched_should_not_return_existing_file_if_matched(FilterFilesType filter)
|
||||
{
|
||||
@@ -241,7 +244,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Size = 10,
|
||||
Modified = _lastWrite,
|
||||
@@ -267,7 +271,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
|
||||
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>
|
||||
{
|
||||
new TrackFile{
|
||||
new TrackFile
|
||||
{
|
||||
Path = "C:\\file2.avi".AsOsAgnostic(),
|
||||
Size = 10,
|
||||
Modified = _lastWrite
|
||||
|
||||
@@ -5,8 +5,8 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackFileMovingServiceTests
|
||||
{
|
||||
@@ -61,6 +61,5 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackFileMovingServiceTests
|
||||
|
||||
VerifyEventPublished<TrackFileAddedEvent>(Times.Once());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
public class MediaFileTableCleanupServiceFixture : CoreTest<MediaFileTableCleanupService>
|
||||
{
|
||||
private readonly string DELETED_PATH = @"c:\ANY FILE STARTING WITH THIS PATH IS CONSIDERED DELETED!".AsOsAgnostic();
|
||||
private readonly string _deletedPath = @"c:\ANY FILE STARTING WITH THIS PATH IS CONSIDERED DELETED!".AsOsAgnostic();
|
||||
private List<Track> _tracks;
|
||||
private Artist _artist;
|
||||
|
||||
@@ -76,15 +75,15 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.All()
|
||||
.With(x => x.Path = Path.Combine(@"c:\test".AsOsAgnostic(), Path.GetRandomFileName()))
|
||||
.Random(2)
|
||||
.With(c => c.Path = Path.Combine(DELETED_PATH, Path.GetRandomFileName()))
|
||||
.With(c => c.Path = Path.Combine(_deletedPath, Path.GetRandomFileName()))
|
||||
.Build();
|
||||
|
||||
GivenTrackFiles(trackFiles);
|
||||
|
||||
Subject.Clean(_artist, FilesOnDisk(trackFiles.Where(e => !e.Path.StartsWith(DELETED_PATH))));
|
||||
Subject.Clean(_artist, FilesOnDisk(trackFiles.Where(e => !e.Path.StartsWith(_deletedPath))));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(c => c.DeleteMany(It.Is<List<TrackFile>>(e => e.Count == 2 && e.All(y => y.Path.StartsWith(DELETED_PATH))), DeleteMediaFileReason.MissingFromDisk), Times.Once());
|
||||
.Verify(c => c.DeleteMany(It.Is<List<TrackFile>>(e => e.Count == 2 && e.All(y => y.Path.StartsWith(_deletedPath))), DeleteMediaFileReason.MissingFromDisk), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -7,8 +7,8 @@ using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
@@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
private Artist _artist;
|
||||
private List<TrackFile> _trackFiles;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
GivenNoTrackFiles();
|
||||
|
||||
Subject.Execute(new RenameFilesCommand(_artist.Id, new List<int>{1}));
|
||||
Subject.Execute(new RenameFilesCommand(_artist.Id, new List<int> { 1 }));
|
||||
|
||||
Mocker.GetMock<IEventAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<ArtistRenamedEvent>()), Times.Never());
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
@@ -9,12 +10,11 @@ using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.IO;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackFileMovingServiceTests
|
||||
{
|
||||
|
||||
+56
-52
@@ -1,30 +1,30 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation.Aggregators;
|
||||
using FluentAssertions;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation.Aggregators;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
{
|
||||
[TestFixture]
|
||||
public class AggregateFilenameInfoFixture : CoreTest<AggregateFilenameInfo>
|
||||
{
|
||||
|
||||
private LocalAlbumRelease GivenTracks(List<string> files, string root)
|
||||
{
|
||||
var tracks = files.Select(x => new LocalTrack {
|
||||
Path = Path.Combine(root, x),
|
||||
FileTrackInfo = new ParsedTrackInfo {
|
||||
TrackNumbers = new [] { 0 },
|
||||
}
|
||||
}).ToList();
|
||||
var tracks = files.Select(x => new LocalTrack
|
||||
{
|
||||
Path = Path.Combine(root, x),
|
||||
FileTrackInfo = new ParsedTrackInfo
|
||||
{
|
||||
TrackNumbers = new[] { 0 },
|
||||
}
|
||||
}).ToList();
|
||||
return new LocalAlbumRelease(tracks);
|
||||
}
|
||||
|
||||
@@ -39,12 +39,13 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
[Test]
|
||||
public void should_aggregate_filenames_example()
|
||||
{
|
||||
var release = GivenTracks(new List<string> {
|
||||
var release = GivenTracks(new List<string>
|
||||
{
|
||||
"Adele - 19 - 101 - Daydreamer.mp3",
|
||||
"Adele - 19 - 102 - Best for Last.mp3",
|
||||
"Adele - 19 - 103 - Chasing Pavements.mp3",
|
||||
"Adele - 19 - 203 - That's It, I Quit, I'm Moving On.mp3"
|
||||
}, @"C:\incoming".AsOsAgnostic());
|
||||
}, @"C:\incoming".AsOsAgnostic());
|
||||
|
||||
Subject.Aggregate(release, true);
|
||||
|
||||
@@ -56,49 +57,51 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
|
||||
public static class TestCaseFactory
|
||||
{
|
||||
private static List<string[]> tokenList = new List<string[]> {
|
||||
private static List<string[]> tokenList = new List<string[]>
|
||||
{
|
||||
new[] { "trackNum2", "artist", "title", "tag" },
|
||||
new[] { "trackNum3", "artist", "title", "tag" },
|
||||
new[] { "trackNum2", "artist", "tag", "title" },
|
||||
new[] { "trackNum3", "artist", "tag", "title" },
|
||||
new[] { "trackNum2", "artist", "title" },
|
||||
new[] { "trackNum3", "artist", "title" },
|
||||
|
||||
new [] {"trackNum2", "artist", "title", "tag"},
|
||||
new [] {"trackNum3", "artist", "title", "tag"},
|
||||
new [] {"trackNum2", "artist", "tag", "title"},
|
||||
new [] {"trackNum3", "artist", "tag", "title"},
|
||||
new [] {"trackNum2", "artist", "title"},
|
||||
new [] {"trackNum3", "artist", "title"},
|
||||
new[] { "artist", "tag", "trackNum2", "title" },
|
||||
new[] { "artist", "tag", "trackNum3", "title" },
|
||||
new[] { "artist", "trackNum2", "title", "tag" },
|
||||
new[] { "artist", "trackNum3", "title", "tag" },
|
||||
new[] { "artist", "trackNum2", "title" },
|
||||
new[] { "artist", "trackNum3", "title" },
|
||||
|
||||
new [] {"artist", "tag", "trackNum2", "title"},
|
||||
new [] {"artist", "tag", "trackNum3", "title"},
|
||||
new [] {"artist", "trackNum2", "title", "tag"},
|
||||
new [] {"artist", "trackNum3", "title", "tag"},
|
||||
new [] {"artist", "trackNum2", "title"},
|
||||
new [] {"artist", "trackNum3", "title"},
|
||||
new[] { "artist", "title", "tag" },
|
||||
new[] { "artist", "tag", "title" },
|
||||
new[] { "artist", "title" },
|
||||
|
||||
new [] {"artist", "title", "tag"},
|
||||
new [] {"artist", "tag", "title"},
|
||||
new [] {"artist", "title"},
|
||||
new[] { "trackNum2", "title" },
|
||||
new[] { "trackNum3", "title" },
|
||||
|
||||
new [] {"trackNum2", "title"},
|
||||
new [] {"trackNum3", "title"},
|
||||
|
||||
new [] {"title"},
|
||||
new[] { "title" },
|
||||
};
|
||||
|
||||
private static List<Tuple<string, string>> separators = new List<Tuple<string, string>> {
|
||||
private static List<Tuple<string, string>> separators = new List<Tuple<string, string>>
|
||||
{
|
||||
Tuple.Create(" - ", " "),
|
||||
Tuple.Create("_", " "),
|
||||
Tuple.Create("-", "_")
|
||||
};
|
||||
|
||||
private static List<Tuple<string[], string, string>> otherCases = new List<Tuple<string[], string, string>> {
|
||||
Tuple.Create(new [] {"track2", "title"}, " ", " "),
|
||||
Tuple.Create(new [] {"track3", "title"}, " ", " ")
|
||||
private static List<Tuple<string[], string, string>> otherCases = new List<Tuple<string[], string, string>>
|
||||
{
|
||||
Tuple.Create(new[] { "track2", "title" }, " ", " "),
|
||||
Tuple.Create(new[] { "track3", "title" }, " ", " ")
|
||||
};
|
||||
|
||||
|
||||
public static IEnumerable TestCases
|
||||
{
|
||||
get
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
foreach (var tokens in tokenList)
|
||||
{
|
||||
foreach (var separator in separators)
|
||||
@@ -130,7 +133,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
var components = new List<string>();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch(field)
|
||||
switch (field)
|
||||
{
|
||||
case "artist":
|
||||
components.Add("artist name".Replace(" ", whitespace));
|
||||
@@ -139,7 +142,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
components.Add("tag string ignore".Replace(" ", whitespace));
|
||||
break;
|
||||
case "title":
|
||||
components.Add($"{(char)(96+i)} track title {i}".Replace(" ", whitespace));
|
||||
components.Add($"{(char)(96 + i)} track title {i}".Replace(" ", whitespace));
|
||||
break;
|
||||
case "trackNum2":
|
||||
components.Add(i.ToString("00"));
|
||||
@@ -149,6 +152,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outp.Add(string.Join(fieldSeparator, components) + ".mp3");
|
||||
}
|
||||
|
||||
@@ -159,7 +163,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
{
|
||||
for (int i = 1; i <= tracks.Count; i++)
|
||||
{
|
||||
var info = tracks[i-1].FileTrackInfo;
|
||||
var info = tracks[i - 1].FileTrackInfo;
|
||||
|
||||
if (tokens.Contains("artist"))
|
||||
{
|
||||
@@ -168,7 +172,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
|
||||
if (tokens.Contains("title"))
|
||||
{
|
||||
info.Title.Should().Be($"{(char)(96+i)} track title {i}".Replace(" ", whitespace));
|
||||
info.Title.Should().Be($"{(char)(96 + i)} track title {i}".Replace(" ", whitespace));
|
||||
}
|
||||
|
||||
if (tokens.Contains("trackNum2") || tokens.Contains("trackNum3"))
|
||||
@@ -186,8 +190,9 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestCaseFactory), "TestCases")]
|
||||
public void should_aggregate_filenames_auto(Tuple<string[], string, string> testcase)
|
||||
{
|
||||
var files = GivenFilenames(testcase.Item1, testcase.Item2, testcase.Item3);
|
||||
@@ -197,6 +202,5 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Aggregation.Aggregators
|
||||
|
||||
VerifyDataAuto(release.LocalTracks, testcase.Item1, testcase.Item3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+25
-26
@@ -1,41 +1,40 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
[TestFixture]
|
||||
public class AlbumDistanceFixture : CoreTest<IdentificationService>
|
||||
{
|
||||
|
||||
private ArtistMetadata artist;
|
||||
private ArtistMetadata _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
artist = Builder<ArtistMetadata>
|
||||
_artist = Builder<ArtistMetadata>
|
||||
.CreateNew()
|
||||
.With(x => x.Name = "artist")
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
private List<Track> GivenTracks(int count)
|
||||
{
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.With(x => x.MediumNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.With(x => x.MediumNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private LocalTrack GivenLocalTrack(Track track, AlbumRelease release)
|
||||
@@ -56,7 +55,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.With(x => x.Label = release.Label.First())
|
||||
.With(x => x.Year = (uint)(release.Album.Value.ReleaseDate?.Year ?? 0))
|
||||
.Build();
|
||||
|
||||
|
||||
var localTrack = Builder<LocalTrack>
|
||||
.CreateNew()
|
||||
.With(x => x.FileTrackInfo = fileInfo)
|
||||
@@ -72,6 +71,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
output.Add(GivenLocalTrack(track, release));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var album = Builder<Album>
|
||||
.CreateNew()
|
||||
.With(x => x.Title = title)
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.Build();
|
||||
|
||||
var media = Builder<Medium>
|
||||
@@ -109,7 +109,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void test_identical_albums()
|
||||
{
|
||||
@@ -142,7 +142,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var release = GivenAlbumRelease("album", tracks);
|
||||
var localTracks = GivenLocalTracks(tracks, release);
|
||||
var mapping = GivenMapping(localTracks, tracks);
|
||||
|
||||
|
||||
release.Album.Value.ArtistMetadata = Builder<ArtistMetadata>
|
||||
.CreateNew()
|
||||
.With(x => x.Name = "different artist")
|
||||
@@ -164,19 +164,18 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.With(x => x.Name = "Various Artists")
|
||||
.With(x => x.ForeignArtistId = "89ad4ac3-39f7-470e-963a-56509c546377")
|
||||
.Build();
|
||||
|
||||
|
||||
Subject.AlbumReleaseDistance(localTracks, release, mapping).NormalizedDistance().Should().Be(0.0);
|
||||
}
|
||||
|
||||
// TODO: there are a couple more VA tests in beets but we don't support VA yet anyway
|
||||
|
||||
[Test]
|
||||
public void test_tracks_out_of_order()
|
||||
{
|
||||
var tracks = GivenTracks(3);
|
||||
var release = GivenAlbumRelease("album", tracks);
|
||||
var localTracks = GivenLocalTracks(tracks, release);
|
||||
localTracks = new [] {1, 3, 2}.Select(x => localTracks[x-1]).ToList();
|
||||
localTracks = new[] { 1, 3, 2 }.Select(x => localTracks[x - 1]).ToList();
|
||||
var mapping = GivenMapping(localTracks, tracks);
|
||||
|
||||
var dist = Subject.AlbumReleaseDistance(localTracks, release, mapping);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Test.Common;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.Add("add", 1.0);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"add", new List<double> { 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "add", new List<double> { 1.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -22,13 +22,13 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddEquality("equality", "ghi", new List<string> { "abc", "def", "ghi" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"equality", new List<double> { 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "equality", new List<double> { 0.0 } } });
|
||||
|
||||
dist.AddEquality("equality", "xyz", new List<string> { "abc", "def", "ghi" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"equality", new List<double> { 0.0, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "equality", new List<double> { 0.0, 1.0 } } });
|
||||
|
||||
dist.AddEquality("equality", "abc", new List<string> { "abc", "def", "ghi" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"equality", new List<double> { 0.0, 1.0, 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "equality", new List<double> { 0.0, 1.0, 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -36,10 +36,10 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddBool("expr", true);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"expr", new List<double> { 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "expr", new List<double> { 1.0 } } });
|
||||
|
||||
dist.AddBool("expr", false);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"expr", new List<double> { 1.0, 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "expr", new List<double> { 1.0, 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -47,16 +47,16 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddNumber("number", 1, 1);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"number", new List<double> { 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "number", new List<double> { 0.0 } } });
|
||||
|
||||
dist.AddNumber("number", 1, 2);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"number", new List<double> { 0.0, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "number", new List<double> { 0.0, 1.0 } } });
|
||||
|
||||
dist.AddNumber("number", 2, 1);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"number", new List<double> { 0.0, 1.0, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "number", new List<double> { 0.0, 1.0, 1.0 } } });
|
||||
|
||||
dist.AddNumber("number", -1, 2);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"number", new List<double> { 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "number", new List<double> { 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -64,13 +64,13 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddPriority("priority", "abc", new List<string> { "abc" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0 } } });
|
||||
|
||||
dist.AddPriority("priority", "def", new List<string> { "abc", "def" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0, 0.5 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0, 0.5 } } });
|
||||
|
||||
dist.AddPriority("priority", "xyz", new List<string> { "abc", "def" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0, 0.5, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0, 0.5, 1.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -78,16 +78,16 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddPriority("priority", new List<string> { "abc" }, new List<string> { "abc" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0 } } });
|
||||
|
||||
dist.AddPriority("priority", new List<string> { "def" }, new List<string> { "abc" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0, 1.0 } } });
|
||||
|
||||
dist.AddPriority("priority", new List<string> { "abc", "xyz" }, new List<string> { "abc" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0, 1.0, 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0, 1.0, 0.0 } } });
|
||||
|
||||
dist.AddPriority("priority", new List<string> { "def", "xyz" }, new List<string> { "abc", "def" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"priority", new List<double> { 0.0, 1.0, 0.0, 0.5 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "priority", new List<double> { 0.0, 1.0, 0.0, 0.5 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -95,16 +95,16 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddRatio("ratio", 25, 100);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"ratio", new List<double> { 0.25 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "ratio", new List<double> { 0.25 } } });
|
||||
|
||||
dist.AddRatio("ratio", 10, 5);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"ratio", new List<double> { 0.25, 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "ratio", new List<double> { 0.25, 1.0 } } });
|
||||
|
||||
dist.AddRatio("ratio", -5, 5);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"ratio", new List<double> { 0.25, 1.0, 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "ratio", new List<double> { 0.25, 1.0, 0.0 } } });
|
||||
|
||||
dist.AddRatio("ratio", 5, 0);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"ratio", new List<double> { 0.25, 1.0, 0.0, 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "ratio", new List<double> { 0.25, 1.0, 0.0, 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddString("string", "abcd", "bcde");
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"string", new List<double> { 0.5 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.5 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -120,15 +120,15 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddString("string", string.Empty, "bcd");
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"string", new List<double> { 1.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void test_add_string_both_none()
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddString("string", string.Empty, string.Empty);
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { {"string", new List<double> { 0.0 }}} );
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
+27
-30
@@ -1,42 +1,39 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Music;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetCandidatesFixture : CoreTest<IdentificationService>
|
||||
{
|
||||
|
||||
private ArtistMetadata artist;
|
||||
private ArtistMetadata _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
artist = Builder<ArtistMetadata>
|
||||
_artist = Builder<ArtistMetadata>
|
||||
.CreateNew()
|
||||
.With(x => x.Name = "artist")
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
private List<Track> GivenTracks(int count)
|
||||
{
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.Build()
|
||||
.ToList();
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private ParsedTrackInfo GivenParsedTrackInfo(Track track, AlbumRelease release)
|
||||
@@ -76,7 +73,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var album = Builder<Album>
|
||||
.CreateNew()
|
||||
.With(x => x.Title = title)
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.Build();
|
||||
|
||||
var media = Builder<Medium>
|
||||
@@ -110,11 +107,13 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
Mocker.GetMock<IFingerprintingService>()
|
||||
.Setup(x => x.Lookup(It.IsAny<List<LocalTrack>>(), It.IsAny<double>()))
|
||||
.Callback((List<LocalTrack> x, double thres) => {
|
||||
foreach(var track in x) {
|
||||
track.AcoustIdResults = null;
|
||||
}
|
||||
});
|
||||
.Callback((List<LocalTrack> x, double thres) =>
|
||||
{
|
||||
foreach (var track in x)
|
||||
{
|
||||
track.AcoustIdResults = null;
|
||||
}
|
||||
});
|
||||
|
||||
Mocker.GetMock<IReleaseService>()
|
||||
.Setup(x => x.GetReleasesByRecordingIds(It.IsAny<List<string>>()))
|
||||
@@ -134,8 +133,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var localAlbumRelease = new LocalAlbumRelease(localTracks);
|
||||
|
||||
Subject.GetCandidatesFromTags(localAlbumRelease, null, null, release, false).Should().BeEquivalentTo(
|
||||
new List<CandidateAlbumRelease> { new CandidateAlbumRelease(release) }
|
||||
);
|
||||
new List<CandidateAlbumRelease> { new CandidateAlbumRelease(release) });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -152,8 +150,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.Returns(release);
|
||||
|
||||
Subject.GetCandidatesFromTags(localAlbumRelease, null, null, null, false).Should().BeEquivalentTo(
|
||||
new List<CandidateAlbumRelease> { new CandidateAlbumRelease(release) }
|
||||
);
|
||||
new List<CandidateAlbumRelease> { new CandidateAlbumRelease(release) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
-31
@@ -1,27 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using FluentAssertions;
|
||||
using FluentValidation.Results;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation.Aggregators;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation.Aggregators;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
@@ -32,13 +32,13 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
private AddArtistService _addArtistService;
|
||||
private RefreshArtistService _refreshArtistService;
|
||||
|
||||
private IdentificationService Subject;
|
||||
|
||||
private IdentificationService _subject;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
|
||||
// Resolve all the parts we need
|
||||
Mocker.SetConstant<IArtistRepository>(Mocker.Resolve<ArtistRepository>());
|
||||
Mocker.SetConstant<IArtistMetadataRepository>(Mocker.Resolve<ArtistMetadataRepository>());
|
||||
@@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
Mocker.SetConstant<IConfigService>(Mocker.Resolve<IConfigService>());
|
||||
Mocker.SetConstant<IProvideArtistInfo>(Mocker.Resolve<SkyHookProxy>());
|
||||
Mocker.SetConstant<IProvideAlbumInfo>(Mocker.Resolve<SkyHookProxy>());
|
||||
|
||||
|
||||
_addArtistService = Mocker.Resolve<AddArtistService>();
|
||||
|
||||
Mocker.SetConstant<IRefreshTrackService>(Mocker.Resolve<RefreshTrackService>());
|
||||
@@ -71,14 +71,14 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
Mocker.SetConstant<ITrackGroupingService>(Mocker.Resolve<TrackGroupingService>());
|
||||
|
||||
// set up the augmenters
|
||||
List<IAggregate<LocalAlbumRelease>> aggregators = new List<IAggregate<LocalAlbumRelease>> {
|
||||
List<IAggregate<LocalAlbumRelease>> aggregators = new List<IAggregate<LocalAlbumRelease>>
|
||||
{
|
||||
Mocker.Resolve<AggregateFilenameInfo>()
|
||||
};
|
||||
Mocker.SetConstant<IEnumerable<IAggregate<LocalAlbumRelease>>>(aggregators);
|
||||
Mocker.SetConstant<IAugmentingService>(Mocker.Resolve<AugmentingService>());
|
||||
|
||||
Subject = Mocker.Resolve<IdentificationService>();
|
||||
|
||||
_subject = Mocker.Resolve<IdentificationService>();
|
||||
}
|
||||
|
||||
private void GivenMetadataProfile(MetadataProfile profile)
|
||||
@@ -102,15 +102,18 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
private Artist GivenArtist(string foreignArtistId, int metadataProfileId)
|
||||
{
|
||||
var artist = _addArtistService.AddArtist(new Artist {
|
||||
Metadata = new ArtistMetadata {
|
||||
ForeignArtistId = foreignArtistId
|
||||
},
|
||||
Path = @"c:\test".AsOsAgnostic(),
|
||||
MetadataProfileId = metadataProfileId
|
||||
});
|
||||
var artist = _addArtistService.AddArtist(new Artist
|
||||
{
|
||||
Metadata = new ArtistMetadata
|
||||
{
|
||||
ForeignArtistId = foreignArtistId
|
||||
},
|
||||
Path = @"c:\test".AsOsAgnostic(),
|
||||
MetadataProfileId = metadataProfileId
|
||||
});
|
||||
|
||||
var command = new RefreshArtistCommand{
|
||||
var command = new RefreshArtistCommand
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
Trigger = CommandTrigger.Unspecified
|
||||
};
|
||||
@@ -127,15 +130,17 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
Mocker.GetMock<IFingerprintingService>()
|
||||
.Setup(x => x.Lookup(It.IsAny<List<LocalTrack>>(), It.IsAny<double>()))
|
||||
.Callback((List<LocalTrack> track, double thres) => {
|
||||
track.ForEach(x => x.AcoustIdResults = fingerprints.SingleOrDefault(f => f.Path == x.Path).AcoustIdResults);
|
||||
});
|
||||
.Callback((List<LocalTrack> track, double thres) =>
|
||||
{
|
||||
track.ForEach(x => x.AcoustIdResults = fingerprints.SingleOrDefault(f => f.Path == x.Path).AcoustIdResults);
|
||||
});
|
||||
}
|
||||
|
||||
public static class IdTestCaseFactory
|
||||
{
|
||||
// for some reason using Directory.GetFiles causes nUnit to error
|
||||
private static string[] files = {
|
||||
private static string[] files =
|
||||
{
|
||||
"FilesWithMBIds.json",
|
||||
"PreferMissingToBadMatch.json",
|
||||
"InconsistentTyposInAlbum.json",
|
||||
@@ -159,7 +164,8 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
// these are slow to run so only do so manually
|
||||
[Explicit]
|
||||
[Test, TestCaseSource(typeof(IdTestCaseFactory), "TestCases")]
|
||||
[Test]
|
||||
[TestCaseSource(typeof(IdTestCaseFactory), "TestCases")]
|
||||
public void should_match_tracks(string file)
|
||||
{
|
||||
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Identification", file);
|
||||
@@ -168,17 +174,18 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var artists = GivenArtists(testcase.LibraryArtists);
|
||||
var specifiedArtist = artists.SingleOrDefault(x => x.Metadata.Value.ForeignArtistId == testcase.Artist);
|
||||
|
||||
var tracks = testcase.Tracks.Select(x => new LocalTrack {
|
||||
Path = x.Path.AsOsAgnostic(),
|
||||
FileTrackInfo = x.FileTrackInfo
|
||||
}).ToList();
|
||||
var tracks = testcase.Tracks.Select(x => new LocalTrack
|
||||
{
|
||||
Path = x.Path.AsOsAgnostic(),
|
||||
FileTrackInfo = x.FileTrackInfo
|
||||
}).ToList();
|
||||
|
||||
if (testcase.Fingerprints != null)
|
||||
{
|
||||
GivenFingerprints(testcase.Fingerprints);
|
||||
}
|
||||
|
||||
var result = Subject.Identify(tracks, specifiedArtist, null, null, testcase.NewDownload, testcase.SingleRelease, false);
|
||||
var result = _subject.Identify(tracks, specifiedArtist, null, null, testcase.NewDownload, testcase.SingleRelease, false);
|
||||
|
||||
TestLogger.Debug($"Found releases:\n{result.Where(x => x.AlbumRelease != null).Select(x => x.AlbumRelease?.ForeignReleaseId).ToJson()}");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Test.Common;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
@@ -15,170 +15,178 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
m.Run();
|
||||
m.Cost.Should().Be(expectedCost);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void MunkresSquareTest1()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 2, 4, 6 },
|
||||
{ 3, 6, 9 }
|
||||
};
|
||||
|
||||
RunTest(C, 10);
|
||||
|
||||
RunTest(c, 10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresSquareTest2()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 400, 150, 400 },
|
||||
{ 400, 450, 600 },
|
||||
{ 300, 225, 300 }
|
||||
};
|
||||
|
||||
RunTest(C, 850);
|
||||
RunTest(c, 850);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresSquareTest3()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 10, 10, 8 },
|
||||
{ 9, 8, 1 },
|
||||
{ 9, 7, 4 }
|
||||
};
|
||||
|
||||
RunTest(C, 18);
|
||||
RunTest(c, 18);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresSquareTest4()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 5, 9, 1 },
|
||||
{ 10, 3, 2 },
|
||||
{ 8, 7, 4 }
|
||||
};
|
||||
|
||||
RunTest(C, 12);
|
||||
RunTest(c, 12);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresSquareTest5()
|
||||
{
|
||||
var C = new double[,] {
|
||||
{12, 26, 17, 0, 0},
|
||||
{49, 43, 36, 10, 5},
|
||||
{97, 9, 66, 34, 0},
|
||||
{52, 42, 19, 36, 0},
|
||||
{15, 93, 55, 80, 0}
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 12, 26, 17, 0, 0 },
|
||||
{ 49, 43, 36, 10, 5 },
|
||||
{ 97, 9, 66, 34, 0 },
|
||||
{ 52, 42, 19, 36, 0 },
|
||||
{ 15, 93, 55, 80, 0 }
|
||||
};
|
||||
|
||||
RunTest(C, 48);
|
||||
RunTest(c, 48);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Munkres5x5Test()
|
||||
{
|
||||
var C = new double[,] {
|
||||
{12, 9, 27, 10, 23},
|
||||
{7, 13, 13, 30, 19},
|
||||
{25, 18, 26, 11, 26},
|
||||
{9, 28, 26, 23, 13},
|
||||
{16, 16, 24, 6, 9}
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 12, 9, 27, 10, 23 },
|
||||
{ 7, 13, 13, 30, 19 },
|
||||
{ 25, 18, 26, 11, 26 },
|
||||
{ 9, 28, 26, 23, 13 },
|
||||
{ 16, 16, 24, 6, 9 }
|
||||
};
|
||||
|
||||
RunTest(C, 51);
|
||||
RunTest(c, 51);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Munkres10x10Test()
|
||||
{
|
||||
var C = new double[,] {
|
||||
{37, 34, 29, 26, 19, 8, 9, 23, 19, 29},
|
||||
{9, 28, 20, 8, 18, 20, 14, 33, 23, 14},
|
||||
{15, 26, 12, 28, 6, 17, 9, 13, 21, 7},
|
||||
{2, 8, 38, 36, 39, 5, 36, 2, 38, 27},
|
||||
{30, 3, 33, 16, 21, 39, 7, 23, 28, 36},
|
||||
{7, 5, 19, 22, 36, 36, 24, 19, 30, 2},
|
||||
{34, 20, 13, 36, 12, 33, 9, 10, 23, 5},
|
||||
{7, 37, 22, 39, 33, 39, 10, 3, 13, 26},
|
||||
{21, 25, 23, 39, 31, 37, 32, 33, 38, 1},
|
||||
{17, 34, 40, 10, 29, 37, 40, 3, 25, 3}
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 37, 34, 29, 26, 19, 8, 9, 23, 19, 29 },
|
||||
{ 9, 28, 20, 8, 18, 20, 14, 33, 23, 14 },
|
||||
{ 15, 26, 12, 28, 6, 17, 9, 13, 21, 7 },
|
||||
{ 2, 8, 38, 36, 39, 5, 36, 2, 38, 27 },
|
||||
{ 30, 3, 33, 16, 21, 39, 7, 23, 28, 36 },
|
||||
{ 7, 5, 19, 22, 36, 36, 24, 19, 30, 2 },
|
||||
{ 34, 20, 13, 36, 12, 33, 9, 10, 23, 5 },
|
||||
{ 7, 37, 22, 39, 33, 39, 10, 3, 13, 26 },
|
||||
{ 21, 25, 23, 39, 31, 37, 32, 33, 38, 1 },
|
||||
{ 17, 34, 40, 10, 29, 37, 40, 3, 25, 3 }
|
||||
};
|
||||
|
||||
RunTest(C, 66);
|
||||
RunTest(c, 66);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Munkres20x20Test()
|
||||
{
|
||||
var C = new double[,] {
|
||||
{5, 4, 3, 9, 8, 9, 3, 5, 6, 9, 4, 10, 3, 5, 6, 6, 1, 8, 10, 2},
|
||||
{10, 9, 9, 2, 8, 3, 9, 9, 10, 1, 7, 10, 8, 4, 2, 1, 4, 8, 4, 8},
|
||||
{10, 4, 4, 3, 1, 3, 5, 10, 6, 8, 6, 8, 4, 10, 7, 2, 4, 5, 1, 8},
|
||||
{2, 1, 4, 2, 3, 9, 3, 4, 7, 3, 4, 1, 3, 2, 9, 8, 6, 5, 7, 8},
|
||||
{3, 4, 4, 1, 4, 10, 1, 2, 6, 4, 5, 10, 2, 2, 3, 9, 10, 9, 9, 10},
|
||||
{1, 10, 1, 8, 1, 3, 1, 7, 1, 1, 2, 1, 2, 6, 3, 3, 4, 4, 8, 6},
|
||||
{1, 8, 7, 10, 10, 3, 4, 6, 1, 6, 6, 4, 9, 6, 9, 6, 4, 5, 4, 7},
|
||||
{8, 10, 3, 9, 4, 9, 3, 3, 4, 6, 4, 2, 6, 7, 7, 4, 4, 3, 4, 7},
|
||||
{1, 3, 8, 2, 6, 9, 2, 7, 4, 8, 10, 8, 10, 5, 1, 3, 10, 10, 2, 9},
|
||||
{2, 4, 1, 9, 2, 9, 7, 8, 2, 1, 4, 10, 5, 2, 7, 6, 5, 7, 2, 6},
|
||||
{4, 5, 1, 4, 2, 3, 3, 4, 1, 8, 8, 2, 6, 9, 5, 9, 6, 3, 9, 3},
|
||||
{3, 1, 1, 8, 6, 8, 8, 7, 9, 3, 2, 1, 8, 2, 4, 7, 3, 1, 2, 4},
|
||||
{5, 9, 8, 6, 10, 4, 10, 3, 4, 10, 10, 10, 1, 7, 8, 8, 7, 7, 8, 8},
|
||||
{1, 4, 6, 1, 6, 1, 2, 10, 5, 10, 2, 6, 2, 4, 5, 5, 3, 5, 1, 5},
|
||||
{5, 6, 9, 10, 6, 6, 10, 6, 4, 1, 5, 3, 9, 5, 2, 10, 9, 9, 5, 1},
|
||||
{10, 9, 4, 6, 9, 5, 3, 7, 10, 1, 6, 8, 1, 1, 10, 9, 5, 7, 7, 5},
|
||||
{2, 6, 6, 6, 6, 2, 9, 4, 7, 5, 3, 2, 10, 3, 4, 5, 10, 9, 1, 7},
|
||||
{5, 2, 4, 9, 8, 4, 8, 2, 4, 1, 3, 7, 6, 8, 1, 6, 8, 8, 10, 10},
|
||||
{9, 6, 3, 1, 8, 5, 7, 8, 7, 2, 1, 8, 2, 8, 3, 7, 4, 8, 7, 7},
|
||||
{8, 4, 4, 9, 7, 10, 6, 2, 1, 5, 8, 5, 1, 1, 1, 9, 1, 3, 5, 3}
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 5, 4, 3, 9, 8, 9, 3, 5, 6, 9, 4, 10, 3, 5, 6, 6, 1, 8, 10, 2 },
|
||||
{ 10, 9, 9, 2, 8, 3, 9, 9, 10, 1, 7, 10, 8, 4, 2, 1, 4, 8, 4, 8 },
|
||||
{ 10, 4, 4, 3, 1, 3, 5, 10, 6, 8, 6, 8, 4, 10, 7, 2, 4, 5, 1, 8 },
|
||||
{ 2, 1, 4, 2, 3, 9, 3, 4, 7, 3, 4, 1, 3, 2, 9, 8, 6, 5, 7, 8 },
|
||||
{ 3, 4, 4, 1, 4, 10, 1, 2, 6, 4, 5, 10, 2, 2, 3, 9, 10, 9, 9, 10 },
|
||||
{ 1, 10, 1, 8, 1, 3, 1, 7, 1, 1, 2, 1, 2, 6, 3, 3, 4, 4, 8, 6 },
|
||||
{ 1, 8, 7, 10, 10, 3, 4, 6, 1, 6, 6, 4, 9, 6, 9, 6, 4, 5, 4, 7 },
|
||||
{ 8, 10, 3, 9, 4, 9, 3, 3, 4, 6, 4, 2, 6, 7, 7, 4, 4, 3, 4, 7 },
|
||||
{ 1, 3, 8, 2, 6, 9, 2, 7, 4, 8, 10, 8, 10, 5, 1, 3, 10, 10, 2, 9 },
|
||||
{ 2, 4, 1, 9, 2, 9, 7, 8, 2, 1, 4, 10, 5, 2, 7, 6, 5, 7, 2, 6 },
|
||||
{ 4, 5, 1, 4, 2, 3, 3, 4, 1, 8, 8, 2, 6, 9, 5, 9, 6, 3, 9, 3 },
|
||||
{ 3, 1, 1, 8, 6, 8, 8, 7, 9, 3, 2, 1, 8, 2, 4, 7, 3, 1, 2, 4 },
|
||||
{ 5, 9, 8, 6, 10, 4, 10, 3, 4, 10, 10, 10, 1, 7, 8, 8, 7, 7, 8, 8 },
|
||||
{ 1, 4, 6, 1, 6, 1, 2, 10, 5, 10, 2, 6, 2, 4, 5, 5, 3, 5, 1, 5 },
|
||||
{ 5, 6, 9, 10, 6, 6, 10, 6, 4, 1, 5, 3, 9, 5, 2, 10, 9, 9, 5, 1 },
|
||||
{ 10, 9, 4, 6, 9, 5, 3, 7, 10, 1, 6, 8, 1, 1, 10, 9, 5, 7, 7, 5 },
|
||||
{ 2, 6, 6, 6, 6, 2, 9, 4, 7, 5, 3, 2, 10, 3, 4, 5, 10, 9, 1, 7 },
|
||||
{ 5, 2, 4, 9, 8, 4, 8, 2, 4, 1, 3, 7, 6, 8, 1, 6, 8, 8, 10, 10 },
|
||||
{ 9, 6, 3, 1, 8, 5, 7, 8, 7, 2, 1, 8, 2, 8, 3, 7, 4, 8, 7, 7 },
|
||||
{ 8, 4, 4, 9, 7, 10, 6, 2, 1, 5, 8, 5, 1, 1, 1, 9, 1, 3, 5, 3 }
|
||||
};
|
||||
|
||||
RunTest(C, 22);
|
||||
RunTest(c, 22);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresRectangularTest1()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 400, 150, 400, 1 },
|
||||
{ 400, 450, 600, 2 },
|
||||
{ 300, 225, 300, 3 }
|
||||
};
|
||||
|
||||
RunTest(C, 452);
|
||||
RunTest(c, 452);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresRectangularTest2()
|
||||
{
|
||||
var C = new double[,] {
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 10, 10, 8, 11 },
|
||||
{ 9, 8, 1, 1 },
|
||||
{ 9, 7, 4, 10 }
|
||||
};
|
||||
|
||||
RunTest(C, 15);
|
||||
RunTest(c, 15);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MunkresRectangularTest3()
|
||||
{
|
||||
var C = new double[,] {
|
||||
{34, 26, 17, 12},
|
||||
{43, 43, 36, 10},
|
||||
{97, 47, 66, 34},
|
||||
{52, 42, 19, 36},
|
||||
{15, 93, 55, 80}
|
||||
var c = new double[,]
|
||||
{
|
||||
{ 34, 26, 17, 12 },
|
||||
{ 43, 43, 36, 10 },
|
||||
{ 97, 47, 66, 34 },
|
||||
{ 52, 42, 19, 36 },
|
||||
{ 15, 93, 55, 80 }
|
||||
};
|
||||
|
||||
RunTest(C, 70);
|
||||
RunTest(c, 70);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.CreateNew()
|
||||
.With(x => x.Name = "artist")
|
||||
.Build();
|
||||
|
||||
|
||||
var mbTrack = Builder<Track>
|
||||
.CreateNew()
|
||||
.With(x => x.Title = title)
|
||||
@@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.With(x => x.TrackNumbers = new[] { 1 })
|
||||
.With(x => x.RecordingMBId = track.ForeignRecordingId)
|
||||
.Build();
|
||||
|
||||
|
||||
var localTrack = Builder<LocalTrack>
|
||||
.CreateNew()
|
||||
.With(x => x.FileTrackInfo = fileInfo)
|
||||
@@ -46,7 +46,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
return localTrack;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void test_identical_tracks()
|
||||
{
|
||||
@@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
Subject.TrackDistance(localTrack, track, 1, true).NormalizedDistance().Should().Be(0.0);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void test_feat_removed_from_localtrack()
|
||||
{
|
||||
|
||||
+52
-69
@@ -1,16 +1,16 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Test.Common;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder.PropertyNaming;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FizzWare.NBuilder.PropertyNaming;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
@@ -18,50 +18,51 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
// but the standard random value namer would give paths that are too long on windows
|
||||
public class RandomValueNamerShortStrings : RandomValuePropertyNamer
|
||||
{
|
||||
private readonly IRandomGenerator generator;
|
||||
private static readonly List<char> allowedChars;
|
||||
|
||||
public RandomValueNamerShortStrings(BuilderSettings settings) : base(settings)
|
||||
private static readonly List<char> AllowedChars;
|
||||
private readonly IRandomGenerator _generator;
|
||||
|
||||
public RandomValueNamerShortStrings(BuilderSettings settings)
|
||||
: base(settings)
|
||||
{
|
||||
generator = new RandomGenerator();
|
||||
_generator = new RandomGenerator();
|
||||
}
|
||||
|
||||
static RandomValueNamerShortStrings()
|
||||
{
|
||||
allowedChars = new List<char>();
|
||||
AllowedChars = new List<char>();
|
||||
for (char c = 'a'; c < 'z'; c++)
|
||||
{
|
||||
allowedChars.Add(c);
|
||||
AllowedChars.Add(c);
|
||||
}
|
||||
|
||||
for (char c = 'A'; c < 'Z'; c++)
|
||||
{
|
||||
allowedChars.Add(c);
|
||||
AllowedChars.Add(c);
|
||||
}
|
||||
|
||||
for (char c = '0'; c < '9'; c++)
|
||||
{
|
||||
allowedChars.Add(c);
|
||||
AllowedChars.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetString(MemberInfo memberInfo)
|
||||
{
|
||||
int length = generator.Next(1, 100);
|
||||
int length = _generator.Next(1, 100);
|
||||
|
||||
char[] chars = new char[length];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int index = generator.Next(0, allowedChars.Count - 1);
|
||||
chars[i] = allowedChars[index];
|
||||
int index = _generator.Next(0, AllowedChars.Count - 1);
|
||||
chars[i] = AllowedChars[index];
|
||||
}
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(chars);
|
||||
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class TrackGroupingServiceFixture : CoreTest<TrackGroupingService>
|
||||
{
|
||||
@@ -117,7 +118,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
.With(f => f.AlbumMBId = null)
|
||||
.With(f => f.ReleaseMBId = null)
|
||||
.Build();
|
||||
|
||||
|
||||
var tracks = fileInfos.Select(x => Builder<LocalTrack>
|
||||
.CreateNew()
|
||||
.With(y => y.FileTrackInfo = x)
|
||||
@@ -196,7 +197,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(true);
|
||||
|
||||
|
||||
output.Count.Should().Be(1);
|
||||
output[0].LocalTracks.Count.Should().Be(count);
|
||||
}
|
||||
@@ -206,10 +207,8 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[TestCase("disk")]
|
||||
public void should_group_multi_disc_release(string mediaName)
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album\\{mediaName} 1".AsOsAgnostic(),
|
||||
"artist", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album\\{mediaName} 2".AsOsAgnostic(),
|
||||
"artist", "album", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album\\{mediaName} 1".AsOsAgnostic(), "artist", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album\\{mediaName} 2".AsOsAgnostic(), "artist", "album", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(true);
|
||||
@@ -222,14 +221,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_not_group_two_different_albums_by_same_artist()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album1".AsOsAgnostic(),
|
||||
"artist", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album2".AsOsAgnostic(),
|
||||
"artist", "album2", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album1".AsOsAgnostic(), "artist", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album2".AsOsAgnostic(), "artist", "album2", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(2);
|
||||
output[0].LocalTracks.Count.Should().Be(10);
|
||||
@@ -239,14 +236,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_group_albums_with_typos()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album".AsOsAgnostic(),
|
||||
"artist", "Rastaman Vibration (Remastered)", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album".AsOsAgnostic(),
|
||||
"artist", "Rastaman Vibration (Remastered", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist - album".AsOsAgnostic(), "artist", "Rastaman Vibration (Remastered)", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist - album".AsOsAgnostic(), "artist", "Rastaman Vibration (Remastered", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(true);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(1);
|
||||
output[0].LocalTracks.Count.Should().Be(15);
|
||||
@@ -255,14 +250,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_not_group_two_different_tracks_in_same_directory()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming".AsOsAgnostic(),
|
||||
"artist", "album1", 1);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming".AsOsAgnostic(),
|
||||
"artist", "album2", 1));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming".AsOsAgnostic(), "artist", "album1", 1);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming".AsOsAgnostic(), "artist", "album2", 1));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(2);
|
||||
output[0].LocalTracks.Count.Should().Be(1);
|
||||
@@ -272,14 +265,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_separate_two_albums_in_same_directory()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist discog".AsOsAgnostic(),
|
||||
"artist", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist disog".AsOsAgnostic(),
|
||||
"artist", "album2", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\artist discog".AsOsAgnostic(), "artist", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\artist disog".AsOsAgnostic(), "artist", "album2", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(2);
|
||||
output[0].LocalTracks.Count.Should().Be(10);
|
||||
@@ -292,13 +283,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var tracks = new List<LocalTrack>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
tracks.AddRange(GivenTracks($"C:\\music".AsOsAgnostic(),
|
||||
"artist" + i, "album" + i, 10));
|
||||
tracks.AddRange(GivenTracks($"C:\\music".AsOsAgnostic(), "artist" + i, "album" + i, 10));
|
||||
}
|
||||
|
||||
// don't test various artists here because it's designed to only work if there's a common album
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(100);
|
||||
output.Select(x => x.LocalTracks.Count).Distinct().Should().BeEquivalentTo(new List<int> { 10 });
|
||||
@@ -307,14 +297,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_separate_two_albums_by_different_artists_in_same_directory()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming".AsOsAgnostic(),
|
||||
"artist1", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming".AsOsAgnostic(),
|
||||
"artist2", "album2", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming".AsOsAgnostic(), "artist1", "album1", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming".AsOsAgnostic(), "artist2", "album2", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(2);
|
||||
output[0].LocalTracks.Count.Should().Be(10);
|
||||
@@ -329,7 +317,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(true);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(true);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
output.Count.Should().Be(1);
|
||||
output[0].LocalTracks.Count.Should().Be(10);
|
||||
@@ -338,14 +326,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_not_group_two_albums_by_different_artists_with_same_title()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(),
|
||||
"artist1", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(),
|
||||
"artist2", "album", 5));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(), "artist1", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(), "artist2", "album", 5));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
|
||||
output.Count.Should().Be(2);
|
||||
@@ -369,8 +355,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_not_fail_if_some_tags_null()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(),
|
||||
"artist1", "album", 10);
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(), "artist1", "album", 10);
|
||||
tracks.AddRange(GivenTracksWithNoTags($"C:\\music\\incoming\\album".AsOsAgnostic(), 2));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
@@ -384,17 +369,15 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
[Test]
|
||||
public void should_cope_with_one_album_in_subfolder_of_another()
|
||||
{
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(),
|
||||
"artist1", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\album\\anotheralbum".AsOsAgnostic(),
|
||||
"artist2", "album2", 10));
|
||||
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(), "artist1", "album", 10);
|
||||
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\album\\anotheralbum".AsOsAgnostic(), "artist2", "album2", 10));
|
||||
|
||||
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
|
||||
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
|
||||
|
||||
var output = Subject.GroupTracks(tracks);
|
||||
|
||||
foreach(var group in output)
|
||||
foreach (var group in output)
|
||||
{
|
||||
TestLogger.Debug($"*** group {group} ***");
|
||||
TestLogger.Debug(string.Join("\n", group.LocalTracks.Select(x => x.Path)));
|
||||
|
||||
+45
-44
@@ -1,41 +1,38 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Music;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
{
|
||||
[TestFixture]
|
||||
public class TrackMappingFixture : CoreTest<IdentificationService>
|
||||
{
|
||||
|
||||
private ArtistMetadata artist;
|
||||
private ArtistMetadata _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
artist = Builder<ArtistMetadata>
|
||||
_artist = Builder<ArtistMetadata>
|
||||
.CreateNew()
|
||||
.With(x => x.Name = "artist")
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
private List<Track> GivenTracks(int count)
|
||||
{
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.Build()
|
||||
.ToList();
|
||||
return Builder<Track>
|
||||
.CreateListOfSize(count)
|
||||
.All()
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private ParsedTrackInfo GivenParsedTrackInfo(Track track, AlbumRelease release)
|
||||
@@ -76,7 +73,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var album = Builder<Album>
|
||||
.CreateNew()
|
||||
.With(x => x.Title = title)
|
||||
.With(x => x.ArtistMetadata = artist)
|
||||
.With(x => x.ArtistMetadata = _artist)
|
||||
.Build();
|
||||
|
||||
var media = Builder<Medium>
|
||||
@@ -102,19 +99,20 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
var release = GivenAlbumRelease("album", tracks);
|
||||
var localTracks = GivenLocalTracks(tracks, release);
|
||||
|
||||
localTracks[2].FileTrackInfo.TrackNumbers = new [] { 2 };
|
||||
localTracks[1].FileTrackInfo.TrackNumbers = new [] { 3 };
|
||||
localTracks = new [] {0, 2, 1}.Select(x => localTracks[x]).ToList();
|
||||
localTracks[2].FileTrackInfo.TrackNumbers = new[] { 2 };
|
||||
localTracks[1].FileTrackInfo.TrackNumbers = new[] { 3 };
|
||||
localTracks = new[] { 0, 2, 1 }.Select(x => localTracks[x]).ToList();
|
||||
|
||||
var result = Subject.MapReleaseTracks(localTracks, tracks);
|
||||
|
||||
|
||||
result.Mapping
|
||||
.ToDictionary(x => x.Key, y => y.Value.Item1)
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track> {
|
||||
{localTracks[0], tracks[0]},
|
||||
{localTracks[1], tracks[2]},
|
||||
{localTracks[2], tracks[1]},
|
||||
});
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track>
|
||||
{
|
||||
{ localTracks[0], tracks[0] },
|
||||
{ localTracks[1], tracks[2] },
|
||||
{ localTracks[2], tracks[1] },
|
||||
});
|
||||
result.LocalExtra.Should().BeEmpty();
|
||||
result.MBExtra.Should().BeEmpty();
|
||||
}
|
||||
@@ -135,11 +133,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
|
||||
result.Mapping
|
||||
.ToDictionary(x => x.Key, y => y.Value.Item1)
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track> {
|
||||
{localTracks[0], tracks[0]},
|
||||
{localTracks[1], tracks[1]},
|
||||
{localTracks[2], tracks[2]},
|
||||
});
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track>
|
||||
{
|
||||
{ localTracks[0], tracks[0] },
|
||||
{ localTracks[1], tracks[1] },
|
||||
{ localTracks[2], tracks[2] },
|
||||
});
|
||||
result.LocalExtra.Should().BeEmpty();
|
||||
result.MBExtra.Should().BeEmpty();
|
||||
}
|
||||
@@ -153,13 +152,14 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
localTracks.RemoveAt(1);
|
||||
|
||||
var result = Subject.MapReleaseTracks(localTracks, tracks);
|
||||
|
||||
|
||||
result.Mapping
|
||||
.ToDictionary(x => x.Key, y => y.Value.Item1)
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track> {
|
||||
{localTracks[0], tracks[0]},
|
||||
{localTracks[1], tracks[2]}
|
||||
});
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track>
|
||||
{
|
||||
{ localTracks[0], tracks[0] },
|
||||
{ localTracks[1], tracks[2] }
|
||||
});
|
||||
result.LocalExtra.Should().BeEmpty();
|
||||
result.MBExtra.Should().BeEquivalentTo(new List<Track> { tracks[1] });
|
||||
}
|
||||
@@ -173,13 +173,14 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
|
||||
tracks.RemoveAt(1);
|
||||
|
||||
var result = Subject.MapReleaseTracks(localTracks, tracks);
|
||||
|
||||
|
||||
result.Mapping
|
||||
.ToDictionary(x => x.Key, y => y.Value.Item1)
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track> {
|
||||
{localTracks[0], tracks[0]},
|
||||
{localTracks[2], tracks[1]}
|
||||
});
|
||||
.Should().BeEquivalentTo(new Dictionary<LocalTrack, Track>
|
||||
{
|
||||
{ localTracks[0], tracks[0] },
|
||||
{ localTracks[2], tracks[1] }
|
||||
});
|
||||
result.LocalExtra.Should().BeEquivalentTo(new List<LocalTrack> { localTracks[1] });
|
||||
result.MBExtra.Should().BeEmpty();
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.IO.Abstractions;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
using FizzWare.NBuilder;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
{
|
||||
@@ -38,7 +38,6 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
private Mock<IImportDecisionEngineSpecification<LocalAlbumRelease>> _albumfail2;
|
||||
private Mock<IImportDecisionEngineSpecification<LocalAlbumRelease>> _albumfail3;
|
||||
|
||||
|
||||
private Mock<IImportDecisionEngineSpecification<LocalTrack>> _pass1;
|
||||
private Mock<IImportDecisionEngineSpecification<LocalTrack>> _pass2;
|
||||
private Mock<IImportDecisionEngineSpecification<LocalTrack>> _pass3;
|
||||
@@ -58,7 +57,6 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
_albumfail2 = new Mock<IImportDecisionEngineSpecification<LocalAlbumRelease>>();
|
||||
_albumfail3 = new Mock<IImportDecisionEngineSpecification<LocalAlbumRelease>>();
|
||||
|
||||
|
||||
_pass1 = new Mock<IImportDecisionEngineSpecification<LocalTrack>>();
|
||||
_pass2 = new Mock<IImportDecisionEngineSpecification<LocalTrack>>();
|
||||
_pass3 = new Mock<IImportDecisionEngineSpecification<LocalTrack>>();
|
||||
@@ -74,7 +72,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
_albumfail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalAlbumRelease>())).Returns(Decision.Reject("_albumfail1"));
|
||||
_albumfail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalAlbumRelease>())).Returns(Decision.Reject("_albumfail2"));
|
||||
_albumfail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalAlbumRelease>())).Returns(Decision.Reject("_albumfail3"));
|
||||
|
||||
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>())).Returns(Decision.Accept());
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>())).Returns(Decision.Accept());
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>())).Returns(Decision.Accept());
|
||||
@@ -104,11 +102,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
|
||||
Mocker.GetMock<IIdentificationService>()
|
||||
.Setup(s => s.Identify(It.IsAny<List<LocalTrack>>(), It.IsAny<Artist>(), It.IsAny<Album>(), It.IsAny<AlbumRelease>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
.Returns((List<LocalTrack> tracks, Artist artist, Album album, AlbumRelease release, bool newDownload, bool singleRelease, bool includeExisting) => {
|
||||
var ret = new LocalAlbumRelease(tracks);
|
||||
ret.AlbumRelease = _albumRelease;
|
||||
return new List<LocalAlbumRelease> { ret };
|
||||
});
|
||||
.Returns((List<LocalTrack> tracks, Artist artist, Album album, AlbumRelease release, bool newDownload, bool singleRelease, bool includeExisting) =>
|
||||
{
|
||||
var ret = new LocalAlbumRelease(tracks);
|
||||
ret.AlbumRelease = _albumRelease;
|
||||
return new List<LocalAlbumRelease> { ret };
|
||||
});
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.FilterUnchangedFiles(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>()))
|
||||
@@ -269,7 +268,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
.Setup(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()))
|
||||
.Throws<TestException>();
|
||||
|
||||
GivenAudioFiles(new []
|
||||
GivenAudioFiles(new[]
|
||||
{
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@@ -289,7 +288,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
{
|
||||
GivenSpecifications(_pass1);
|
||||
|
||||
GivenAudioFiles(new []
|
||||
GivenAudioFiles(new[]
|
||||
{
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@@ -298,9 +297,10 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
|
||||
Mocker.GetMock<IIdentificationService>()
|
||||
.Setup(s => s.Identify(It.IsAny<List<LocalTrack>>(), It.IsAny<Artist>(), It.IsAny<Album>(), It.IsAny<AlbumRelease>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
.Returns((List<LocalTrack> tracks, Artist artist, Album album, AlbumRelease release, bool newDownload, bool singleRelease, bool includeExisting) => {
|
||||
return new List<LocalAlbumRelease> { new LocalAlbumRelease(tracks) };
|
||||
});
|
||||
.Returns((List<LocalTrack> tracks, Artist artist, Album album, AlbumRelease release, bool newDownload, bool singleRelease, bool includeExisting) =>
|
||||
{
|
||||
return new List<LocalAlbumRelease> { new LocalAlbumRelease(tracks) };
|
||||
});
|
||||
|
||||
var decisions = Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false);
|
||||
|
||||
@@ -316,7 +316,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
{
|
||||
GivenSpecifications(_pass1);
|
||||
|
||||
GivenAudioFiles(new []
|
||||
GivenAudioFiles(new[]
|
||||
{
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic(),
|
||||
@@ -339,7 +339,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||
.Setup(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()))
|
||||
.Throws<TestException>();
|
||||
|
||||
GivenAudioFiles(new []
|
||||
GivenAudioFiles(new[]
|
||||
{
|
||||
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic()
|
||||
});
|
||||
|
||||
+7
-7
@@ -7,9 +7,9 @@ using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
@@ -24,7 +24,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_rootFolder = @"C:\Test\Music".AsOsAgnostic();
|
||||
_rootFolder = @"C:\Test\Music".AsOsAgnostic();
|
||||
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Path = Path.Combine(_rootFolder, "Alice in Chains"))
|
||||
@@ -36,11 +36,11 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
.ToList();
|
||||
|
||||
_localTrack = new LocalTrack
|
||||
{
|
||||
Path = @"C:\Test\Unsorted\Alice in Chains\Alice in Chains - track1.mp3".AsOsAgnostic(),
|
||||
Tracks = tracks,
|
||||
Artist = _artist
|
||||
};
|
||||
{
|
||||
Path = @"C:\Test\Unsorted\Alice in Chains\Alice in Chains - track1.mp3".AsOsAgnostic(),
|
||||
Tracks = tracks,
|
||||
Artist = _artist
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenFileSize(long size)
|
||||
|
||||
+1
-1
@@ -6,9 +6,9 @@ using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
|
||||
+1
-1
@@ -5,9 +5,9 @@ using Marr.Data;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
{
|
||||
|
||||
+2
-3
@@ -3,14 +3,14 @@ using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Marr.Data;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Specifications;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
{
|
||||
@@ -159,7 +159,6 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Specifications
|
||||
Subject.IsSatisfiedBy(_localTrack).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_a_revision_upgrade_and_prefers_propers()
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
@@ -18,22 +18,21 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
private TrackFile _trackFile;
|
||||
private LocalTrack _localTrack;
|
||||
private string rootPath = @"C:\Test\Music\Artist".AsOsAgnostic();
|
||||
private string _rootPath = @"C:\Test\Music\Artist".AsOsAgnostic();
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_localTrack = new LocalTrack();
|
||||
_localTrack.Artist = new Artist
|
||||
{
|
||||
Path = rootPath
|
||||
};
|
||||
{
|
||||
Path = _rootPath
|
||||
};
|
||||
|
||||
_trackFile = Builder<TrackFile>
|
||||
.CreateNew()
|
||||
.Build();
|
||||
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FileExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
@@ -56,7 +55,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
new TrackFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
Path = Path.Combine(_rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
@@ -71,7 +70,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
new TrackFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
Path = Path.Combine(_rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
@@ -85,14 +84,14 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
new TrackFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
Path = Path.Combine(_rootPath, @"Season 01\30.rock.s01e01.avi"),
|
||||
}))
|
||||
.TheNext(1)
|
||||
.With(e => e.TrackFile = new LazyLoaded<TrackFile>(
|
||||
new TrackFile
|
||||
{
|
||||
Id = 2,
|
||||
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e02.avi"),
|
||||
Path = Path.Combine(_rootPath, @"Season 01\30.rock.s01e02.avi"),
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Reference in New Issue
Block a user