aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs112
-rw-r--r--tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs9
-rw-r--r--tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs4
-rw-r--r--tests/Jellyfin.Providers.Tests/Manager/ProviderManagerTests.cs4
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest.json (renamed from tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json)0
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs6
6 files changed, 125 insertions, 10 deletions
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs
new file mode 100644
index 000000000..5d86d6bae
--- /dev/null
+++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs
@@ -0,0 +1,112 @@
+using System.Text.Json;
+using Jellyfin.Data.Enums;
+using Jellyfin.Extensions.Json.Converters;
+using Xunit;
+
+namespace Jellyfin.Extensions.Tests.Json.Converters;
+
+public class JsonDefaultStringEnumConverterTests
+{
+ private readonly JsonSerializerOptions _jsonOptions = new() { Converters = { new JsonDefaultStringEnumConverterFactory() } };
+
+ /// <summary>
+ /// Test to ensure that `null` and empty string are deserialized to the default value.
+ /// </summary>
+ /// <param name="input">The input string.</param>
+ /// <param name="output">The expected enum value.</param>
+ [Theory]
+ [InlineData("\"\"", MediaStreamProtocol.http)]
+ [InlineData("\"Http\"", MediaStreamProtocol.http)]
+ [InlineData("\"Hls\"", MediaStreamProtocol.hls)]
+ public void Deserialize_Enum_Direct(string input, MediaStreamProtocol output)
+ {
+ var value = JsonSerializer.Deserialize<MediaStreamProtocol>(input, _jsonOptions);
+ Assert.Equal(output, value);
+ }
+
+ /// <summary>
+ /// Test to ensure that `null` and empty string are deserialized to the default value.
+ /// </summary>
+ /// <param name="input">The input string.</param>
+ /// <param name="output">The expected enum value.</param>
+ [Theory]
+ [InlineData(null, MediaStreamProtocol.http)]
+ [InlineData("\"\"", MediaStreamProtocol.http)]
+ [InlineData("\"Http\"", MediaStreamProtocol.http)]
+ [InlineData("\"Hls\"", MediaStreamProtocol.hls)]
+ public void Deserialize_Enum(string? input, MediaStreamProtocol output)
+ {
+ input ??= "null";
+ var json = $"{{ \"EnumValue\": {input} }}";
+ var value = JsonSerializer.Deserialize<TestClass>(json, _jsonOptions);
+ Assert.NotNull(value);
+ Assert.Equal(output, value.EnumValue);
+ }
+
+ /// <summary>
+ /// Test to ensure that empty string is deserialized to the default value,
+ /// and `null` is deserialized to `null`.
+ /// </summary>
+ /// <param name="input">The input string.</param>
+ /// <param name="output">The expected enum value.</param>
+ [Theory]
+ [InlineData(null, null)]
+ [InlineData("\"\"", MediaStreamProtocol.http)]
+ [InlineData("\"Http\"", MediaStreamProtocol.http)]
+ [InlineData("\"Hls\"", MediaStreamProtocol.hls)]
+ public void Deserialize_Enum_Nullable(string? input, MediaStreamProtocol? output)
+ {
+ input ??= "null";
+ var json = $"{{ \"EnumValue\": {input} }}";
+ var value = JsonSerializer.Deserialize<NullTestClass>(json, _jsonOptions);
+ Assert.NotNull(value);
+ Assert.Equal(output, value.EnumValue);
+ }
+
+ /// <summary>
+ /// Ensures that the roundtrip serialization & deserialization is successful.
+ /// </summary>
+ /// <param name="input">Input enum.</param>
+ /// <param name="output">Output enum.</param>
+ [Theory]
+ [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)]
+ [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)]
+ public void Enum_RoundTrip(MediaStreamProtocol input, MediaStreamProtocol output)
+ {
+ var inputObj = new TestClass { EnumValue = input };
+
+ var outputObj = JsonSerializer.Deserialize<TestClass>(JsonSerializer.Serialize(inputObj, _jsonOptions), _jsonOptions);
+
+ Assert.NotNull(outputObj);
+ Assert.Equal(output, outputObj.EnumValue);
+ }
+
+ /// <summary>
+ /// Ensures that the roundtrip serialization & deserialization is successful, including null.
+ /// </summary>
+ /// <param name="input">Input enum.</param>
+ /// <param name="output">Output enum.</param>
+ [Theory]
+ [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)]
+ [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)]
+ [InlineData(null, null)]
+ public void Enum_RoundTrip_Nullable(MediaStreamProtocol? input, MediaStreamProtocol? output)
+ {
+ var inputObj = new NullTestClass { EnumValue = input };
+
+ var outputObj = JsonSerializer.Deserialize<NullTestClass>(JsonSerializer.Serialize(inputObj, _jsonOptions), _jsonOptions);
+
+ Assert.NotNull(outputObj);
+ Assert.Equal(output, outputObj.EnumValue);
+ }
+
+ private sealed class TestClass
+ {
+ public MediaStreamProtocol EnumValue { get; set; }
+ }
+
+ private sealed class NullTestClass
+ {
+ public MediaStreamProtocol? EnumValue { get; set; }
+ }
+}
diff --git a/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs b/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
index 909de8f72..6d88dbb8e 100644
--- a/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
+++ b/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
+using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
@@ -388,21 +389,21 @@ namespace Jellyfin.Model.Tests
// Assert.Equal("webm", val.Container);
Assert.Equal(streamInfo.Container, uri.Extension);
Assert.Equal("stream", uri.Filename);
- Assert.Equal("http", streamInfo.SubProtocol);
+ Assert.Equal(MediaStreamProtocol.http, streamInfo.SubProtocol);
}
else if (transcodeProtocol.Equals("HLS.mp4", StringComparison.Ordinal))
{
Assert.Equal("mp4", streamInfo.Container);
Assert.Equal("m3u8", uri.Extension);
Assert.Equal("master", uri.Filename);
- Assert.Equal("hls", streamInfo.SubProtocol);
+ Assert.Equal(MediaStreamProtocol.hls, streamInfo.SubProtocol);
}
else
{
Assert.Equal("ts", streamInfo.Container);
Assert.Equal("m3u8", uri.Extension);
Assert.Equal("master", uri.Filename);
- Assert.Equal("hls", streamInfo.SubProtocol);
+ Assert.Equal(MediaStreamProtocol.hls, streamInfo.SubProtocol);
}
// Full transcode
@@ -488,7 +489,7 @@ namespace Jellyfin.Model.Tests
}
else if (playMethod is null)
{
- Assert.Null(streamInfo.SubProtocol);
+ Assert.Equal(MediaStreamProtocol.http, streamInfo.SubProtocol);
Assert.Equal("stream", uri.Filename);
Assert.False(streamInfo.EstimateContentLength);
diff --git a/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs b/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
index 198ad5a27..2399a10a3 100644
--- a/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
+++ b/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
@@ -27,7 +27,7 @@ public static class ImageFormatExtensionsTests
[InlineData((ImageFormat)int.MinValue)]
[InlineData((ImageFormat)int.MaxValue)]
[InlineData((ImageFormat)(-1))]
- [InlineData((ImageFormat)5)]
+ [InlineData((ImageFormat)6)]
public static void GetMimeType_Valid_ThrowsInvalidEnumArgumentException(ImageFormat format)
=> Assert.Throws<InvalidEnumArgumentException>(() => format.GetMimeType());
@@ -40,7 +40,7 @@ public static class ImageFormatExtensionsTests
[InlineData((ImageFormat)int.MinValue)]
[InlineData((ImageFormat)int.MaxValue)]
[InlineData((ImageFormat)(-1))]
- [InlineData((ImageFormat)5)]
+ [InlineData((ImageFormat)6)]
public static void GetExtension_Valid_ThrowsInvalidEnumArgumentException(ImageFormat format)
=> Assert.Throws<InvalidEnumArgumentException>(() => format.GetExtension());
}
diff --git a/tests/Jellyfin.Providers.Tests/Manager/ProviderManagerTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ProviderManagerTests.cs
index 478db6941..6fccce049 100644
--- a/tests/Jellyfin.Providers.Tests/Manager/ProviderManagerTests.cs
+++ b/tests/Jellyfin.Providers.Tests/Manager/ProviderManagerTests.cs
@@ -17,6 +17,7 @@ using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Providers.Manager;
+using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
@@ -572,7 +573,8 @@ namespace Jellyfin.Providers.Tests.Manager
Mock.Of<IServerApplicationPaths>(),
libraryManager.Object,
baseItemManager!,
- Mock.Of<ILyricManager>());
+ Mock.Of<ILyricManager>(),
+ Mock.Of<IMemoryCache>());
return providerManager;
}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json b/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest.json
index 57367ce88..57367ce88 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json
+++ b/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest.json
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs
index 5caf7d124..f58a3276b 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs
@@ -50,7 +50,7 @@ namespace Jellyfin.Server.Implementations.Tests.Updates
{
PackageInfo[] packages = await _installationManager.GetPackages(
"Jellyfin Stable",
- "https://repo.jellyfin.org/releases/plugin/manifest-stable.json",
+ "https://repo.jellyfin.org/files/plugin/manifest.json",
false);
Assert.Equal(25, packages.Length);
@@ -61,7 +61,7 @@ namespace Jellyfin.Server.Implementations.Tests.Updates
{
PackageInfo[] packages = await _installationManager.GetPackages(
"Jellyfin Stable",
- "https://repo.jellyfin.org/releases/plugin/manifest-stable.json",
+ "https://repo.jellyfin.org/files/plugin/manifest.json",
false);
packages = _installationManager.FilterPackages(packages, "Anime").ToArray();
@@ -73,7 +73,7 @@ namespace Jellyfin.Server.Implementations.Tests.Updates
{
PackageInfo[] packages = await _installationManager.GetPackages(
"Jellyfin Stable",
- "https://repo.jellyfin.org/releases/plugin/manifest-stable.json",
+ "https://repo.jellyfin.org/files/plugin/manifest.json",
false);
packages = _installationManager.FilterPackages(packages, id: new Guid("a4df60c5-6ab4-412a-8f79-2cab93fb2bc5")).ToArray();