mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-19 21:44:30 -04:00
New: Only scan files that are new or updated (#760)
* New: Only scan files that are new or updated Pass through filter correctly Add more tests Add tests for migration 30 * Fix windows disk provider * Don't publish deleted event for unmapped file * Fix test on windows
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
@@ -13,11 +14,16 @@ 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;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ScanFixture : CoreTest<DiskScanService>
|
||||
public class ScanFixture : FileSystemTest<DiskScanService>
|
||||
{
|
||||
private Artist _artist;
|
||||
private string _rootFolder;
|
||||
@@ -34,42 +40,34 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
.With(s => s.Path = artistFolder)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetParentFolder(It.IsAny<string>()))
|
||||
.Returns((string path) => Directory.GetParent(path).FullName);
|
||||
|
||||
Mocker.GetMock<IRootFolderService>()
|
||||
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
|
||||
.Returns(_rootFolder);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Setup(v => v.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), It.IsAny<bool>()))
|
||||
.Setup(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>(), It.IsAny<bool>()))
|
||||
.Returns(new List<ImportDecision<LocalTrack>>());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(v => v.GetFilesByArtist(It.IsAny<int>()))
|
||||
.Returns(new List<TrackFile>());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(v => v.GetFilesWithBasePath(It.IsAny<string>()))
|
||||
.Returns(new List<TrackFile>());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(v => v.FilterUnchangedFiles(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>()))
|
||||
.Returns((List<IFileInfo> files, Artist artist) => files);
|
||||
}
|
||||
|
||||
private void GivenRootFolder(params string[] subfolders)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(_rootFolder))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetDirectories(_rootFolder))
|
||||
.Returns(subfolders);
|
||||
FileSystem.AddDirectory(_rootFolder);
|
||||
|
||||
foreach (var folder in subfolders)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(folder))
|
||||
.Returns(true);
|
||||
FileSystem.AddDirectory(folder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +76,36 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
GivenRootFolder(_artist.Path);
|
||||
}
|
||||
|
||||
private void GivenFiles(IEnumerable<string> files)
|
||||
private List<IFileInfo> GivenFiles(IEnumerable<string> files, DateTimeOffset? lastWrite = null)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
|
||||
.Returns(files.ToArray());
|
||||
if (lastWrite == null)
|
||||
{
|
||||
TestLogger.Debug("Using default lastWrite");
|
||||
lastWrite = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
FileSystem.AddFile(file, new MockFileData(string.Empty) { LastWriteTime = lastWrite.Value });
|
||||
}
|
||||
|
||||
return files.Select(x => DiskProvider.GetFileInfo(x)).ToList();
|
||||
}
|
||||
|
||||
private void GivenKnownFiles(IEnumerable<string> files, DateTimeOffset? lastWrite = null)
|
||||
{
|
||||
if (lastWrite == null)
|
||||
{
|
||||
TestLogger.Debug("Using default lastWrite");
|
||||
lastWrite = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(x => x.GetFilesWithBasePath(_artist.Path))
|
||||
.Returns(files.Select(x => new TrackFile {
|
||||
Path = x,
|
||||
Modified = lastWrite.Value.UtcDateTime
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -115,7 +138,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
.Verify(v => v.Clean(It.IsAny<Artist>(), It.IsAny<List<string>>()), Times.Never());
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _artist, false), Times.Never());
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), _artist, FilterFilesType.Known, true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -129,8 +152,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.CreateFolder(_artist.Path), Times.Once());
|
||||
DiskProvider.FolderExists(_artist.Path).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -144,8 +166,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.CreateFolder(_artist.Path), Times.Never());
|
||||
DiskProvider.FolderExists(_artist.Path).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -155,14 +176,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.FolderExists(_artist.Path), Times.Once());
|
||||
DiskProvider.FolderExists(_artist.Path).Should().BeFalse();
|
||||
|
||||
Mocker.GetMock<IMediaFileTableCleanupService>()
|
||||
.Verify(v => v.Clean(It.IsAny<Artist>(), It.IsAny<List<string>>()), Times.Once());
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _artist, false), Times.Never());
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), _artist, FilterFilesType.Known, true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -180,7 +200,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
.Verify(v => v.Clean(It.IsAny<Artist>(), It.IsAny<List<string>>()), Times.Once());
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _artist, false), Times.Never());
|
||||
.Verify(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), _artist, FilterFilesType.Known, true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -190,14 +210,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "file1.flac"),
|
||||
Path.Combine(_artist.Path, "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 2), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 2), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -207,20 +227,17 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "EXTRAS", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Extras", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "EXTRAs", "file3.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "ExTrAs", "file4.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "EXTRAS", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Extras", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "EXTRAs", "file3.flac"),
|
||||
Path.Combine(_artist.Path, "ExTrAs", "file4.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Once());
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -230,15 +247,15 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, ".AppleDouble", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, ".appledouble", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, ".AppleDouble", "file1.flac"),
|
||||
Path.Combine(_artist.Path, ".appledouble", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -250,18 +267,18 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Extras", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, ".AppleDouble", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e02.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 2", "s02e01.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 2", "s02e02.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Extras", "file1.flac"),
|
||||
Path.Combine(_artist.Path, ".AppleDouble", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e02.flac"),
|
||||
Path.Combine(_artist.Path, "Season 2", "s02e01.flac"),
|
||||
Path.Combine(_artist.Path, "Season 2", "s02e02.flac"),
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 4), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 4), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -271,13 +288,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Album 1", ".t01.mp3").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "Album 1", ".t01.mp3")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -287,16 +304,16 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, ".@__thumb", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, ".@__THUMB", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, ".hidden", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, ".@__thumb", "file1.flac"),
|
||||
Path.Combine(_artist.Path, ".@__THUMB", "file2.flac"),
|
||||
Path.Combine(_artist.Path, ".hidden", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -306,17 +323,17 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", ".@__thumb", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", ".@__THUMB", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", ".hidden", "file2.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", ".AppleDouble", "s01e01.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "Season 1", ".@__thumb", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", ".@__THUMB", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", ".hidden", "file2.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", ".AppleDouble", "s01e01.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -326,14 +343,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "@eaDir", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "@eaDir", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -343,14 +360,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, ".@__thumb", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, ".@__thumb", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -362,14 +379,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 2), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 2), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -379,15 +396,173 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
|
||||
|
||||
GivenFiles(new List<string>
|
||||
{
|
||||
Path.Combine(_artist.Path, ".DS_STORE").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "._24 The Status Quo Combustion.flac").AsOsAgnostic(),
|
||||
Path.Combine(_artist.Path, "24 The Status Quo Combustion.flac").AsOsAgnostic()
|
||||
Path.Combine(_artist.Path, ".DS_STORE"),
|
||||
Path.Combine(_artist.Path, "._24 The Status Quo Combustion.flac"),
|
||||
Path.Combine(_artist.Path, "24 The Status Quo Combustion.flac")
|
||||
});
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _artist, false), Times.Once());
|
||||
.Verify(v => v.GetImportDecisions(It.Is<List<IFileInfo>>(l => l.Count == 1), _artist, FilterFilesType.Known, true), Times.Once());
|
||||
}
|
||||
|
||||
private void GivenRejections()
|
||||
{
|
||||
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()
|
||||
})
|
||||
.Select(x => new ImportDecision<LocalTrack>(x, new Rejection("Reject")))
|
||||
.ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_insert_new_unmatched_files_when_all_new()
|
||||
{
|
||||
var files = new List<string> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
|
||||
GivenFiles(files);
|
||||
GivenKnownFiles(new List<string>());
|
||||
GivenRejections();
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.AddMany(It.Is<List<TrackFile>>(l => l.Select(t => t.Path).SequenceEqual(files))),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_insert_new_unmatched_files_when_some_known()
|
||||
{
|
||||
var files = new List<string> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
|
||||
GivenFiles(files);
|
||||
GivenKnownFiles(files.GetRange(1, 1));
|
||||
GivenRejections();
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.AddMany(It.Is<List<TrackFile>>(l => l.Select(t => t.Path).SequenceEqual(files.GetRange(0, 1)))),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_insert_files_when_all_known()
|
||||
{
|
||||
var files = new List<string> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
|
||||
GivenFiles(files);
|
||||
GivenKnownFiles(files);
|
||||
GivenRejections();
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.AddMany(It.Is<List<TrackFile>>(l => l.Count == 0)),
|
||||
Times.Once());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.AddMany(It.Is<List<TrackFile>>(l => l.Count > 0)),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_info_for_unchanged_known_files()
|
||||
{
|
||||
var files = new List<string> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
|
||||
GivenFiles(files);
|
||||
GivenKnownFiles(files);
|
||||
GivenRejections();
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.Update(It.Is<List<TrackFile>>(l => l.Count == 0)),
|
||||
Times.Once());
|
||||
|
||||
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> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
Path.Combine(_artist.Path, "Season 1", "s01e01.flac")
|
||||
};
|
||||
|
||||
GivenFiles(files, new DateTime(2019, 2, 1));
|
||||
GivenKnownFiles(files);
|
||||
GivenRejections();
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.Update(It.Is<List<TrackFile>>(l => l.Count == 2)),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_fields_for_updated_files()
|
||||
{
|
||||
var files = new List<string> {
|
||||
Path.Combine(_artist.Path, "Season 1", "file1.flac"),
|
||||
};
|
||||
|
||||
GivenKnownFiles(files);
|
||||
|
||||
FileSystem.AddFile(files[0], new MockFileData("".PadRight(100)) { LastWriteTime = new DateTime(2019, 2, 1) });
|
||||
|
||||
var localTrack = Builder<LocalTrack>.CreateNew()
|
||||
.With(x => x.Path = files[0])
|
||||
.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()
|
||||
})
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Setup(x => x.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>(), It.IsAny<bool>()))
|
||||
.Returns(new List<ImportDecision<LocalTrack>> { new ImportDecision<LocalTrack>(localTrack, new Rejection("Reject")) });
|
||||
|
||||
Subject.Scan(_artist);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(x => x.Update(It.Is<List<TrackFile>>(
|
||||
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
|
||||
)),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user