Improve code clarity and test documentation
Refactored ImageProcessor to use explicit 'this.' member access for consistency and readability. Enhanced test files with XML documentation, explicit types, modern C# syntax, and clearer Moq setups. Enabled XML doc generation for test project. Updated assembly info and cache files as a result of build changes. No functional or behavioral changes.
This commit is contained in:
@@ -13,8 +13,17 @@ namespace Jellyfin.Controller.Tests
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="BaseItemManager"/>.
|
||||
/// </summary>
|
||||
public class BaseItemManagerTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that IsMetadataFetcherEnabled checks library and server configuration options.
|
||||
/// </summary>
|
||||
/// <param name="itemType">The type of item to test.</param>
|
||||
/// <param name="fetcherName">The name of the metadata fetcher.</param>
|
||||
/// <param name="expected">The expected result.</param>
|
||||
[Theory]
|
||||
[InlineData(typeof(Book), "LibraryEnabled", true)]
|
||||
[InlineData(typeof(Book), "LibraryDisabled", false)]
|
||||
@@ -24,30 +33,36 @@ namespace Jellyfin.Controller.Tests
|
||||
{
|
||||
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
|
||||
|
||||
var libraryTypeOptions = itemType == typeof(Book)
|
||||
TypeOptions? libraryTypeOptions = itemType == typeof(Book)
|
||||
? new TypeOptions
|
||||
{
|
||||
Type = "Book",
|
||||
MetadataFetchers = new[] { "LibraryEnabled" }
|
||||
MetadataFetchers = ["LibraryEnabled"],
|
||||
}
|
||||
: null;
|
||||
|
||||
var serverConfiguration = new ServerConfiguration();
|
||||
foreach (var typeConfig in serverConfiguration.MetadataOptions)
|
||||
ServerConfiguration serverConfiguration = new();
|
||||
foreach (MetadataOptions typeConfig in serverConfiguration.MetadataOptions)
|
||||
{
|
||||
typeConfig.DisabledMetadataFetchers = new[] { "ServerDisabled" };
|
||||
typeConfig.DisabledMetadataFetchers = ["ServerDisabled"];
|
||||
}
|
||||
|
||||
var serverConfigurationManager = new Mock<IServerConfigurationManager>();
|
||||
serverConfigurationManager.Setup(scm => scm.Configuration)
|
||||
Mock<IServerConfigurationManager> serverConfigurationManager = new();
|
||||
_ = serverConfigurationManager.Setup(scm => scm.Configuration)
|
||||
.Returns(serverConfiguration);
|
||||
|
||||
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
|
||||
var actual = baseItemManager.IsMetadataFetcherEnabled(item, libraryTypeOptions, fetcherName);
|
||||
BaseItemManager baseItemManager = new(serverConfigurationManager.Object);
|
||||
bool actual = baseItemManager.IsMetadataFetcherEnabled(item, libraryTypeOptions, fetcherName);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that IsImageFetcherEnabled checks library and server configuration options.
|
||||
/// </summary>
|
||||
/// <param name="itemType">The type of item to test.</param>
|
||||
/// <param name="fetcherName">The name of the image fetcher.</param>
|
||||
/// <param name="expected">The expected result.</param>
|
||||
[Theory]
|
||||
[InlineData(typeof(Book), "LibraryEnabled", true)]
|
||||
[InlineData(typeof(Book), "LibraryDisabled", false)]
|
||||
@@ -57,26 +72,26 @@ namespace Jellyfin.Controller.Tests
|
||||
{
|
||||
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
|
||||
|
||||
var libraryTypeOptions = itemType == typeof(Book)
|
||||
TypeOptions? libraryTypeOptions = itemType == typeof(Book)
|
||||
? new TypeOptions
|
||||
{
|
||||
Type = "Book",
|
||||
ImageFetchers = new[] { "LibraryEnabled" }
|
||||
ImageFetchers = ["LibraryEnabled"],
|
||||
}
|
||||
: null;
|
||||
|
||||
var serverConfiguration = new ServerConfiguration();
|
||||
foreach (var typeConfig in serverConfiguration.MetadataOptions)
|
||||
ServerConfiguration serverConfiguration = new();
|
||||
foreach (MetadataOptions typeConfig in serverConfiguration.MetadataOptions)
|
||||
{
|
||||
typeConfig.DisabledImageFetchers = new[] { "ServerDisabled" };
|
||||
typeConfig.DisabledImageFetchers = ["ServerDisabled"];
|
||||
}
|
||||
|
||||
var serverConfigurationManager = new Mock<IServerConfigurationManager>();
|
||||
serverConfigurationManager.Setup(scm => scm.Configuration)
|
||||
Mock<IServerConfigurationManager> serverConfigurationManager = new();
|
||||
_ = serverConfigurationManager.Setup(scm => scm.Configuration)
|
||||
.Returns(serverConfiguration);
|
||||
|
||||
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
|
||||
var actual = baseItemManager.IsImageFetcherEnabled(item, libraryTypeOptions, fetcherName);
|
||||
BaseItemManager baseItemManager = new(serverConfigurationManager.Object);
|
||||
bool actual = baseItemManager.IsImageFetcherEnabled(item, libraryTypeOptions, fetcherName);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
@@ -4,124 +4,140 @@
|
||||
|
||||
namespace Jellyfin.Controller.Tests
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.IO;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="DirectoryService"/>.
|
||||
/// </summary>
|
||||
public class DirectoryServiceTests
|
||||
{
|
||||
private const string LowerCasePath = "/music/someartist";
|
||||
private const string UpperCasePath = "/music/SOMEARTIST";
|
||||
|
||||
private static readonly FileSystemMetadata[] _lowerCaseFileSystemMetadata =
|
||||
{
|
||||
private static readonly FileSystemMetadata[] LowerCaseFileSystemMetadata =
|
||||
[
|
||||
new()
|
||||
{
|
||||
FullName = LowerCasePath + "/Artwork",
|
||||
IsDirectory = true
|
||||
IsDirectory = true,
|
||||
},
|
||||
new()
|
||||
{
|
||||
FullName = LowerCasePath + "/Some Other Folder",
|
||||
IsDirectory = true
|
||||
IsDirectory = true,
|
||||
},
|
||||
new()
|
||||
{
|
||||
FullName = LowerCasePath + "/Song 2.mp3",
|
||||
IsDirectory = false
|
||||
IsDirectory = false,
|
||||
},
|
||||
new()
|
||||
{
|
||||
FullName = LowerCasePath + "/Song 3.mp3",
|
||||
IsDirectory = false
|
||||
}
|
||||
};
|
||||
IsDirectory = false,
|
||||
},
|
||||
];
|
||||
|
||||
private static readonly FileSystemMetadata[] _upperCaseFileSystemMetadata =
|
||||
{
|
||||
private static readonly FileSystemMetadata[] UpperCaseFileSystemMetadata =
|
||||
[
|
||||
new()
|
||||
{
|
||||
FullName = UpperCasePath + "/Lyrics",
|
||||
IsDirectory = true
|
||||
IsDirectory = true,
|
||||
},
|
||||
new()
|
||||
{
|
||||
FullName = UpperCasePath + "/Song 1.mp3",
|
||||
IsDirectory = false
|
||||
}
|
||||
};
|
||||
IsDirectory = false,
|
||||
},
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFileSystemEntries caches entries for paths with different casing.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFileSystemEntries_GivenPathsWithDifferentCasing_CachesAll()
|
||||
{
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(_upperCaseFileSystemMetadata);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(_lowerCaseFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(UpperCaseFileSystemMetadata);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(LowerCaseFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var upperCaseResult = directoryService.GetFileSystemEntries(UpperCasePath);
|
||||
var lowerCaseResult = directoryService.GetFileSystemEntries(LowerCasePath);
|
||||
FileSystemMetadata[] upperCaseResult = directoryService.GetFileSystemEntries(UpperCasePath);
|
||||
FileSystemMetadata[] lowerCaseResult = directoryService.GetFileSystemEntries(LowerCasePath);
|
||||
|
||||
Assert.Equal(_upperCaseFileSystemMetadata, upperCaseResult);
|
||||
Assert.Equal(_lowerCaseFileSystemMetadata, lowerCaseResult);
|
||||
Assert.Equal(UpperCaseFileSystemMetadata, upperCaseResult);
|
||||
Assert.Equal(LowerCaseFileSystemMetadata, lowerCaseResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFiles returns correct files for paths with different casing.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFiles_GivenPathsWithDifferentCasing_ReturnsCorrectFiles()
|
||||
{
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(_upperCaseFileSystemMetadata);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(_lowerCaseFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(UpperCaseFileSystemMetadata);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(LowerCaseFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var upperCaseResult = directoryService.GetFiles(UpperCasePath);
|
||||
var lowerCaseResult = directoryService.GetFiles(LowerCasePath);
|
||||
List<FileSystemMetadata> upperCaseResult = directoryService.GetFiles(UpperCasePath);
|
||||
List<FileSystemMetadata> lowerCaseResult = directoryService.GetFiles(LowerCasePath);
|
||||
|
||||
Assert.Equal(_upperCaseFileSystemMetadata.Where(f => !f.IsDirectory), upperCaseResult);
|
||||
Assert.Equal(_lowerCaseFileSystemMetadata.Where(f => !f.IsDirectory), lowerCaseResult);
|
||||
Assert.Equal(UpperCaseFileSystemMetadata.Where(f => !f.IsDirectory), upperCaseResult);
|
||||
Assert.Equal(LowerCaseFileSystemMetadata.Where(f => !f.IsDirectory), lowerCaseResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetDirectories returns correct directories for paths with different casing.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetDirectories_GivenPathsWithDifferentCasing_ReturnsCorrectDirectories()
|
||||
{
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(_upperCaseFileSystemMetadata);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(_lowerCaseFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(UpperCaseFileSystemMetadata);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(LowerCaseFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var upperCaseResult = directoryService.GetDirectories(UpperCasePath);
|
||||
var lowerCaseResult = directoryService.GetDirectories(LowerCasePath);
|
||||
List<FileSystemMetadata> upperCaseResult = directoryService.GetDirectories(UpperCasePath);
|
||||
List<FileSystemMetadata> lowerCaseResult = directoryService.GetDirectories(LowerCasePath);
|
||||
|
||||
Assert.Equal(_upperCaseFileSystemMetadata.Where(f => f.IsDirectory), upperCaseResult);
|
||||
Assert.Equal(_lowerCaseFileSystemMetadata.Where(f => f.IsDirectory), lowerCaseResult);
|
||||
Assert.Equal(UpperCaseFileSystemMetadata.Where(f => f.IsDirectory), upperCaseResult);
|
||||
Assert.Equal(LowerCaseFileSystemMetadata.Where(f => f.IsDirectory), lowerCaseResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFile returns correct file for paths with different casing.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFile_GivenFilePathsWithDifferentCasing_ReturnsCorrectFile()
|
||||
{
|
||||
const string lowerCasePath = "/music/someartist/song 1.mp3";
|
||||
var lowerCaseFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata lowerCaseFileSystemMetadata = new()
|
||||
{
|
||||
FullName = lowerCasePath,
|
||||
Exists = true
|
||||
Exists = true,
|
||||
};
|
||||
const string upperCasePath = "/music/SOMEARTIST/SONG 1.mp3";
|
||||
var upperCaseFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata upperCaseFileSystemMetadata = new()
|
||||
{
|
||||
FullName = upperCasePath,
|
||||
Exists = false
|
||||
Exists = false,
|
||||
};
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
|
||||
var lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
|
||||
var upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
|
||||
var upperCaseFileResult = directoryService.GetFile(upperCasePath);
|
||||
FileSystemMetadata? lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
|
||||
FileSystemMetadata? lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
|
||||
FileSystemMetadata? upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
|
||||
FileSystemMetadata? upperCaseFileResult = directoryService.GetFile(upperCasePath);
|
||||
|
||||
Assert.Null(lowerCaseDirResult);
|
||||
Assert.Equal(lowerCaseFileSystemMetadata, lowerCaseFileResult);
|
||||
@@ -129,32 +145,35 @@ namespace Jellyfin.Controller.Tests
|
||||
Assert.Null(upperCaseFileResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetDirectory returns correct directory for paths with different casing.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetDirectory_GivenFilePathsWithDifferentCasing_ReturnsCorrectDirectory()
|
||||
{
|
||||
const string lowerCasePath = "/music/someartist/Lyrics";
|
||||
var lowerCaseFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata lowerCaseFileSystemMetadata = new()
|
||||
{
|
||||
FullName = lowerCasePath,
|
||||
IsDirectory = true,
|
||||
Exists = true
|
||||
Exists = true,
|
||||
};
|
||||
const string upperCasePath = "/music/SOMEARTIST/LYRICS";
|
||||
var upperCaseFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata upperCaseFileSystemMetadata = new()
|
||||
{
|
||||
FullName = upperCasePath,
|
||||
IsDirectory = true,
|
||||
Exists = false
|
||||
Exists = false,
|
||||
};
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
|
||||
var lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
|
||||
var upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
|
||||
var upperCaseFileResult = directoryService.GetFile(upperCasePath);
|
||||
FileSystemMetadata? lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
|
||||
FileSystemMetadata? lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
|
||||
FileSystemMetadata? upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
|
||||
FileSystemMetadata? upperCaseFileResult = directoryService.GetFile(upperCasePath);
|
||||
|
||||
Assert.Equal(lowerCaseFileSystemMetadata, lowerCaseDirResult);
|
||||
Assert.Null(lowerCaseFileResult);
|
||||
@@ -162,92 +181,101 @@ namespace Jellyfin.Controller.Tests
|
||||
Assert.Null(upperCaseFileResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFile returns cached file when the path is already cached.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFile_GivenCachedPath_ReturnsCachedFile()
|
||||
{
|
||||
const string path = "/music/someartist/song 1.mp3";
|
||||
var cachedFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata cachedFileSystemMetadata = new()
|
||||
{
|
||||
FullName = path,
|
||||
Exists = true
|
||||
Exists = true,
|
||||
};
|
||||
var newFileSystemMetadata = new FileSystemMetadata
|
||||
FileSystemMetadata newFileSystemMetadata = new()
|
||||
{
|
||||
FullName = "/music/SOMEARTIST/song 1.mp3",
|
||||
Exists = true
|
||||
Exists = true,
|
||||
};
|
||||
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(cachedFileSystemMetadata);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(cachedFileSystemMetadata);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var result = directoryService.GetFile(path);
|
||||
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(newFileSystemMetadata);
|
||||
var secondResult = directoryService.GetFile(path);
|
||||
FileSystemMetadata? result = directoryService.GetFile(path);
|
||||
_ = fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(newFileSystemMetadata);
|
||||
FileSystemMetadata? secondResult = directoryService.GetFile(path);
|
||||
|
||||
Assert.Equivalent(cachedFileSystemMetadata, result);
|
||||
Assert.Equivalent(cachedFileSystemMetadata, secondResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFilePaths returns only cached paths when clear is not called.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFilePaths_GivenCachedFilePathWithoutClear_ReturnsOnlyCachedPaths()
|
||||
{
|
||||
const string path = "/music/someartist";
|
||||
|
||||
var cachedPaths = new[]
|
||||
{
|
||||
string[] cachedPaths =
|
||||
[
|
||||
"/music/someartist/song 1.mp3",
|
||||
"/music/someartist/song 2.mp3",
|
||||
"/music/someartist/song 3.mp3",
|
||||
"/music/someartist/song 4.mp3",
|
||||
};
|
||||
var newPaths = new[]
|
||||
{
|
||||
];
|
||||
string[] newPaths =
|
||||
[
|
||||
"/music/someartist/song 5.mp3",
|
||||
"/music/someartist/song 6.mp3",
|
||||
"/music/someartist/song 7.mp3",
|
||||
"/music/someartist/song 8.mp3",
|
||||
};
|
||||
];
|
||||
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var result = directoryService.GetFilePaths(path);
|
||||
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
|
||||
var secondResult = directoryService.GetFilePaths(path);
|
||||
IReadOnlyList<string> result = directoryService.GetFilePaths(path);
|
||||
_ = fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
|
||||
IReadOnlyList<string> secondResult = directoryService.GetFilePaths(path);
|
||||
|
||||
Assert.Equal(cachedPaths, result);
|
||||
Assert.Equal(cachedPaths, secondResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that GetFilePaths returns new paths when clear is called.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFilePaths_GivenCachedFilePathWithClear_ReturnsNewPaths()
|
||||
{
|
||||
const string path = "/music/someartist";
|
||||
|
||||
var cachedPaths = new[]
|
||||
{
|
||||
string[] cachedPaths =
|
||||
[
|
||||
"/music/someartist/song 1.mp3",
|
||||
"/music/someartist/song 2.mp3",
|
||||
"/music/someartist/song 3.mp3",
|
||||
"/music/someartist/song 4.mp3",
|
||||
};
|
||||
var newPaths = new[]
|
||||
{
|
||||
];
|
||||
string[] newPaths =
|
||||
[
|
||||
"/music/someartist/song 5.mp3",
|
||||
"/music/someartist/song 6.mp3",
|
||||
"/music/someartist/song 7.mp3",
|
||||
"/music/someartist/song 8.mp3",
|
||||
};
|
||||
];
|
||||
|
||||
var fileSystemMock = new Mock<IFileSystem>();
|
||||
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
|
||||
var directoryService = new DirectoryService(fileSystemMock.Object);
|
||||
Mock<IFileSystem> fileSystemMock = new();
|
||||
_ = fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
|
||||
DirectoryService directoryService = new(fileSystemMock.Object);
|
||||
|
||||
var result = directoryService.GetFilePaths(path);
|
||||
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
|
||||
var secondResult = directoryService.GetFilePaths(path, true);
|
||||
IReadOnlyList<string> result = directoryService.GetFilePaths(path);
|
||||
_ = fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
|
||||
IReadOnlyList<string> secondResult = directoryService.GetFilePaths(path, true);
|
||||
|
||||
Assert.Equal(cachedPaths, result);
|
||||
Assert.Equal(newPaths, secondResult);
|
||||
|
||||
@@ -2,49 +2,67 @@
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Jellyfin.Controller.Tests.Entities;
|
||||
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
public class BaseItemTests
|
||||
namespace Jellyfin.Controller.Tests.Entities
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("", "")]
|
||||
[InlineData("1", "0000000001")]
|
||||
[InlineData("t", "t")]
|
||||
[InlineData("test", "test")]
|
||||
[InlineData("test1", "test0000000001")]
|
||||
[InlineData("1test 2", "0000000001test 0000000002")]
|
||||
public void BaseItem_ModifySortChunks_Valid(string input, string expected)
|
||||
=> Assert.Equal(expected, BaseItem.ModifySortChunks(input));
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
[Theory]
|
||||
[InlineData("/Movies/Ted/Ted.mp4", "/Movies/Ted/Ted - Unrated Edition.mp4", "Ted", "Unrated Edition")]
|
||||
[InlineData("/Movies/Deadpool 2 (2018)/Deadpool 2 (2018).mkv", "/Movies/Deadpool 2 (2018)/Deadpool 2 (2018) - Super Duper Cut.mkv", "Deadpool 2 (2018)", "Super Duper Cut")]
|
||||
public void GetMediaSourceName_Valid(string primaryPath, string altPath, string name, string altName)
|
||||
/// <summary>
|
||||
/// Tests for <see cref="BaseItem"/>.
|
||||
/// </summary>
|
||||
public class BaseItemTests
|
||||
{
|
||||
var mediaSourceManager = new Mock<IMediaSourceManager>();
|
||||
mediaSourceManager.Setup(x => x.GetPathProtocol(It.IsAny<string>()))
|
||||
.Returns((string x) => MediaProtocol.File);
|
||||
BaseItem.MediaSourceManager = mediaSourceManager.Object;
|
||||
|
||||
var video = new Video()
|
||||
/// <summary>
|
||||
/// Tests that ModifySortChunks correctly modifies sort chunks.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string.</param>
|
||||
/// <param name="expected">The expected output string.</param>
|
||||
[Theory]
|
||||
[InlineData("", "")]
|
||||
[InlineData("1", "0000000001")]
|
||||
[InlineData("t", "t")]
|
||||
[InlineData("test", "test")]
|
||||
[InlineData("test1", "test0000000001")]
|
||||
[InlineData("1test 2", "0000000001test 0000000002")]
|
||||
public void BaseItem_ModifySortChunks_Valid(string input, string expected)
|
||||
{
|
||||
Path = primaryPath
|
||||
};
|
||||
Assert.Equal(expected, BaseItem.ModifySortChunks(input));
|
||||
}
|
||||
|
||||
var videoAlt = new Video()
|
||||
/// <summary>
|
||||
/// Tests that GetMediaSourceName returns the correct name for media sources.
|
||||
/// </summary>
|
||||
/// <param name="primaryPath">The primary path.</param>
|
||||
/// <param name="altPath">The alternate path.</param>
|
||||
/// <param name="name">The expected name for the primary path.</param>
|
||||
/// <param name="altName">The expected name for the alternate path.</param>
|
||||
[Theory]
|
||||
[InlineData("/Movies/Ted/Ted.mp4", "/Movies/Ted/Ted - Unrated Edition.mp4", "Ted", "Unrated Edition")]
|
||||
[InlineData("/Movies/Deadpool 2 (2018)/Deadpool 2 (2018).mkv", "/Movies/Deadpool 2 (2018)/Deadpool 2 (2018) - Super Duper Cut.mkv", "Deadpool 2 (2018)", "Super Duper Cut")]
|
||||
public void GetMediaSourceName_Valid(string primaryPath, string altPath, string name, string altName)
|
||||
{
|
||||
Path = altPath,
|
||||
};
|
||||
Mock<IMediaSourceManager> mediaSourceManager = new();
|
||||
_ = mediaSourceManager.Setup(x => x.GetPathProtocol(It.IsAny<string>()))
|
||||
.Returns((string x) => MediaProtocol.File);
|
||||
BaseItem.MediaSourceManager = mediaSourceManager.Object;
|
||||
|
||||
video.LocalAlternateVersions = [videoAlt.Path];
|
||||
Video video = new()
|
||||
{
|
||||
Path = primaryPath,
|
||||
};
|
||||
|
||||
Assert.Equal(name, video.GetMediaSourceName(video));
|
||||
Assert.Equal(altName, video.GetMediaSourceName(videoAlt));
|
||||
Video videoAlt = new()
|
||||
{
|
||||
Path = altPath,
|
||||
};
|
||||
|
||||
video.LocalAlternateVersions = [videoAlt.Path];
|
||||
|
||||
Assert.Equal(name, video.GetMediaSourceName(video));
|
||||
Assert.Equal(altName, video.GetMediaSourceName(videoAlt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{462584F7-5023-4019-9EAC-B98CA458C0A0}</ProjectGuid>
|
||||
<TargetFramework>net11.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user