1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
using System;
using System.IO;
using Emby.Naming.Common;
using Emby.Naming.Video;
using Emby.Server.Implementations.Library;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Moq;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Library;
public class CoreResolutionIgnoreRuleTest
{
private readonly CoreResolutionIgnoreRule _rule;
private readonly NamingOptions _namingOptions;
private readonly Mock<IServerApplicationPaths> _appPathsMock;
public CoreResolutionIgnoreRuleTest()
{
_namingOptions = new NamingOptions();
_namingOptions.AllExtrasTypesFolderNames.TryAdd("extras", ExtraType.Trailer);
_appPathsMock = new Mock<IServerApplicationPaths>();
_appPathsMock.SetupGet(x => x.RootFolderPath).Returns("/server/root");
_rule = new CoreResolutionIgnoreRule(_namingOptions, _appPathsMock.Object);
}
private FileSystemMetadata MakeFileSystemMetadata(string fullName, bool isDirectory = false)
=> new FileSystemMetadata { FullName = fullName, Name = Path.GetFileName(fullName), IsDirectory = isDirectory };
private BaseItem MakeParent(string name = "Parent", bool isTopParent = false, Type? type = null)
{
return type switch
{
Type t when t == typeof(Folder) => CreateMock<Folder>(name, isTopParent).Object,
Type t when t == typeof(AggregateFolder) => CreateMock<AggregateFolder>(name, isTopParent).Object,
Type t when t == typeof(UserRootFolder) => CreateMock<UserRootFolder>(name, isTopParent).Object,
_ => CreateMock<BaseItem>(name, isTopParent).Object
};
}
private static Mock<T> CreateMock<T>(string name, bool isTopParent)
where T : BaseItem
{
var mock = new Mock<T>();
mock.SetupGet(p => p.Name).Returns(name);
mock.SetupGet(p => p.IsTopParent).Returns(isTopParent);
return mock;
}
[Fact]
public void TestApplicationFolder()
{
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("/server/root/extras", isDirectory: true),
null));
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("/server/root/small.jpg"),
null));
}
[Fact]
public void TestTopLevelDirectory()
{
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("Series/Extras", true),
MakeParent(type: typeof(AggregateFolder))));
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("Series/Extras/Extras", true),
MakeParent(isTopParent: true)));
}
[Fact]
public void TestIgnorePatterns()
{
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("/Media/big.jpg"),
MakeParent()));
Assert.True(_rule.ShouldIgnore(
MakeFileSystemMetadata("/Media/small.jpg"),
MakeParent()));
}
[Fact]
public void TestExtrasTypesFolderNames()
{
FileSystemMetadata fileSystemMetadata = MakeFileSystemMetadata("/Movies/Up/extras", true);
Assert.False(_rule.ShouldIgnore(
fileSystemMetadata,
MakeParent(type: typeof(AggregateFolder))));
Assert.False(_rule.ShouldIgnore(
fileSystemMetadata,
MakeParent(type: typeof(UserRootFolder))));
Assert.False(_rule.ShouldIgnore(
fileSystemMetadata,
null));
Assert.True(_rule.ShouldIgnore(
fileSystemMetadata,
MakeParent()));
Assert.True(_rule.ShouldIgnore(
fileSystemMetadata,
MakeParent(type: typeof(Folder))));
}
[Fact]
public void TestThemeSong()
{
Assert.False(_rule.ShouldIgnore(
MakeFileSystemMetadata("/Movies/Up/intro.mp3"),
MakeParent()));
Assert.True(_rule.ShouldIgnore(
MakeFileSystemMetadata("/Movies/Up/theme.mp3"),
MakeParent()));
}
}
|