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:
ta264
2019-06-08 20:13:58 +01:00
committed by Qstick
parent 8fe8aec97c
commit 166fc90454
95 changed files with 1590 additions and 723 deletions
@@ -186,10 +186,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
var path = copiedFile;
var track = new TrackFile {
Artist = new Artist {
Path = Path.GetDirectoryName(path)
},
RelativePath = Path.GetFileName(path)
Path = path
};
testTags.Write(path);
@@ -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());
}
}
}
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.MediaFiles;
@@ -14,11 +13,12 @@ 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
{
[TestFixture]
public class DownloadedAlbumsCommandServiceFixture : CoreTest<DownloadedAlbumsCommandService>
public class DownloadedAlbumsCommandServiceFixture : FileSystemTest<DownloadedAlbumsCommandService>
{
private string _downloadFolder = "c:\\drop_other\\Show.S01E01\\".AsOsAgnostic();
private string _downloadFile = "c:\\drop_other\\Show.S01E01.mkv".AsOsAgnostic();
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.MediaFiles
{
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessRootFolder(It.IsAny<DirectoryInfo>()))
.Setup(v => v.ProcessRootFolder(It.IsAny<IDirectoryInfo>()))
.Returns(new List<ImportResult>());
Mocker.GetMock<IDownloadedTracksImportService>()
@@ -56,14 +56,12 @@ namespace NzbDrone.Core.Test.MediaFiles
private void GivenExistingFolder(string path)
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
FileSystem.AddDirectory(path);
}
private void GivenExistingFile(string path)
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
FileSystem.AddFile(path, new MockFileData(string.Empty));
}
private void GivenValidQueueItem()
@@ -78,7 +76,7 @@ namespace NzbDrone.Core.Test.MediaFiles
{
Assert.Throws<ArgumentException>(() => Subject.Execute(new DownloadedAlbumsScanCommand()));
Mocker.GetMock<IDownloadedTracksImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Never());
Mocker.GetMock<IDownloadedTracksImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<IDirectoryInfo>()), Times.Never());
}
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
@@ -12,36 +12,33 @@ using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
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
{
[TestFixture]
public class DownloadedTracksImportServiceFixture : CoreTest<DownloadedTracksImportService>
public class DownloadedTracksImportServiceFixture : FileSystemTest<DownloadedTracksImportService>
{
private string _droneFactory = "c:\\drop\\".AsOsAgnostic();
private string[] _subFolders = new[] { "c:\\root\\foldername".AsOsAgnostic() };
private string[] _audioFiles = new[] { "c:\\root\\foldername\\01 the first track.ext".AsOsAgnostic() };
private string[] _subFolders = new[] { "c:\\drop\\foldername".AsOsAgnostic() };
private string[] _audioFiles = new[] { "c:\\drop\\foldername\\01 the first track.ext".AsOsAgnostic() };
private TrackedDownload _trackedDownload;
[SetUp]
public void Setup()
{
GivenAudioFiles(_audioFiles, 10);
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_audioFiles);
.Returns(_audioFiles.Select(x => DiskProvider.GetFileInfo(x)).ToArray());
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
.Returns(_subFolders);
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<IFileInfo>>()))
.Returns<string, IEnumerable<IFileInfo>>((b, s) => s.ToList());
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
@@ -65,6 +62,14 @@ namespace NzbDrone.Core.Test.MediaFiles
};
}
private void GivenAudioFiles(string[] files, long filesize)
{
foreach (var file in files)
{
FileSystem.AddFile(file, new MockFileData("".PadRight((int)filesize)));
}
}
private void GivenValidArtist()
{
Mocker.GetMock<IParsingService>()
@@ -80,7 +85,7 @@ namespace NzbDrone.Core.Test.MediaFiles
imported.Add(new ImportDecision<LocalTrack>(localTrack));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), null))
.Setup(s => s.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), null))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
@@ -92,13 +97,13 @@ namespace NzbDrone.Core.Test.MediaFiles
private void WasImportedResponse()
{
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
.Returns(new IFileInfo[0]);
}
[Test]
public void should_search_for_artist_using_folder_name()
{
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IParsingService>().Verify(c => c.GetArtist("foldername"), Times.Once());
}
@@ -108,10 +113,12 @@ namespace NzbDrone.Core.Test.MediaFiles
{
GivenValidArtist();
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<string>()))
.Returns(true);
foreach (var file in _audioFiles)
{
FileSystem.AddFile(file, new MockFileData("".PadRight(10)) { AllowedFileShare = FileShare.None });
}
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
VerifyNoImport();
}
@@ -121,10 +128,10 @@ namespace NzbDrone.Core.Test.MediaFiles
{
Mocker.GetMock<IParsingService>().Setup(c => c.GetArtist("foldername")).Returns((Artist)null);
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IMakeImportDecision>()
.Verify(c => c.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), It.IsAny<ParsedTrackInfo>()),
.Verify(c => c.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<ParsedTrackInfo>()),
Times.Never());
VerifyNoImport();
@@ -141,9 +148,9 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskScanService>()
.Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
.Returns(new IFileInfo[0]);
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskScanService>()
.Verify(v => v.GetAudioFiles(It.IsAny<string>(), true), Times.Never());
@@ -158,7 +165,7 @@ namespace NzbDrone.Core.Test.MediaFiles
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), false, null, ImportMode.Auto))
.Returns(new List<ImportResult>());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFolderSize(It.IsAny<string>()), Times.Never());
@@ -175,14 +182,14 @@ namespace NzbDrone.Core.Test.MediaFiles
imported.Add(new ImportDecision<LocalTrack>(localTrack));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), null))
.Setup(s => s.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), null))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
.Returns(imported.Select(i => new ImportResult(i)).ToList());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
@@ -195,13 +202,9 @@ namespace NzbDrone.Core.Test.MediaFiles
public void should_remove_unpack_from_folder_name(string prefix)
{
var folderName = "Alien Ant Farm - Truant (2003)";
var folders = new[] { string.Format(@"C:\Test\Unsorted\{0}{1}", prefix, folderName).AsOsAgnostic() };
FileSystem.AddDirectory(string.Format(@"C:\drop\{0}{1}", prefix, folderName).AsOsAgnostic());
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetDirectories(It.IsAny<string>()))
.Returns(folders);
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IParsingService>()
.Verify(v => v.GetArtist(folderName), Times.Once());
@@ -213,13 +216,8 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_return_importresult_on_unknown_artist()
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(false);
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
var fileName = @"C:\folder\file.mkv".AsOsAgnostic();
FileSystem.AddFile(fileName, new MockFileData(string.Empty));
var result = Subject.ProcessPath(fileName);
@@ -241,33 +239,18 @@ namespace NzbDrone.Core.Test.MediaFiles
imported.Add(new ImportDecision<LocalTrack>(localTrack));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), null))
.Setup(s => s.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), null))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
.Returns(imported.Select(i => new ImportResult(i)).ToList());
//Mocker.GetMock<IDetectSample>()
// .Setup(s => s.IsSample(It.IsAny<Artist>(),
// It.IsAny<QualityModel>(),
// It.IsAny<string>(),
// It.IsAny<long>(),
// It.IsAny<bool>()))
// .Returns(true);
GivenAudioFiles(new []{ _audioFiles.First().Replace(".ext", ".rar") }, 15.Megabytes());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
.Returns(new []{ _audioFiles.First().Replace(".ext", ".rar") });
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFileSize(It.IsAny<string>()))
.Returns(15.Megabytes());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
ExceptionVerification.ExpectedWarns(1);
}
@@ -277,12 +260,6 @@ namespace NzbDrone.Core.Test.MediaFiles
{
var folderName = @"C:\media\ba09030e-1234-1234-1234-123456789abc\[HorribleSubs] Maria the Virgin Witch - 09 [720p]".AsOsAgnostic();
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(folderName))
.Returns(false);
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(folderName))
.Returns(false);
Subject.ProcessPath(folderName).Should().BeEmpty();
Mocker.GetMock<IParsingService>()
@@ -302,26 +279,16 @@ namespace NzbDrone.Core.Test.MediaFiles
imported.Add(new ImportDecision<LocalTrack>(localTrack));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), null))
.Setup(s => s.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), null))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
.Returns(new List<ImportResult>());
//Mocker.GetMock<IDetectSample>()
// .Setup(s => s.IsSample(It.IsAny<Artist>(),
// It.IsAny<QualityModel>(),
// It.IsAny<string>(),
// It.IsAny<long>(),
// It.IsAny<bool>()))
// .Returns(true);
Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFileSize(It.IsAny<string>()))
.Returns(15.Megabytes());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
@@ -338,8 +305,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Subject.ProcessPath(_droneFactory, ImportMode.Auto, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
}
[Test]
@@ -353,8 +319,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Subject.ProcessPath(_droneFactory, ImportMode.Move, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once());
DiskProvider.FolderExists(_subFolders[0]).Should().BeFalse();
}
[Test]
@@ -368,8 +333,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Subject.ProcessPath(_droneFactory, ImportMode.Copy, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
}
private void VerifyNoImport()
@@ -89,10 +89,6 @@ namespace NzbDrone.Core.Test.MediaFiles
_downloadClientItem = Builder<DownloadClientItem>.CreateNew().Build();
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesWithRelativePath(It.IsAny<int>(), It.IsAny<string>()))
.Returns(new List<TrackFile>());
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesByAlbum(It.IsAny<int>()))
.Returns(new List<TrackFile>());
@@ -220,8 +216,8 @@ namespace NzbDrone.Core.Test.MediaFiles
public void should_delete_existing_trackfiles_with_the_same_path()
{
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesWithRelativePath(It.IsAny<int>(), It.IsAny<string>()))
.Returns(Builder<TrackFile>.CreateListOfSize(1).BuildList());
.Setup(s => s.GetFileWithPath(It.IsAny<string>()))
.Returns(Builder<TrackFile>.CreateNew().Build());
var track = _approvedDecisions.First();
track.Item.ExistingFile = true;
@@ -26,8 +26,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
.Build();
_trackFile = Builder<TrackFile>.CreateNew()
.With(f => f.RelativePath = "Artist Name - Track01")
.With(f => f.Path = Path.Combine(_artist.Path, "Artist Name - Track01"))
.With(f => f.Path = "/Artist Name - Track01")
.Build();
Mocker.GetMock<IDiskProvider>()
@@ -117,28 +117,6 @@ namespace NzbDrone.Core.Test.MediaFiles
files.Should().HaveCount(4);
}
[Test]
public void get_files_by_relative_path()
{
VerifyData();
var files = Subject.GetFilesWithRelativePath(artist.Id, "RelativePath2");
VerifyEagerLoaded(files);
files.Should().OnlyContain(c => c.AlbumId == album.Id);
files.Should().OnlyContain(c => c.RelativePath == "RelativePath2");
}
[Test]
public void get_files_by_relative_path_should_only_contain_monitored_releases()
{
VerifyData();
// file 5 is linked to an unmonitored release
var files = Subject.GetFilesWithRelativePath(artist.Id, "RelativePath5");
files.Should().BeEmpty();
}
private void VerifyData()
{
Db.All<Artist>().Should().HaveCount(1);
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
@@ -8,13 +7,18 @@ using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music;
using NzbDrone.Test.Common;
using System.IO.Abstractions.TestingHelpers;
using System.IO.Abstractions;
using System;
using FizzWare.NBuilder;
namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
{
[TestFixture]
public class FilterFixture : CoreTest<MediaFileService>
public class FilterFixture : FileSystemTest<MediaFileService>
{
private Artist _artist;
private DateTime _lastWrite = new DateTime(2019, 1, 1);
[SetUp]
public void Setup()
@@ -26,125 +30,252 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileServiceTests
};
}
[Test]
public void filter_should_return_all_files_if_no_existing_files()
private List<IFileInfo> GivenFiles(string[] files)
{
var files = new List<string>()
foreach (var file in files)
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
};
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Returns(new List<TrackFile>());
Subject.FilterExistingFiles(files, _artist).Should().BeEquivalentTo(files);
FileSystem.AddFile(file, new MockFileData(string.Empty) { LastWriteTime = _lastWrite });
}
return files.Select(x => DiskProvider.GetFileInfo(x)).ToList();
}
[Test]
public void filter_should_return_none_if_all_files_exist()
[TestCase(FilterFilesType.Known)]
[TestCase(FilterFilesType.Matched)]
public void filter_should_return_all_files_if_no_existing_files(FilterFilesType filter)
{
var files = new List<string>()
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
};
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Returns(files.Select(f => new TrackFile { RelativePath = Path.GetFileName(f) }).ToList());
Subject.FilterExistingFiles(files, _artist).Should().BeEmpty();
}
[Test]
public void filter_should_return_none_existing_files()
{
var files = new List<string>()
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
};
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Returns(new List<TrackFile>
var files = GivenFiles(new []
{
new TrackFile{ RelativePath = "file2.avi".AsOsAgnostic()}
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
});
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>());
Subject.FilterExistingFiles(files, _artist).Should().HaveCount(2);
Subject.FilterExistingFiles(files, _artist).Should().NotContain("C:\\file2.avi".AsOsAgnostic());
Subject.FilterUnchangedFiles(files, _artist, filter).Should().BeEquivalentTo(files);
}
[Test]
public void filter_should_return_none_existing_files_ignoring_case()
[TestCase(FilterFilesType.Known)]
[TestCase(FilterFilesType.Matched)]
public void filter_should_return_nothing_if_all_files_exist(FilterFilesType filter)
{
var files = GivenFiles(new []
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
});
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(files.Select(f => new TrackFile {
Path = f.FullName,
Modified = _lastWrite
}).ToList());
Subject.FilterUnchangedFiles(files, _artist, filter).Should().BeEmpty();
}
[TestCase(FilterFilesType.Known)]
[TestCase(FilterFilesType.Matched)]
public void filter_should_not_return_existing_files(FilterFilesType filter)
{
var files = GivenFiles(new []
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\file2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
});
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<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_ignoring_case(FilterFilesType filter)
{
WindowsOnly();
var files = new List<string>()
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\FILE2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
};
var files = GivenFiles(new []
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\FILE2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
});
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{ RelativePath = "file2.avi".AsOsAgnostic()}
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Modified = _lastWrite
}
});
Subject.FilterExistingFiles(files, _artist).Should().HaveCount(2);
Subject.FilterExistingFiles(files, _artist).Should().NotContain("C:\\file2.avi".AsOsAgnostic());
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(2);
Subject.FilterUnchangedFiles(files, _artist, filter).Select(x => x.FullName).Should().NotContain("C:\\file2.avi".AsOsAgnostic());
}
[Test]
public void filter_should_return_none_existing_files_not_ignoring_case()
[TestCase(FilterFilesType.Known)]
[TestCase(FilterFilesType.Matched)]
public void filter_should_return_none_existing_files_not_ignoring_case(FilterFilesType filter)
{
MonoOnly();
var files = new List<string>()
{
"C:\\file1.avi".AsOsAgnostic(),
"C:\\FILE2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
};
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Returns(new List<TrackFile>
var files = GivenFiles(new []
{
new TrackFile{ RelativePath = "file2.avi".AsOsAgnostic()}
"C:\\file1.avi".AsOsAgnostic(),
"C:\\FILE2.avi".AsOsAgnostic(),
"C:\\file3.avi".AsOsAgnostic()
});
Subject.FilterExistingFiles(files, _artist).Should().HaveCount(3);
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Modified = _lastWrite
}
});
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(3);
}
[Test]
public void filter_should_not_change_casing()
[TestCase(FilterFilesType.Known)]
[TestCase(FilterFilesType.Matched)]
public void filter_should_not_change_casing(FilterFilesType filter)
{
var files = new List<string>()
{
"C:\\FILE1.avi".AsOsAgnostic()
};
var files = GivenFiles(new []
{
"C:\\FILE1.avi".AsOsAgnostic()
});
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesByArtist(It.IsAny<int>()))
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>());
Subject.FilterExistingFiles(files, _artist).Should().HaveCount(1);
Subject.FilterExistingFiles(files, _artist).Should().NotContain(files.First().ToLower());
Subject.FilterExistingFiles(files, _artist).Should().Contain(files.First());
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(1);
Subject.FilterUnchangedFiles(files, _artist, filter).Select(x => x.FullName).Should().NotContain(files.First().FullName.ToLower());
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)
{
FileSystem.AddFile("C:\\file1.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file2.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file3.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
var files = FileSystem.AllFiles.Select(x => DiskProvider.GetFileInfo(x)).ToList();
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Size = 10,
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.Matched)]
public void filter_unmatched_should_return_existing_file_if_unmatched(FilterFilesType filter)
{
FileSystem.AddFile("C:\\file1.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file2.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file3.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
var files = FileSystem.AllFiles.Select(x => DiskProvider.GetFileInfo(x)).ToList();
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Size = 10,
Modified = _lastWrite,
Tracks = new List<Track>()
}
});
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)
{
FileSystem.AddFile("C:\\file1.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file2.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file3.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
var files = FileSystem.AllFiles.Select(x => DiskProvider.GetFileInfo(x)).ToList();
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Size = 10,
Modified = _lastWrite,
Tracks = Builder<Track>.CreateListOfSize(1).Build() as List<Track>
}
});
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_existing_file_if_size_changed(FilterFilesType filter)
{
FileSystem.AddFile("C:\\file1.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file2.avi".AsOsAgnostic(), new MockFileData("".PadRight(11)) { LastWriteTime = _lastWrite });
FileSystem.AddFile("C:\\file3.avi".AsOsAgnostic(), new MockFileData("".PadRight(10)) { LastWriteTime = _lastWrite });
var files = FileSystem.AllFiles.Select(x => DiskProvider.GetFileInfo(x)).ToList();
Mocker.GetMock<IMediaFileRepository>()
.Setup(c => c.GetFilesWithBasePath(It.IsAny<string>()))
.Returns(new List<TrackFile>
{
new TrackFile{
Path = "C:\\file2.avi".AsOsAgnostic(),
Size = 10,
Modified = _lastWrite
}
});
Subject.FilterUnchangedFiles(files, _artist, filter).Should().HaveCount(3);
Subject.FilterUnchangedFiles(files, _artist, filter).Select(x => x.FullName).Should().Contain("C:\\file2.avi".AsOsAgnostic());
}
}
}
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Test.MediaFiles
{
public class MediaFileTableCleanupServiceFixture : CoreTest<MediaFileTableCleanupService>
{
private const string DELETED_PATH = "ANY FILE WITH THIS PATH IS CONSIDERED DELETED!";
private readonly string DELETED_PATH = @"c:\ANY FILE WITH THIS PATH IS CONSIDERED DELETED!".AsOsAgnostic();
private List<Track> _tracks;
private Artist _artist;
@@ -56,13 +56,15 @@ namespace NzbDrone.Core.Test.MediaFiles
private List<string> FilesOnDisk(IEnumerable<TrackFile> trackFiles)
{
return trackFiles.Select(e => Path.Combine(_artist.Path, e.RelativePath)).ToList();
return trackFiles.Select(e => e.Path).ToList();
}
[Test]
public void should_skip_files_that_exist_in_disk()
public void should_skip_files_that_exist_on_disk()
{
var trackFiles = Builder<TrackFile>.CreateListOfSize(10)
.All()
.With(x => x.Path = Path.Combine(@"c:\test".AsOsAgnostic(), Path.GetRandomFileName()))
.Build();
GivenTrackFiles(trackFiles);
@@ -76,31 +78,17 @@ namespace NzbDrone.Core.Test.MediaFiles
public void should_delete_non_existent_files()
{
var trackFiles = Builder<TrackFile>.CreateListOfSize(10)
.All()
.With(x => x.Path = Path.Combine(@"c:\test".AsOsAgnostic(), Path.GetRandomFileName()))
.Random(2)
.With(c => c.RelativePath = DELETED_PATH)
.With(c => c.Path = DELETED_PATH)
.Build();
GivenTrackFiles(trackFiles);
Subject.Clean(_artist, FilesOnDisk(trackFiles.Where(e => e.RelativePath != DELETED_PATH)));
Subject.Clean(_artist, FilesOnDisk(trackFiles.Where(e => e.Path != DELETED_PATH)));
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.Is<TrackFile>(e => e.RelativePath == DELETED_PATH), DeleteMediaFileReason.MissingFromDisk), Times.Exactly(2));
}
[Test]
public void should_delete_files_that_dont_belong_to_any_tracks()
{
var trackFiles = Builder<TrackFile>.CreateListOfSize(10)
.Random(10)
.With(c => c.RelativePath = "ExistingPath")
.Build();
GivenTrackFiles(trackFiles);
GivenFilesAreNotAttachedToTrack();
Subject.Clean(_artist, FilesOnDisk(trackFiles));
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.IsAny<TrackFile>(), DeleteMediaFileReason.NoLinkedEpisodes), Times.Exactly(10));
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.Is<TrackFile>(e => e.Path == DELETED_PATH), DeleteMediaFileReason.MissingFromDisk), Times.Exactly(2));
}
[Test]
@@ -118,7 +106,7 @@ namespace NzbDrone.Core.Test.MediaFiles
{
var trackFiles = Builder<TrackFile>.CreateListOfSize(10)
.Random(10)
.With(c => c.RelativePath = "ExistingPath")
.With(c => c.Path = "/ExistingPath".AsOsAgnostic())
.Build();
GivenTrackFiles(trackFiles);
@@ -14,6 +14,7 @@ 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
{
@@ -33,7 +34,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackFileMovingServiceTests
_trackFile = Builder<TrackFile>.CreateNew()
.With(f => f.Path = null)
.With(f => f.RelativePath = @"Album\File.mp3")
.With(f => f.Path = Path.Combine(_artist.Path, @"Album\File.mp3"))
.Build();
_localtrack = Builder<LocalTrack>.CreateNew()
@@ -3,11 +3,11 @@ using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using System.IO.Abstractions;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music;
@@ -18,13 +18,14 @@ using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Profiles.Languages;
using NzbDrone.Core.MediaFiles.TrackImport.Identification;
using System.IO.Abstractions.TestingHelpers;
namespace NzbDrone.Core.Test.MediaFiles.TrackImport
{
[TestFixture]
public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker>
public class ImportDecisionMakerFixture : FileSystemTest<ImportDecisionMaker>
{
private List<string> _audioFiles;
private List<IFileInfo> _fileInfos;
private LocalTrack _localTrack;
private Artist _artist;
private AlbumRelease _albumRelease;
@@ -112,8 +113,8 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
});
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.FilterExistingFiles(It.IsAny<List<string>>(), It.IsAny<Artist>()))
.Returns((List<string> files, Artist artist) => files);
.Setup(c => c.FilterUnchangedFiles(It.IsAny<List<IFileInfo>>(), It.IsAny<Artist>(), It.IsAny<FilterFilesType>()))
.Returns((List<IFileInfo> files, Artist artist) => files);
GivenSpecifications(_albumpass1);
}
@@ -125,11 +126,12 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
private void GivenAudioFiles(IEnumerable<string> videoFiles)
{
_audioFiles = videoFiles.ToList();
foreach (var file in videoFiles)
{
FileSystem.AddFile(file, new MockFileData(string.Empty));
}
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.FilterExistingFiles(_audioFiles, It.IsAny<Artist>()))
.Returns(_audioFiles);
_fileInfos = videoFiles.Select(x => DiskProvider.GetFileInfo(x)).ToList();
}
private void GivenAugmentationSuccess()
@@ -149,7 +151,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenAugmentationSuccess();
GivenSpecifications(_albumpass1, _albumpass2, _albumpass3, _albumfail1, _albumfail2, _albumfail3);
Subject.GetImportDecisions(_audioFiles, new Artist(), null, null, downloadClientItem, null, false, false, false, false);
Subject.GetImportDecisions(_fileInfos, new Artist(), null, null, downloadClientItem, null, FilterFilesType.None, false, false, false);
_albumfail1.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalAlbumRelease>()), Times.Once());
_albumfail2.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalAlbumRelease>()), Times.Once());
@@ -166,7 +168,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenAugmentationSuccess();
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
Subject.GetImportDecisions(_audioFiles, new Artist(), null, null, downloadClientItem, null, false, false, false, false);
Subject.GetImportDecisions(_fileInfos, new Artist(), null, null, downloadClientItem, null, FilterFilesType.None, false, false, false);
_fail1.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>()), Times.Once());
_fail2.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>()), Times.Once());
@@ -184,7 +186,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumpass1, _albumpass2, _albumpass3, _albumfail1, _albumfail2, _albumfail3);
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
Subject.GetImportDecisions(_audioFiles, new Artist(), null, null, downloadClientItem, null, false, false, false, false);
Subject.GetImportDecisions(_fileInfos, new Artist(), null, null, downloadClientItem, null, FilterFilesType.None, false, false, false);
_fail1.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>()), Times.Never());
_fail2.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalTrack>()), Times.Never());
@@ -200,7 +202,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumfail1);
GivenSpecifications(_pass1);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Approved.Should().BeFalse();
}
@@ -211,7 +213,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumpass1);
GivenSpecifications(_fail1);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Approved.Should().BeFalse();
}
@@ -222,7 +224,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumpass1, _albumfail1, _albumpass2, _albumpass3);
GivenSpecifications(_pass1, _pass2, _pass3);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Approved.Should().BeFalse();
}
@@ -233,7 +235,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumpass1, _albumpass2, _albumpass3);
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Approved.Should().BeFalse();
}
@@ -245,7 +247,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenSpecifications(_albumpass1, _albumpass2, _albumpass3);
GivenSpecifications(_pass1, _pass2, _pass3);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Approved.Should().BeTrue();
}
@@ -256,7 +258,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
GivenAugmentationSuccess();
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
var result = Subject.GetImportDecisions(_audioFiles, new Artist(), false);
var result = Subject.GetImportDecisions(_fileInfos, new Artist(), FilterFilesType.None, false);
result.Single().Rejections.Should().HaveCount(3);
}
@@ -276,10 +278,10 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic()
});
Subject.GetImportDecisions(_audioFiles, _artist, false);
Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false);
Mocker.GetMock<IAugmentingService>()
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_audioFiles.Count));
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_fileInfos.Count));
ExceptionVerification.ExpectedErrors(3);
}
@@ -302,10 +304,10 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
return new List<LocalAlbumRelease> { new LocalAlbumRelease(tracks) };
});
var decisions = Subject.GetImportDecisions(_audioFiles, _artist, false);
var decisions = Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false);
Mocker.GetMock<IAugmentingService>()
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_audioFiles.Count));
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_fileInfos.Count));
decisions.Should().HaveCount(3);
decisions.First().Rejections.Should().NotBeEmpty();
@@ -323,10 +325,10 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic()
});
var decisions = Subject.GetImportDecisions(_audioFiles, _artist, false);
var decisions = Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false);
Mocker.GetMock<IAugmentingService>()
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_audioFiles.Count));
.Verify(c => c.Augment(It.IsAny<LocalTrack>(), It.IsAny<bool>()), Times.Exactly(_fileInfos.Count));
decisions.Should().HaveCount(3);
decisions.First().Rejections.Should().NotBeEmpty();
@@ -344,7 +346,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
@"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV".AsOsAgnostic()
});
Subject.GetImportDecisions(_audioFiles, _artist, false).Should().HaveCount(1);
Subject.GetImportDecisions(_fileInfos, _artist, FilterFilesType.None, false).Should().HaveCount(1);
ExceptionVerification.ExpectedErrors(1);
}
@@ -18,6 +18,7 @@ namespace NzbDrone.Core.Test.MediaFiles
{
private TrackFile _trackFile;
private LocalTrack _localTrack;
private string rootPath = @"C:\Test\Music\Artist".AsOsAgnostic();
[SetUp]
public void Setup()
@@ -25,7 +26,7 @@ namespace NzbDrone.Core.Test.MediaFiles
_localTrack = new LocalTrack();
_localTrack.Artist = new Artist
{
Path = @"C:\Test\Music\Artist".AsOsAgnostic()
Path = rootPath
};
_trackFile = Builder<TrackFile>
@@ -55,7 +56,7 @@ namespace NzbDrone.Core.Test.MediaFiles
new TrackFile
{
Id = 1,
RelativePath = @"Season 01\30.rock.s01e01.avi",
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e01.avi"),
}))
.Build()
.ToList();
@@ -70,7 +71,7 @@ namespace NzbDrone.Core.Test.MediaFiles
new TrackFile
{
Id = 1,
RelativePath = @"Season 01\30.rock.s01e01.avi",
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e01.avi"),
}))
.Build()
.ToList();
@@ -84,14 +85,14 @@ namespace NzbDrone.Core.Test.MediaFiles
new TrackFile
{
Id = 1,
RelativePath = @"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,
RelativePath = @"Season 01\30.rock.s01e02.avi",
Path = Path.Combine(rootPath, @"Season 01\30.rock.s01e02.avi"),
}))
.Build()
.ToList();