aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs4
-rw-r--r--tests/Jellyfin.Api.Tests/Jellyfin.Api.Tests.csproj11
-rw-r--r--tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs43
-rw-r--r--tests/Jellyfin.Common.Tests/Jellyfin.Common.Tests.csproj7
-rw-r--r--tests/Jellyfin.Controller.Tests/Jellyfin.Controller.Tests.csproj7
-rw-r--r--tests/Jellyfin.MediaEncoding.Tests/Jellyfin.MediaEncoding.Tests.csproj7
-rw-r--r--tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs19
-rw-r--r--tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj21
-rw-r--r--tests/Jellyfin.Naming.Tests/Jellyfin.Naming.Tests.csproj19
-rw-r--r--tests/Jellyfin.Naming.Tests/Music/MultiDiscAlbumTests.cs90
-rw-r--r--tests/Jellyfin.Naming.Tests/Subtitles/SubtitleParserTests.cs49
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/AbsoluteEpisodeNumberTests.cs2
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/DailyEpisodeTests.cs14
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/EpisodeNumberWithoutSeasonTests.cs3
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/EpisodePathParserTest.cs3
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/EpisodeWithoutSeasonTests.cs6
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/SeasonNumberTests.cs2
-rw-r--r--tests/Jellyfin.Naming.Tests/TV/SimpleEpisodeTests.cs6
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/BaseVideoTest.cs13
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs1
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs2
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/Format3DTests.cs63
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs48
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/StackTests.cs16
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/StubTests.cs14
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs26
-rw-r--r--tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs458
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/HttpServer/ResponseFilterTests.cs18
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj7
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/IgnorePatternsTests.cs21
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs27
-rw-r--r--tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs49
-rw-r--r--tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs120
-rw-r--r--tests/MediaBrowser.Api.Tests/MediaBrowser.Api.Tests.csproj33
-rw-r--r--tests/jellyfin-tests.ruleset22
35 files changed, 767 insertions, 484 deletions
diff --git a/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs b/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs
index 3b3d03c8b..437dfa410 100644
--- a/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs
+++ b/tests/Jellyfin.Api.Tests/Auth/CustomAuthenticationHandlerTests.cs
@@ -88,7 +88,9 @@ namespace Jellyfin.Api.Tests.Auth
var authenticateResult = await _sut.AuthenticateAsync();
Assert.False(authenticateResult.Succeeded);
- Assert.Equal("Invalid user", authenticateResult.Failure.Message);
+ Assert.True(authenticateResult.None);
+ // TODO return when legacy API is removed.
+ // Assert.Equal("Invalid user", authenticateResult.Failure.Message);
}
[Fact]
diff --git a/tests/Jellyfin.Api.Tests/Jellyfin.Api.Tests.csproj b/tests/Jellyfin.Api.Tests/Jellyfin.Api.Tests.csproj
index b159db2bd..269ff0986 100644
--- a/tests/Jellyfin.Api.Tests/Jellyfin.Api.Tests.csproj
+++ b/tests/Jellyfin.Api.Tests/Jellyfin.Api.Tests.csproj
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{A2FD0A10-8F62-4F9D-B171-FFDF9F0AFA9D}</ProjectGuid>
+ </PropertyGroup>
+
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
@@ -11,12 +16,12 @@
<PackageReference Include="AutoFixture" Version="4.11.0" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.11.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.11.0" />
- <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.3" />
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.5" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
- <PackageReference Include="Moq" Version="4.13.1" />
+ <PackageReference Include="Moq" Version="4.14.1" />
</ItemGroup>
<ItemGroup>
diff --git a/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs b/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs
new file mode 100644
index 000000000..8bf613f05
--- /dev/null
+++ b/tests/Jellyfin.Common.Tests/Extensions/StringExtensionsTests.cs
@@ -0,0 +1,43 @@
+using System;
+using MediaBrowser.Common.Extensions;
+using Xunit;
+
+namespace Jellyfin.Common.Tests.Extensions
+{
+ public class StringExtensionsTests
+ {
+ [Theory]
+ [InlineData("", 'q', "")]
+ [InlineData("Banana split", ' ', "Banana")]
+ [InlineData("Banana split", 'q', "Banana split")]
+ public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
+ {
+ var result = str.AsSpan().LeftPart(needle).ToString();
+ Assert.Equal(expectedResult, result);
+ }
+
+ [Theory]
+ [InlineData("", "", "")]
+ [InlineData("", "q", "")]
+ [InlineData("Banana split", "", "")]
+ [InlineData("Banana split", " ", "Banana")]
+ [InlineData("Banana split test", " split", "Banana")]
+ public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string expectedResult)
+ {
+ var result = str.AsSpan().LeftPart(needle).ToString();
+ Assert.Equal(expectedResult, result);
+ }
+
+ [Theory]
+ [InlineData("", "", StringComparison.Ordinal, "")]
+ [InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
+ [InlineData("Banana split test", " split", StringComparison.Ordinal, "Banana")]
+ [InlineData("Banana split test", " Split", StringComparison.Ordinal, "Banana split test")]
+ [InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "Banana split test")]
+ public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string expectedResult)
+ {
+ var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
+ Assert.Equal(expectedResult, result);
+ }
+ }
+}
diff --git a/tests/Jellyfin.Common.Tests/Jellyfin.Common.Tests.csproj b/tests/Jellyfin.Common.Tests/Jellyfin.Common.Tests.csproj
index 81a2242e7..003e29a66 100644
--- a/tests/Jellyfin.Common.Tests/Jellyfin.Common.Tests.csproj
+++ b/tests/Jellyfin.Common.Tests/Jellyfin.Common.Tests.csproj
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{DF194677-DFD3-42AF-9F75-D44D5A416478}</ProjectGuid>
+ </PropertyGroup>
+
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
@@ -8,7 +13,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
diff --git a/tests/Jellyfin.Controller.Tests/Jellyfin.Controller.Tests.csproj b/tests/Jellyfin.Controller.Tests/Jellyfin.Controller.Tests.csproj
index 30994dee6..3c806be17 100644
--- a/tests/Jellyfin.Controller.Tests/Jellyfin.Controller.Tests.csproj
+++ b/tests/Jellyfin.Controller.Tests/Jellyfin.Controller.Tests.csproj
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{462584F7-5023-4019-9EAC-B98CA458C0A0}</ProjectGuid>
+ </PropertyGroup>
+
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
@@ -8,7 +13,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
diff --git a/tests/Jellyfin.MediaEncoding.Tests/Jellyfin.MediaEncoding.Tests.csproj b/tests/Jellyfin.MediaEncoding.Tests/Jellyfin.MediaEncoding.Tests.csproj
index 78a020ad5..c2e7bf54c 100644
--- a/tests/Jellyfin.MediaEncoding.Tests/Jellyfin.MediaEncoding.Tests.csproj
+++ b/tests/Jellyfin.MediaEncoding.Tests/Jellyfin.MediaEncoding.Tests.csproj
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{28464062-0939-4AA7-9F7B-24DDDA61A7C0}</ProjectGuid>
+ </PropertyGroup>
+
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
@@ -14,7 +19,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
diff --git a/tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs b/tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs
new file mode 100644
index 000000000..51633e157
--- /dev/null
+++ b/tests/Jellyfin.Model.Tests/Extensions/StringHelperTests.cs
@@ -0,0 +1,19 @@
+using System;
+using MediaBrowser.Model.Extensions;
+using Xunit;
+
+namespace Jellyfin.Model.Tests.Extensions
+{
+ public class StringHelperTests
+ {
+ [Theory]
+ [InlineData("", "")]
+ [InlineData("banana", "Banana")]
+ [InlineData("Banana", "Banana")]
+ [InlineData("ä", "Ä")]
+ public void StringHelper_ValidArgs_Success(string input, string expectedResult)
+ {
+ Assert.Equal(expectedResult, StringHelper.FirstToUpper(input));
+ }
+ }
+}
diff --git a/tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj b/tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj
new file mode 100644
index 000000000..f6c327498
--- /dev/null
+++ b/tests/Jellyfin.Model.Tests/Jellyfin.Model.Tests.csproj
@@ -0,0 +1,21 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+ <IsPackable>false</IsPackable>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="xunit" Version="2.4.1" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
+ <PackageReference Include="coverlet.collector" Version="1.2.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="../../MediaBrowser.Model/MediaBrowser.Model.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/tests/Jellyfin.Naming.Tests/Jellyfin.Naming.Tests.csproj b/tests/Jellyfin.Naming.Tests/Jellyfin.Naming.Tests.csproj
index f404b3e46..43b34dcee 100644
--- a/tests/Jellyfin.Naming.Tests/Jellyfin.Naming.Tests.csproj
+++ b/tests/Jellyfin.Naming.Tests/Jellyfin.Naming.Tests.csproj
@@ -1,4 +1,9 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{3998657B-1CCC-49DD-A19F-275DC8495F57}</ProjectGuid>
+ </PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
@@ -7,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
@@ -16,5 +21,15 @@
<ItemGroup>
<ProjectReference Include="..\..\Emby.Naming\Emby.Naming.csproj" />
</ItemGroup>
+
+ <!-- Code Analyzers-->
+ <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
</Project>
diff --git a/tests/Jellyfin.Naming.Tests/Music/MultiDiscAlbumTests.cs b/tests/Jellyfin.Naming.Tests/Music/MultiDiscAlbumTests.cs
index 9a4b0b542..c9a295a4c 100644
--- a/tests/Jellyfin.Naming.Tests/Music/MultiDiscAlbumTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Music/MultiDiscAlbumTests.cs
@@ -6,61 +6,45 @@ namespace Jellyfin.Naming.Tests.Music
{
public class MultiDiscAlbumTests
{
- [Fact]
- public void TestMultiDiscAlbums()
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
+ [Theory]
+ [InlineData("", false)]
+ [InlineData("C:/", false)]
+ [InlineData("/home/", false)]
+ [InlineData(@"blah blah", false)]
+ [InlineData(@"D:/music/weezer/03 Pinkerton", false)]
+ [InlineData(@"D:/music/michael jackson/Bad (2012 Remaster)", false)]
+ [InlineData(@"cd1", true)]
+ [InlineData(@"disc18", true)]
+ [InlineData(@"disk10", true)]
+ [InlineData(@"vol7", true)]
+ [InlineData(@"volume1", true)]
+ [InlineData(@"cd 1", true)]
+ [InlineData(@"disc 1", true)]
+ [InlineData(@"disk 1", true)]
+ [InlineData(@"disk", false)]
+ [InlineData(@"disk ·", false)]
+ [InlineData(@"disk a", false)]
+ [InlineData(@"disk volume", false)]
+ [InlineData(@"disc disc", false)]
+ [InlineData(@"disk disc 6", false)]
+ [InlineData(@"cd - 1", true)]
+ [InlineData(@"disc- 1", true)]
+ [InlineData(@"disk - 1", true)]
+ [InlineData(@"Disc 01 (Hugo Wolf · 24 Lieder)", true)]
+ [InlineData(@"Disc 04 (Encores and Folk Songs)", true)]
+ [InlineData(@"Disc04 (Encores and Folk Songs)", true)]
+ [InlineData(@"Disc 04(Encores and Folk Songs)", true)]
+ [InlineData(@"Disc04(Encores and Folk Songs)", true)]
+ [InlineData(@"D:/Video/MBTestLibrary/VideoTest/music/.38 special/anth/Disc 2", true)]
+ [InlineData(@"[1985] Opportunities (Let's make lots of money) (1985)", false)]
+ [InlineData(@"Blah 04(Encores and Folk Songs)", false)]
+ public void AlbumParser_MultidiscPath_Identifies(string path, bool result)
{
- Assert.False(IsMultiDiscAlbumFolder(@"blah blah"));
- Assert.False(IsMultiDiscAlbumFolder(@"D:/music/weezer/03 Pinkerton"));
- Assert.False(IsMultiDiscAlbumFolder(@"D:/music/michael jackson/Bad (2012 Remaster)"));
+ var parser = new AlbumParser(_namingOptions);
- Assert.True(IsMultiDiscAlbumFolder(@"cd1"));
- Assert.True(IsMultiDiscAlbumFolder(@"disc18"));
- Assert.True(IsMultiDiscAlbumFolder(@"disk10"));
- Assert.True(IsMultiDiscAlbumFolder(@"vol7"));
- Assert.True(IsMultiDiscAlbumFolder(@"volume1"));
-
- Assert.True(IsMultiDiscAlbumFolder(@"cd 1"));
- Assert.True(IsMultiDiscAlbumFolder(@"disc 1"));
- Assert.True(IsMultiDiscAlbumFolder(@"disk 1"));
-
- Assert.False(IsMultiDiscAlbumFolder(@"disk"));
- Assert.False(IsMultiDiscAlbumFolder(@"disk ·"));
- Assert.False(IsMultiDiscAlbumFolder(@"disk a"));
-
- Assert.False(IsMultiDiscAlbumFolder(@"disk volume"));
- Assert.False(IsMultiDiscAlbumFolder(@"disc disc"));
- Assert.False(IsMultiDiscAlbumFolder(@"disk disc 6"));
-
- Assert.True(IsMultiDiscAlbumFolder(@"cd - 1"));
- Assert.True(IsMultiDiscAlbumFolder(@"disc- 1"));
- Assert.True(IsMultiDiscAlbumFolder(@"disk - 1"));
-
- Assert.True(IsMultiDiscAlbumFolder(@"Disc 01 (Hugo Wolf · 24 Lieder)"));
- Assert.True(IsMultiDiscAlbumFolder(@"Disc 04 (Encores and Folk Songs)"));
- Assert.True(IsMultiDiscAlbumFolder(@"Disc04 (Encores and Folk Songs)"));
- Assert.True(IsMultiDiscAlbumFolder(@"Disc 04(Encores and Folk Songs)"));
- Assert.True(IsMultiDiscAlbumFolder(@"Disc04(Encores and Folk Songs)"));
-
- Assert.True(IsMultiDiscAlbumFolder(@"D:/Video/MBTestLibrary/VideoTest/music/.38 special/anth/Disc 2"));
- }
-
- [Fact]
- public void TestMultiDiscAlbums1()
- {
- Assert.False(IsMultiDiscAlbumFolder(@"[1985] Opportunities (Let's make lots of money) (1985)"));
- }
-
- [Fact]
- public void TestMultiDiscAlbums2()
- {
- Assert.False(IsMultiDiscAlbumFolder(@"Blah 04(Encores and Folk Songs)"));
- }
-
- private bool IsMultiDiscAlbumFolder(string path)
- {
- var parser = new AlbumParser(new NamingOptions());
-
- return parser.IsMultiPart(path);
+ Assert.Equal(result, parser.IsMultiPart(path));
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/Subtitles/SubtitleParserTests.cs b/tests/Jellyfin.Naming.Tests/Subtitles/SubtitleParserTests.cs
index 41da889c2..d11809de1 100644
--- a/tests/Jellyfin.Naming.Tests/Subtitles/SubtitleParserTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Subtitles/SubtitleParserTests.cs
@@ -1,4 +1,5 @@
-using Emby.Naming.Common;
+using System;
+using Emby.Naming.Common;
using Emby.Naming.Subtitles;
using Xunit;
@@ -6,34 +7,40 @@ namespace Jellyfin.Naming.Tests.Subtitles
{
public class SubtitleParserTests
{
- private SubtitleParser GetParser()
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
+ [Theory]
+ [InlineData("The Skin I Live In (2011).srt", null, false, false)]
+ [InlineData("The Skin I Live In (2011).eng.srt", "eng", false, false)]
+ [InlineData("The Skin I Live In (2011).eng.default.srt", "eng", true, false)]
+ [InlineData("The Skin I Live In (2011).eng.forced.srt", "eng", false, true)]
+ [InlineData("The Skin I Live In (2011).eng.foreign.srt", "eng", false, true)]
+ [InlineData("The Skin I Live In (2011).eng.default.foreign.srt", "eng", true, true)]
+ [InlineData("The Skin I Live In (2011).default.foreign.eng.srt", "eng", true, true)]
+ public void SubtitleParser_ValidFileName_Parses(string input, string language, bool isDefault, bool isForced)
{
- var options = new NamingOptions();
+ var parser = new SubtitleParser(_namingOptions);
- return new SubtitleParser(options);
- }
+ var result = parser.ParseFile(input);
- [Fact]
- public void TestSubtitles()
- {
- Test("The Skin I Live In (2011).srt", null, false, false);
- Test("The Skin I Live In (2011).eng.srt", "eng", false, false);
- Test("The Skin I Live In (2011).eng.default.srt", "eng", true, false);
- Test("The Skin I Live In (2011).eng.forced.srt", "eng", false, true);
- Test("The Skin I Live In (2011).eng.foreign.srt", "eng", false, true);
- Test("The Skin I Live In (2011).eng.default.foreign.srt", "eng", true, true);
- Test("The Skin I Live In (2011).default.foreign.eng.srt", "eng", true, true);
+ Assert.Equal(language, result?.Language, true);
+ Assert.Equal(isDefault, result?.IsDefault);
+ Assert.Equal(isForced, result?.IsForced);
}
- private void Test(string input, string language, bool isDefault, bool isForced)
+ [Theory]
+ [InlineData("The Skin I Live In (2011).mp4")]
+ public void SubtitleParser_InvalidFileName_ReturnsNull(string input)
{
- var parser = GetParser();
+ var parser = new SubtitleParser(_namingOptions);
- var result = parser.ParseFile(input);
+ Assert.Null(parser.ParseFile(input));
+ }
- Assert.Equal(language, result.Language, true);
- Assert.Equal(isDefault, result.IsDefault);
- Assert.Equal(isForced, result.IsForced);
+ [Fact]
+ public void SubtitleParser_EmptyFileName_ThrowsArgumentException()
+ {
+ Assert.Throws<ArgumentException>(() => new SubtitleParser(_namingOptions).ParseFile(string.Empty));
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/AbsoluteEpisodeNumberTests.cs b/tests/Jellyfin.Naming.Tests/TV/AbsoluteEpisodeNumberTests.cs
index 553d06681..356ba216d 100644
--- a/tests/Jellyfin.Naming.Tests/TV/AbsoluteEpisodeNumberTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/AbsoluteEpisodeNumberTests.cs
@@ -21,7 +21,7 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(options)
.Resolve(path, false, null, null, true);
- Assert.Equal(episodeNumber, result.EpisodeNumber);
+ Assert.Equal(episodeNumber, result?.EpisodeNumber);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/DailyEpisodeTests.cs b/tests/Jellyfin.Naming.Tests/TV/DailyEpisodeTests.cs
index 6ecffe80b..2937914b9 100644
--- a/tests/Jellyfin.Naming.Tests/TV/DailyEpisodeTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/DailyEpisodeTests.cs
@@ -6,8 +6,6 @@ namespace Jellyfin.Naming.Tests.TV
{
public class DailyEpisodeTests
{
-
-
[Theory]
[InlineData(@"/server/anything_1996.11.14.mp4", "anything", 1996, 11, 14)]
[InlineData(@"/server/anything_1996-11-14.mp4", "anything", 1996, 11, 14)]
@@ -23,12 +21,12 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(options)
.Resolve(path, false);
- Assert.Null(result.SeasonNumber);
- Assert.Null(result.EpisodeNumber);
- Assert.Equal(year, result.Year);
- Assert.Equal(month, result.Month);
- Assert.Equal(day, result.Day);
- Assert.Equal(seriesName, result.SeriesName, true);
+ Assert.Null(result?.SeasonNumber);
+ Assert.Null(result?.EpisodeNumber);
+ Assert.Equal(year, result?.Year);
+ Assert.Equal(month, result?.Month);
+ Assert.Equal(day, result?.Day);
+ Assert.Equal(seriesName, result?.SeriesName, true);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/EpisodeNumberWithoutSeasonTests.cs b/tests/Jellyfin.Naming.Tests/TV/EpisodeNumberWithoutSeasonTests.cs
index 0c7d9520e..8bd1a43d6 100644
--- a/tests/Jellyfin.Naming.Tests/TV/EpisodeNumberWithoutSeasonTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/EpisodeNumberWithoutSeasonTests.cs
@@ -6,7 +6,6 @@ namespace Jellyfin.Naming.Tests.TV
{
public class EpisodeNumberWithoutSeasonTests
{
-
[Theory]
[InlineData(8, @"The Simpsons/The Simpsons.S25E08.Steal this episode.mp4")]
[InlineData(2, @"The Simpsons/The Simpsons - 02 - Ep Name.avi")]
@@ -30,7 +29,7 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(options)
.Resolve(path, false);
- Assert.Equal(episodeNumber, result.EpisodeNumber);
+ Assert.Equal(episodeNumber, result?.EpisodeNumber);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/EpisodePathParserTest.cs b/tests/Jellyfin.Naming.Tests/TV/EpisodePathParserTest.cs
index 4b5606715..03aeb7f76 100644
--- a/tests/Jellyfin.Naming.Tests/TV/EpisodePathParserTest.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/EpisodePathParserTest.cs
@@ -1,4 +1,4 @@
-using Emby.Naming.Common;
+using Emby.Naming.Common;
using Emby.Naming.TV;
using Xunit;
@@ -35,7 +35,6 @@ namespace Jellyfin.Naming.Tests.TV
// TODO: [InlineData("Watchmen (2019)/Watchmen 1x03 [WEBDL-720p][EAC3 5.1][h264][-TBS] - She Was Killed by Space Junk.mkv", "Watchmen (2019)", 1, 3)]
// TODO: [InlineData("/The.Legend.of.Condor.Heroes.2017.V2.web-dl.1080p.h264.aac-hdctv/The.Legend.of.Condor.Heroes.2017.E07.V2.web-dl.1080p.h264.aac-hdctv.mkv", "The Legend of Condor Heroes 2017", 1, 7)]
public void ParseEpisodesCorrectly(string path, string name, int season, int episode)
-
{
NamingOptions o = new NamingOptions();
EpisodePathParser p = new EpisodePathParser(o);
diff --git a/tests/Jellyfin.Naming.Tests/TV/EpisodeWithoutSeasonTests.cs b/tests/Jellyfin.Naming.Tests/TV/EpisodeWithoutSeasonTests.cs
index 364eb7ff8..d0418a49e 100644
--- a/tests/Jellyfin.Naming.Tests/TV/EpisodeWithoutSeasonTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/EpisodeWithoutSeasonTests.cs
@@ -19,9 +19,9 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(options)
.Resolve(path, false);
- Assert.Equal(seasonNumber, result.SeasonNumber);
- Assert.Equal(episodeNumber, result.EpisodeNumber);
- Assert.Equal(seriesName, result.SeriesName, true);
+ Assert.Equal(seasonNumber, result?.SeasonNumber);
+ Assert.Equal(episodeNumber, result?.EpisodeNumber);
+ Assert.Equal(seriesName, result?.SeriesName, ignoreCase: true);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/SeasonNumberTests.cs b/tests/Jellyfin.Naming.Tests/TV/SeasonNumberTests.cs
index 9eaf897b9..4837e3a3b 100644
--- a/tests/Jellyfin.Naming.Tests/TV/SeasonNumberTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/SeasonNumberTests.cs
@@ -59,7 +59,7 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(_namingOptions)
.Resolve(path, false);
- Assert.Equal(expected, result.SeasonNumber);
+ Assert.Equal(expected, result?.SeasonNumber);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/TV/SimpleEpisodeTests.cs b/tests/Jellyfin.Naming.Tests/TV/SimpleEpisodeTests.cs
index de253ce37..40b41b9f3 100644
--- a/tests/Jellyfin.Naming.Tests/TV/SimpleEpisodeTests.cs
+++ b/tests/Jellyfin.Naming.Tests/TV/SimpleEpisodeTests.cs
@@ -31,9 +31,9 @@ namespace Jellyfin.Naming.Tests.TV
var result = new EpisodeResolver(options)
.Resolve(path, false);
- Assert.Equal(seasonNumber, result.SeasonNumber);
- Assert.Equal(episodeNumber, result.EpisodeNumber);
- Assert.Equal(seriesName, result.SeriesName, true);
+ Assert.Equal(seasonNumber, result?.SeasonNumber);
+ Assert.Equal(episodeNumber, result?.EpisodeNumber);
+ Assert.Equal(seriesName, result?.SeriesName, true);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/Video/BaseVideoTest.cs b/tests/Jellyfin.Naming.Tests/Video/BaseVideoTest.cs
deleted file mode 100644
index 0c2978aca..000000000
--- a/tests/Jellyfin.Naming.Tests/Video/BaseVideoTest.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Emby.Naming.Common;
-using Emby.Naming.Video;
-
-namespace Jellyfin.Naming.Tests.Video
-{
- public abstract class BaseVideoTest
- {
- private readonly NamingOptions _namingOptions = new NamingOptions();
-
- protected VideoResolver GetParser()
- => new VideoResolver(_namingOptions);
- }
-}
diff --git a/tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs b/tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs
index 49cb2387b..917d8fb3a 100644
--- a/tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs
@@ -46,6 +46,7 @@ namespace Jellyfin.Naming.Tests.Video
[InlineData("Maximum Ride - 2016 - WEBDL-1080p - x264 AC3.mkv", "Maximum Ride", 2016)]
// FIXME: [InlineData("Robin Hood [Multi-Subs] [2018].mkv", "Robin Hood", 2018)]
[InlineData(@"3.Days.to.Kill.2014.720p.BluRay.x264.YIFY.mkv", "3.Days.to.Kill", 2014)] // In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
+ [InlineData("3 days to kill (2005).mkv", "3 days to kill", 2005)]
public void CleanDateTimeTest(string input, string expectedName, int? expectedYear)
{
input = Path.GetFileName(input);
diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs
index a64d17349..a2722a175 100644
--- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs
@@ -5,7 +5,7 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
- public class ExtraTests : BaseVideoTest
+ public class ExtraTests
{
private readonly NamingOptions _videoOptions = new NamingOptions();
diff --git a/tests/Jellyfin.Naming.Tests/Video/Format3DTests.cs b/tests/Jellyfin.Naming.Tests/Video/Format3DTests.cs
index ed3112936..69de96a47 100644
--- a/tests/Jellyfin.Naming.Tests/Video/Format3DTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/Format3DTests.cs
@@ -4,29 +4,29 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
- public class Format3DTests : BaseVideoTest
+ public class Format3DTests
{
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
[Fact]
public void TestKodiFormat3D()
{
- var options = new NamingOptions();
-
- Test("Super movie.3d.mp4", false, null, options);
- Test("Super movie.3d.hsbs.mp4", true, "hsbs", options);
- Test("Super movie.3d.sbs.mp4", true, "sbs", options);
- Test("Super movie.3d.htab.mp4", true, "htab", options);
- Test("Super movie.3d.tab.mp4", true, "tab", options);
- Test("Super movie 3d hsbs.mp4", true, "hsbs", options);
+ Test("Super movie.3d.mp4", false, null);
+ Test("Super movie.3d.hsbs.mp4", true, "hsbs");
+ Test("Super movie.3d.sbs.mp4", true, "sbs");
+ Test("Super movie.3d.htab.mp4", true, "htab");
+ Test("Super movie.3d.tab.mp4", true, "tab");
+ Test("Super movie 3d hsbs.mp4", true, "hsbs");
}
[Fact]
public void Test3DName()
{
var result =
- GetParser().ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.3d.hsbs.mkv");
+ new VideoResolver(_namingOptions).ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.3d.hsbs.mkv");
- Assert.Equal("hsbs", result.Format3D);
- Assert.Equal("Oblivion", result.Name);
+ Assert.Equal("hsbs", result?.Format3D);
+ Assert.Equal("Oblivion", result?.Name);
}
[Fact]
@@ -34,32 +34,31 @@ namespace Jellyfin.Naming.Tests.Video
{
// These were introduced for Media Browser 3
// Kodi conventions are preferred but these still need to be supported
- var options = new NamingOptions();
- Test("Super movie.3d.mp4", false, null, options);
- Test("Super movie.3d.hsbs.mp4", true, "hsbs", options);
- Test("Super movie.3d.sbs.mp4", true, "sbs", options);
- Test("Super movie.3d.htab.mp4", true, "htab", options);
- Test("Super movie.3d.tab.mp4", true, "tab", options);
+ Test("Super movie.3d.mp4", false, null);
+ Test("Super movie.3d.hsbs.mp4", true, "hsbs");
+ Test("Super movie.3d.sbs.mp4", true, "sbs");
+ Test("Super movie.3d.htab.mp4", true, "htab");
+ Test("Super movie.3d.tab.mp4", true, "tab");
- Test("Super movie.hsbs.mp4", true, "hsbs", options);
- Test("Super movie.sbs.mp4", true, "sbs", options);
- Test("Super movie.htab.mp4", true, "htab", options);
- Test("Super movie.tab.mp4", true, "tab", options);
- Test("Super movie.sbs3d.mp4", true, "sbs3d", options);
- Test("Super movie.3d.mvc.mp4", true, "mvc", options);
+ Test("Super movie.hsbs.mp4", true, "hsbs");
+ Test("Super movie.sbs.mp4", true, "sbs");
+ Test("Super movie.htab.mp4", true, "htab");
+ Test("Super movie.tab.mp4", true, "tab");
+ Test("Super movie.sbs3d.mp4", true, "sbs3d");
+ Test("Super movie.3d.mvc.mp4", true, "mvc");
- Test("Super movie [3d].mp4", false, null, options);
- Test("Super movie [hsbs].mp4", true, "hsbs", options);
- Test("Super movie [fsbs].mp4", true, "fsbs", options);
- Test("Super movie [ftab].mp4", true, "ftab", options);
- Test("Super movie [htab].mp4", true, "htab", options);
- Test("Super movie [sbs3d].mp4", true, "sbs3d", options);
+ Test("Super movie [3d].mp4", false, null);
+ Test("Super movie [hsbs].mp4", true, "hsbs");
+ Test("Super movie [fsbs].mp4", true, "fsbs");
+ Test("Super movie [ftab].mp4", true, "ftab");
+ Test("Super movie [htab].mp4", true, "htab");
+ Test("Super movie [sbs3d].mp4", true, "sbs3d");
}
- private void Test(string input, bool is3D, string format3D, NamingOptions options)
+ private void Test(string input, bool is3D, string? format3D)
{
- var parser = new Format3DParser(options);
+ var parser = new Format3DParser(_namingOptions);
var result = parser.Parse(input);
diff --git a/tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs b/tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs
index b8fbb2cb2..4198d69ff 100644
--- a/tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs
@@ -8,9 +8,11 @@ namespace Jellyfin.Naming.Tests.Video
{
public class MultiVersionTests
{
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
// FIXME
// [Fact]
- public void TestMultiEdition1()
+ private void TestMultiEdition1()
{
var files = new[]
{
@@ -26,7 +28,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -35,7 +36,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiEdition2()
+ private void TestMultiEdition2()
{
var files = new[]
{
@@ -51,7 +52,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -74,7 +74,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -83,7 +82,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestLetterFolders()
+ private void TestLetterFolders()
{
var files = new[]
{
@@ -102,7 +101,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(7, result.Count);
@@ -112,7 +110,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersionLimit()
+ private void TestMultiVersionLimit()
{
var files = new[]
{
@@ -132,7 +130,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -142,7 +139,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersionLimit2()
+ private void TestMultiVersionLimit2()
{
var files = new[]
{
@@ -163,7 +160,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(9, result.Count);
@@ -173,7 +169,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion3()
+ private void TestMultiVersion3()
{
var files = new[]
{
@@ -190,7 +186,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(5, result.Count);
@@ -200,7 +195,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion4()
+ private void TestMultiVersion4()
{
// Test for false positive
@@ -219,7 +214,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(5, result.Count);
@@ -229,7 +223,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion5()
+ private void TestMultiVersion5()
{
var files = new[]
{
@@ -249,7 +243,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -262,7 +255,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion6()
+ private void TestMultiVersion6()
{
var files = new[]
{
@@ -282,7 +275,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -295,7 +287,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion7()
+ private void TestMultiVersion7()
{
var files = new[]
{
@@ -309,7 +301,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(2, result.Count);
@@ -317,7 +308,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion8()
+ private void TestMultiVersion8()
{
// This is not actually supported yet
@@ -338,7 +329,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -351,7 +341,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion9()
+ private void TestMultiVersion9()
{
// Test for false positive
@@ -370,7 +360,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(5, result.Count);
@@ -380,7 +369,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion10()
+ private void TestMultiVersion10()
{
var files = new[]
{
@@ -394,7 +383,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -404,7 +392,7 @@ namespace Jellyfin.Naming.Tests.Video
// FIXME
// [Fact]
- public void TestMultiVersion11()
+ private void TestMultiVersion11()
{
// Currently not supported but we should probably handle this.
@@ -420,7 +408,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -430,8 +417,7 @@ namespace Jellyfin.Naming.Tests.Video
private VideoListResolver GetResolver()
{
- var options = new NamingOptions();
- return new VideoListResolver(options);
+ return new VideoListResolver(_namingOptions);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/Video/StackTests.cs b/tests/Jellyfin.Naming.Tests/Video/StackTests.cs
index 3e0cbaf0c..8794d3ebe 100644
--- a/tests/Jellyfin.Naming.Tests/Video/StackTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/StackTests.cs
@@ -6,8 +6,10 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
- public class StackTests : BaseVideoTest
+ public class StackTests
{
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
[Fact]
public void TestSimpleStack()
{
@@ -366,11 +368,11 @@ namespace Jellyfin.Naming.Tests.Video
{
var files = new[]
{
- new FileSystemMetadata{FullName = "Bad Boys (2006) part1.mkv", IsDirectory = false},
- new FileSystemMetadata{FullName = "Bad Boys (2006) part2.mkv", IsDirectory = false},
- new FileSystemMetadata{FullName = "300 (2006) part2", IsDirectory = true},
- new FileSystemMetadata{FullName = "300 (2006) part3", IsDirectory = true},
- new FileSystemMetadata{FullName = "300 (2006) part1", IsDirectory = true}
+ new FileSystemMetadata { FullName = "Bad Boys (2006) part1.mkv", IsDirectory = false },
+ new FileSystemMetadata { FullName = "Bad Boys (2006) part2.mkv", IsDirectory = false },
+ new FileSystemMetadata { FullName = "300 (2006) part2", IsDirectory = true },
+ new FileSystemMetadata { FullName = "300 (2006) part3", IsDirectory = true },
+ new FileSystemMetadata { FullName = "300 (2006) part1", IsDirectory = true }
};
var resolver = GetResolver();
@@ -446,7 +448,7 @@ namespace Jellyfin.Naming.Tests.Video
private StackResolver GetResolver()
{
- return new StackResolver(new NamingOptions());
+ return new StackResolver(_namingOptions);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/Video/StubTests.cs b/tests/Jellyfin.Naming.Tests/Video/StubTests.cs
index 8d5ced9a4..30ba94136 100644
--- a/tests/Jellyfin.Naming.Tests/Video/StubTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/StubTests.cs
@@ -4,8 +4,10 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
- public class StubTests : BaseVideoTest
+ public class StubTests
{
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
[Fact]
public void TestStubs()
{
@@ -27,16 +29,14 @@ namespace Jellyfin.Naming.Tests.Video
public void TestStubName()
{
var result =
- GetParser().ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.dvd.disc");
+ new VideoResolver(_namingOptions).ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.dvd.disc");
- Assert.Equal("Oblivion", result.Name);
+ Assert.Equal("Oblivion", result?.Name);
}
- private void Test(string path, bool isStub, string stubType)
+ private void Test(string path, bool isStub, string? stubType)
{
- var options = new NamingOptions();
-
- var isStubResult = StubResolver.TryResolveFile(path, options, out var stubTypeResult);
+ var isStubResult = StubResolver.TryResolveFile(path, _namingOptions, out var stubTypeResult);
Assert.Equal(isStub, isStubResult);
diff --git a/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs b/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs
index ef8a17898..12c4a50fe 100644
--- a/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs
@@ -8,9 +8,11 @@ namespace Jellyfin.Naming.Tests.Video
{
public class VideoListResolverTests
{
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
// FIXME
// [Fact]
- public void TestStackAndExtras()
+ private void TestStackAndExtras()
{
// No stacking here because there is no part/disc/etc
var files = new[]
@@ -44,7 +46,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(5, result.Count);
@@ -73,7 +74,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -94,7 +94,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -115,7 +114,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -137,7 +135,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -158,7 +155,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -183,7 +179,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(5, result.Count);
@@ -204,7 +199,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = true,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -226,7 +220,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = true,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(2, result.Count);
@@ -248,7 +241,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -270,7 +262,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -293,7 +284,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -316,7 +306,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(2, result.Count);
@@ -336,7 +325,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -356,7 +344,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -377,7 +364,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -398,7 +384,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -421,7 +406,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Equal(4, result.Count);
@@ -442,7 +426,6 @@ namespace Jellyfin.Naming.Tests.Video
{
IsDirectory = false,
FullName = i
-
}).ToList()).ToList();
Assert.Single(result);
@@ -450,8 +433,7 @@ namespace Jellyfin.Naming.Tests.Video
private VideoListResolver GetResolver()
{
- var options = new NamingOptions();
- return new VideoListResolver(options);
+ return new VideoListResolver(_namingOptions);
}
}
}
diff --git a/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs b/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs
index 5a3ce8886..99828b2eb 100644
--- a/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs
+++ b/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs
@@ -1,275 +1,199 @@
-using MediaBrowser.Model.Entities;
+using System.Collections.Generic;
+using Emby.Naming.Common;
+using Emby.Naming.Video;
+using MediaBrowser.Model.Entities;
using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
- public class VideoResolverTests : BaseVideoTest
+ public class VideoResolverTests
{
- // FIXME
- // [Fact]
- public void TestSimpleFile()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006).mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("Brave", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestSimpleFile2()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv");
-
- Assert.Equal(1995, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("Bad Boys", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestSimpleFileWithNumericName()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("300", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestExtra()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal(ExtraType.Trailer, result.ExtraType);
- Assert.Equal("Brave (2006)-trailer", result.Name);
- }
-
- // FIXME
- // [Fact]
- public void TestExtraWithNumericName()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006)-trailer.mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("300 (2006)-trailer", result.Name);
- Assert.Equal(ExtraType.Trailer, result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestStubFileWithNumericName()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).bluray.disc");
-
- Assert.Equal(2006, result.Year);
- Assert.True(result.IsStub);
- Assert.Equal("bluray", result.StubType);
- Assert.False(result.Is3D);
- Assert.Equal("300", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestStubFile()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006).bluray.disc");
-
- Assert.Equal(2006, result.Year);
- Assert.True(result.IsStub);
- Assert.Equal("bluray", result.StubType);
- Assert.False(result.Is3D);
- Assert.Equal("Brave", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestExtraStubWithNumericNameNotSupported()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc");
-
- Assert.Equal(2006, result.Year);
- Assert.True(result.IsStub);
- Assert.Equal("bluray", result.StubType);
- Assert.False(result.Is3D);
- Assert.Equal("300", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestExtraStubNotSupported()
- {
- // Using a stub for an extra is currently not supported
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc");
-
- Assert.Equal(2006, result.Year);
- Assert.True(result.IsStub);
- Assert.Equal("bluray", result.StubType);
- Assert.False(result.Is3D);
- Assert.Equal("brave", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void Test3DFileWithNumericName()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.True(result.Is3D);
- Assert.Equal("sbs", result.Format3D);
- Assert.Equal("300", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestBad3DFileWithNumericName()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("300", result.Name);
- Assert.Null(result.ExtraType);
- Assert.Null(result.Format3D);
- }
-
- // FIXME
- // [Fact]
- public void Test3DFile()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv");
-
- Assert.Equal(2006, result.Year);
- Assert.False(result.IsStub);
- Assert.True(result.Is3D);
- Assert.Equal("sbs", result.Format3D);
- Assert.Equal("brave", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- [Fact]
- public void TestNameWithoutDate()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/American Psycho/American.Psycho.mkv");
-
- Assert.Null(result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Null(result.Format3D);
- Assert.Equal("American.Psycho", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestCleanDateAndStringsSequence()
- {
- var parser = GetParser();
-
- // In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
- var result =
- parser.ResolveFile(@"/server/Movies/3.Days.to.Kill/3.Days.to.Kill.2014.720p.BluRay.x264.YIFY.mkv");
-
- Assert.Equal(2014, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Null(result.Format3D);
- Assert.Equal("3.Days.to.Kill", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- // FIXME
- // [Fact]
- public void TestCleanDateAndStringsSequence1()
- {
- var parser = GetParser();
-
- // In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
- var result =
- parser.ResolveFile(@"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv");
-
- Assert.Equal(2005, result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Null(result.Format3D);
- Assert.Equal("3 days to kill", result.Name);
- Assert.Null(result.ExtraType);
- }
-
- [Fact]
- public void TestFolderNameWithExtension()
- {
- var parser = GetParser();
-
- var result =
- parser.ResolveFile(@"/server/Movies/7 Psychos.mkv/7 Psychos.mkv");
-
- Assert.Null(result.Year);
- Assert.False(result.IsStub);
- Assert.False(result.Is3D);
- Assert.Equal("7 Psychos", result.Name);
- Assert.Null(result.ExtraType);
+ private readonly NamingOptions _namingOptions = new NamingOptions();
+
+ public static IEnumerable<object[]> GetResolveFileTestData()
+ {
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv",
+ Container = "mkv",
+ Name = "7 Psychos"
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv",
+ Container = "mkv",
+ Name = "3 days to kill",
+ Year = 2005
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/American Psycho/American.Psycho.mkv",
+ Container = "mkv",
+ Name = "American.Psycho",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv",
+ Container = "mkv",
+ Name = "brave",
+ Year = 2006,
+ Is3D = true,
+ Format3D = "sbs",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv",
+ Container = "mkv",
+ Name = "300",
+ Year = 2006
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv",
+ Container = "mkv",
+ Name = "300",
+ Year = 2006,
+ Is3D = true,
+ Format3D = "sbs",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc",
+ Container = "disc",
+ Name = "brave",
+ Year = 2006,
+ IsStub = true,
+ StubType = "bluray",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc",
+ Container = "disc",
+ Name = "300",
+ Year = 2006,
+ IsStub = true,
+ StubType = "bluray",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc",
+ Container = "disc",
+ Name = "Brave",
+ Year = 2006,
+ IsStub = true,
+ StubType = "bluray",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006).bluray.disc",
+ Container = "disc",
+ Name = "300",
+ Year = 2006,
+ IsStub = true,
+ StubType = "bluray",
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv",
+ Container = "mkv",
+ Name = "300",
+ Year = 2006,
+ ExtraType = ExtraType.Trailer,
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv",
+ Container = "mkv",
+ Name = "Brave",
+ Year = 2006,
+ ExtraType = ExtraType.Trailer,
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/300 (2007)/300 (2006).mkv",
+ Container = "mkv",
+ Name = "300",
+ Year = 2006
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv",
+ Container = "mkv",
+ Name = "Bad Boys",
+ Year = 1995,
+ }
+ };
+ yield return new object[]
+ {
+ new VideoFileInfo()
+ {
+ Path = @"/server/Movies/Brave (2007)/Brave (2006).mkv",
+ Container = "mkv",
+ Name = "Brave",
+ Year = 2006,
+ }
+ };
+ }
+
+ [Theory]
+ [MemberData(nameof(GetResolveFileTestData))]
+ public void ResolveFile_ValidFileName_Success(VideoFileInfo expectedResult)
+ {
+ var result = new VideoResolver(_namingOptions).ResolveFile(expectedResult.Path);
+
+ Assert.NotNull(result);
+ Assert.Equal(result?.Path, expectedResult.Path);
+ Assert.Equal(result?.Container, expectedResult.Container);
+ Assert.Equal(result?.Name, expectedResult.Name);
+ Assert.Equal(result?.Year, expectedResult.Year);
+ Assert.Equal(result?.ExtraType, expectedResult.ExtraType);
+ Assert.Equal(result?.Format3D, expectedResult.Format3D);
+ Assert.Equal(result?.Is3D, expectedResult.Is3D);
+ Assert.Equal(result?.IsStub, expectedResult.IsStub);
+ Assert.Equal(result?.StubType, expectedResult.StubType);
+ Assert.Equal(result?.IsDirectory, expectedResult.IsDirectory);
+ Assert.Equal(result?.FileNameWithoutExtension, expectedResult.FileNameWithoutExtension);
}
}
}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/HttpServer/ResponseFilterTests.cs b/tests/Jellyfin.Server.Implementations.Tests/HttpServer/ResponseFilterTests.cs
new file mode 100644
index 000000000..39bd94b59
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/HttpServer/ResponseFilterTests.cs
@@ -0,0 +1,18 @@
+using Emby.Server.Implementations.HttpServer;
+using Xunit;
+
+namespace Jellyfin.Server.Implementations.Tests.HttpServer
+{
+ public class ResponseFilterTests
+ {
+ [Theory]
+ [InlineData(null, null)]
+ [InlineData("", "")]
+ [InlineData("This is a clean string.", "This is a clean string.")]
+ [InlineData("This isn't \n\ra clean string.", "This isn't a clean string.")]
+ public void RemoveControlCharacters_ValidArgs_Correct(string? input, string? result)
+ {
+ Assert.Equal(result, ResponseFilter.RemoveControlCharacters(input));
+ }
+ }
+}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj
index b7865439c..3bad6bb7b 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj
+++ b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
+ <PropertyGroup>
+ <ProjectGuid>{2E3A1B4B-4225-4AAA-8B29-0181A84E7AEE}</ProjectGuid>
+ </PropertyGroup>
+
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
@@ -11,7 +16,7 @@
<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.11.0" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.11.0" />
- <PackageReference Include="Moq" Version="4.13.1" />
+ <PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/IgnorePatternsTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/IgnorePatternsTests.cs
new file mode 100644
index 000000000..26dee38c6
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/IgnorePatternsTests.cs
@@ -0,0 +1,21 @@
+using Emby.Server.Implementations.Library;
+using Xunit;
+
+namespace Jellyfin.Server.Implementations.Tests.Library
+{
+ public class IgnorePatternsTests
+ {
+ [Theory]
+ [InlineData("/media/small.jpg", true)]
+ [InlineData("/media/movies/#Recycle/test.txt", true)]
+ [InlineData("/media/movies/#recycle/", true)]
+ [InlineData("thumbs.db", true)]
+ [InlineData(@"C:\media\movies\movie.avi", false)]
+ [InlineData("/media/.hiddendir/file.mp4", true)]
+ [InlineData("/media/dir/.hiddenfile.mp4", true)]
+ public void PathIgnored(string path, bool expected)
+ {
+ Assert.Equal(expected, IgnorePatterns.ShouldIgnore(path));
+ }
+ }
+}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
new file mode 100644
index 000000000..c771f5f4a
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs
@@ -0,0 +1,27 @@
+using System;
+using Emby.Server.Implementations.Library;
+using Xunit;
+
+namespace Jellyfin.Server.Implementations.Tests.Library
+{
+ public class PathExtensionsTests
+ {
+ [Theory]
+ [InlineData("Superman: Red Son [imdbid=tt10985510]", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
+ [InlineData("Superman: Red Son", "imdbid", null)]
+ public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? expectedResult)
+ {
+ Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));
+ }
+
+ [Theory]
+ [InlineData("", "")]
+ [InlineData("Superman: Red Son [imdbid=tt10985510]", "")]
+ [InlineData("", "imdbid")]
+ public void GetAttributeValue_EmptyString_ThrowsArgumentException(string input, string attribute)
+ {
+ Assert.Throws<ArgumentException>(() => PathExtensions.GetAttributeValue(input, attribute));
+ }
+ }
+}
diff --git a/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs b/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs
new file mode 100644
index 000000000..34698fe25
--- /dev/null
+++ b/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs
@@ -0,0 +1,49 @@
+using System.Text.Json;
+using System.Threading.Tasks;
+using MediaBrowser.Model.Branding;
+using Xunit;
+
+namespace MediaBrowser.Api.Tests
+{
+ public sealed class BrandingServiceTests : IClassFixture<JellyfinApplicationFactory>
+ {
+ private readonly JellyfinApplicationFactory _factory;
+
+ public BrandingServiceTests(JellyfinApplicationFactory factory)
+ {
+ _factory = factory;
+ }
+
+ [Fact]
+ public async Task GetConfiguration_ReturnsCorrectResponse()
+ {
+ // Arrange
+ var client = _factory.CreateClient();
+
+ // Act
+ var response = await client.GetAsync("/Branding/Configuration");
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());
+ var responseBody = await response.Content.ReadAsStreamAsync();
+ _ = await JsonSerializer.DeserializeAsync<BrandingOptions>(responseBody);
+ }
+
+ [Theory]
+ [InlineData("/Branding/Css")]
+ [InlineData("/Branding/Css.css")]
+ public async Task GetCss_ReturnsCorrectResponse(string url)
+ {
+ // Arrange
+ var client = _factory.CreateClient();
+
+ // Act
+ var response = await client.GetAsync(url);
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ Assert.Equal("text/css", response.Content.Headers.ContentType.ToString());
+ }
+ }
+}
diff --git a/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs b/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs
new file mode 100644
index 000000000..c39ed07de
--- /dev/null
+++ b/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Concurrent;
+using System.IO;
+using Emby.Server.Implementations;
+using Emby.Server.Implementations.IO;
+using Emby.Server.Implementations.Networking;
+using Jellyfin.Drawing.Skia;
+using Jellyfin.Server;
+using MediaBrowser.Common;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.AspNetCore.TestHost;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Serilog;
+using Serilog.Extensions.Logging;
+
+namespace MediaBrowser.Api.Tests
+{
+ /// <summary>
+ /// Factory for bootstrapping the Jellyfin application in memory for functional end to end tests.
+ /// </summary>
+ public class JellyfinApplicationFactory : WebApplicationFactory<Startup>
+ {
+ private static readonly string _testPathRoot = Path.Combine(Path.GetTempPath(), "jellyfin-test-data");
+ private static readonly ConcurrentBag<IDisposable> _disposableComponents = new ConcurrentBag<IDisposable>();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="JellyfinApplicationFactory"/> class.
+ /// </summary>
+ public JellyfinApplicationFactory()
+ {
+ // Perform static initialization that only needs to happen once per test-run
+ Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
+ Program.PerformStaticInitialization();
+ }
+
+ /// <inheritdoc/>
+ protected override IWebHostBuilder CreateWebHostBuilder()
+ {
+ return new WebHostBuilder();
+ }
+
+ /// <inheritdoc/>
+ protected override void ConfigureWebHost(IWebHostBuilder builder)
+ {
+ // Specify the startup command line options
+ var commandLineOpts = new StartupOptions
+ {
+ NoWebClient = true,
+ NoAutoRunWebApp = true
+ };
+
+ // Use a temporary directory for the application paths
+ var webHostPathRoot = Path.Combine(_testPathRoot, "test-host-" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
+ Directory.CreateDirectory(Path.Combine(webHostPathRoot, "logs"));
+ Directory.CreateDirectory(Path.Combine(webHostPathRoot, "config"));
+ Directory.CreateDirectory(Path.Combine(webHostPathRoot, "cache"));
+ Directory.CreateDirectory(Path.Combine(webHostPathRoot, "jellyfin-web"));
+ var appPaths = new ServerApplicationPaths(
+ webHostPathRoot,
+ Path.Combine(webHostPathRoot, "logs"),
+ Path.Combine(webHostPathRoot, "config"),
+ Path.Combine(webHostPathRoot, "cache"),
+ Path.Combine(webHostPathRoot, "jellyfin-web"));
+
+ // Create the logging config file
+ // TODO: We shouldn't need to do this since we are only logging to console
+ Program.InitLoggingConfigFile(appPaths).GetAwaiter().GetResult();
+
+ // Create a copy of the application configuration to use for startup
+ var startupConfig = Program.CreateAppConfiguration(commandLineOpts, appPaths);
+
+ ILoggerFactory loggerFactory = new SerilogLoggerFactory();
+ _disposableComponents.Add(loggerFactory);
+
+ // Create the app host and initialize it
+ var appHost = new CoreAppHost(
+ appPaths,
+ loggerFactory,
+ commandLineOpts,
+ new ManagedFileSystem(loggerFactory.CreateLogger<ManagedFileSystem>(), appPaths),
+ new NetworkManager(loggerFactory.CreateLogger<NetworkManager>()));
+ _disposableComponents.Add(appHost);
+ var serviceCollection = new ServiceCollection();
+ appHost.Init(serviceCollection);
+
+ // Configure the web host builder
+ Program.ConfigureWebHostBuilder(builder, appHost, serviceCollection, commandLineOpts, startupConfig, appPaths);
+ }
+
+ /// <inheritdoc/>
+ protected override TestServer CreateServer(IWebHostBuilder builder)
+ {
+ // Create the test server using the base implementation
+ var testServer = base.CreateServer(builder);
+
+ // Finish initializing the app host
+ var appHost = (CoreAppHost)testServer.Services.GetRequiredService<IApplicationHost>();
+ appHost.ServiceProvider = testServer.Services;
+ appHost.InitializeServices().GetAwaiter().GetResult();
+ appHost.RunStartupTasksAsync().GetAwaiter().GetResult();
+
+ return testServer;
+ }
+
+ /// <inheritdoc/>
+ protected override void Dispose(bool disposing)
+ {
+ foreach (var disposable in _disposableComponents)
+ {
+ disposable.Dispose();
+ }
+
+ _disposableComponents.Clear();
+
+ base.Dispose(disposing);
+ }
+ }
+}
diff --git a/tests/MediaBrowser.Api.Tests/MediaBrowser.Api.Tests.csproj b/tests/MediaBrowser.Api.Tests/MediaBrowser.Api.Tests.csproj
new file mode 100644
index 000000000..c845ca6cf
--- /dev/null
+++ b/tests/MediaBrowser.Api.Tests/MediaBrowser.Api.Tests.csproj
@@ -0,0 +1,33 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+ <IsPackable>false</IsPackable>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.5" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
+ <PackageReference Include="xunit" Version="2.4.1" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
+ <PackageReference Include="coverlet.collector" Version="1.2.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\Jellyfin.Server\Jellyfin.Server.csproj" />
+ <ProjectReference Include="..\..\MediaBrowser.Api\MediaBrowser.Api.csproj" />
+ </ItemGroup>
+
+ <!-- Code Analyzers-->
+ <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+
+</Project>
diff --git a/tests/jellyfin-tests.ruleset b/tests/jellyfin-tests.ruleset
new file mode 100644
index 000000000..5a113e955
--- /dev/null
+++ b/tests/jellyfin-tests.ruleset
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RuleSet Name="Rules for MediaBrowser.Api.Tests" Description="Code analysis rules for MediaBrowser.Api.Tests.csproj" ToolsVersion="14.0">
+
+ <!-- Include the solution default RuleSet. The rules in this file will override the defaults. -->
+ <Include Path="../jellyfin.ruleset" Action="Default" />
+
+ <!-- StyleCop Analyzer Rules -->
+ <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
+ <!-- SA0001: XML comment analysis is disabled due to project configuration -->
+ <Rule Id="SA0001" Action="None" />
+ </Rules>
+
+ <!-- FxCop Analyzer Rules -->
+ <Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design">
+ <!-- CA1707: Identifiers should not contain underscores -->
+ <Rule Id="CA1707" Action="None" />
+ <!-- CA2007: Consider calling ConfigureAwait on the awaited task -->
+ <Rule Id="CA2007" Action="None" />
+ <!-- CA2234: Pass system uri objects instead of strings -->
+ <Rule Id="CA2234" Action="Info" />
+ </Rules>
+</RuleSet>