aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Extensions.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Jellyfin.Extensions.Tests')
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs1
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs (renamed from tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs)77
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs13
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyArrayModel.cs2
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyCollectionModel.cs19
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyListModel.cs2
-rw-r--r--tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyListModel.cs22
-rw-r--r--tests/Jellyfin.Extensions.Tests/StringExtensionsTests.cs8
8 files changed, 136 insertions, 8 deletions
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs
index 125229ff9..d58a62cc8 100644
--- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs
+++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs
@@ -1,5 +1,6 @@
using System.Text.Json;
using FsCheck;
+using FsCheck.Fluent;
using FsCheck.Xunit;
using Jellyfin.Extensions.Json.Converters;
using Xunit;
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs
index 9fc015823..83f917c17 100644
--- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs
+++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs
@@ -1,4 +1,7 @@
using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Jellyfin.Extensions.Tests.Json.Models;
@@ -7,7 +10,7 @@ using Xunit;
namespace Jellyfin.Extensions.Tests.Json.Converters
{
- public class JsonCommaDelimitedArrayTests
+ public class JsonCommaDelimitedCollectionTests
{
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
{
@@ -37,6 +40,29 @@ namespace Jellyfin.Extensions.Tests.Json.Converters
}
[Fact]
+ public void Deserialize_EmptyList_Success()
+ {
+ var desiredValue = new GenericBodyListModel<string>
+ {
+ Value = []
+ };
+
+ Assert.Throws<InvalidOperationException>(() => JsonSerializer.Deserialize<GenericBodyListModel<string>>(@"{ ""Value"": """" }", _jsonOptions));
+ }
+
+ [Fact]
+ public void Deserialize_EmptyIReadOnlyList_Success()
+ {
+ var desiredValue = new GenericBodyIReadOnlyListModel<string>
+ {
+ Value = []
+ };
+
+ var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": """" }", _jsonOptions);
+ Assert.Equal(desiredValue.Value, value?.Value);
+ }
+
+ [Fact]
public void Deserialize_String_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
@@ -49,6 +75,17 @@ namespace Jellyfin.Extensions.Tests.Json.Converters
}
[Fact]
+ public void Deserialize_StringList_Valid_Success()
+ {
+ var desiredValue = new GenericBodyListModel<string>
+ {
+ Value = ["a", "b", "c"]
+ };
+
+ Assert.Throws<InvalidOperationException>(() => JsonSerializer.Deserialize<GenericBodyListModel<string>>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions));
+ }
+
+ [Fact]
public void Deserialize_String_Space_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
@@ -92,7 +129,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters
Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown]
};
- var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", _jsonOptions);
+ var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,TotallyNotAValidCommand,MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
@@ -131,5 +168,41 @@ namespace Jellyfin.Extensions.Tests.Json.Converters
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
+
+ [Fact]
+ public void Serialize_GenericCommandType_ReadOnlyArray_Valid_Success()
+ {
+ var valueToSerialize = new GenericBodyIReadOnlyCollectionModel<GeneralCommandType>
+ {
+ Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }.AsReadOnly()
+ };
+
+ string value = JsonSerializer.Serialize<GenericBodyIReadOnlyCollectionModel<GeneralCommandType>>(valueToSerialize, _jsonOptions);
+ Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value);
+ }
+
+ [Fact]
+ public void Serialize_GenericCommandType_ImmutableArrayArray_Valid_Success()
+ {
+ var valueToSerialize = new GenericBodyIReadOnlyCollectionModel<GeneralCommandType>
+ {
+ Value = ImmutableArray.Create(new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown })
+ };
+
+ string value = JsonSerializer.Serialize<GenericBodyIReadOnlyCollectionModel<GeneralCommandType>>(valueToSerialize, _jsonOptions);
+ Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value);
+ }
+
+ [Fact]
+ public void Serialize_GenericCommandType_List_Valid_Success()
+ {
+ var valueToSerialize = new GenericBodyIReadOnlyListModel<GeneralCommandType>
+ {
+ Value = new List<GeneralCommandType> { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
+ };
+
+ string value = JsonSerializer.Serialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(valueToSerialize, _jsonOptions);
+ Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value);
+ }
}
}
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs
index 9b977b9a5..26989d59b 100644
--- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs
+++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Jellyfin.Extensions.Tests.Json.Models;
@@ -87,5 +88,17 @@ namespace Jellyfin.Extensions.Tests.Json.Converters
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
+
+ [Fact]
+ public void Serialize_GenericCommandType_IReadOnlyList_Valid_Success()
+ {
+ var valueToSerialize = new GenericBodyIReadOnlyListModel<GeneralCommandType>
+ {
+ Value = new List<GeneralCommandType> { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
+ };
+
+ string value = JsonSerializer.Serialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(valueToSerialize, _jsonOptions);
+ Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value);
+ }
}
}
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyArrayModel.cs b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyArrayModel.cs
index 76669ea19..a698c9c92 100644
--- a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyArrayModel.cs
+++ b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyArrayModel.cs
@@ -14,7 +14,7 @@ namespace Jellyfin.Extensions.Tests.Json.Models
/// Gets or sets the value.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1819:Properties should not return arrays", MessageId = "Value", Justification = "Imported from ServiceStack")]
- [JsonConverter(typeof(JsonCommaDelimitedArrayConverterFactory))]
+ [JsonConverter(typeof(JsonCommaDelimitedCollectionConverterFactory))]
public T[] Value { get; set; } = default!;
}
}
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyCollectionModel.cs b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyCollectionModel.cs
new file mode 100644
index 000000000..14cbc0f50
--- /dev/null
+++ b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyCollectionModel.cs
@@ -0,0 +1,19 @@
+using System.Collections.Generic;
+using System.Text.Json.Serialization;
+using Jellyfin.Extensions.Json.Converters;
+
+namespace Jellyfin.Extensions.Tests.Json.Models
+{
+ /// <summary>
+ /// The generic body <c>IReadOnlyCollection</c> model.
+ /// </summary>
+ /// <typeparam name="T">The value type.</typeparam>
+ public sealed class GenericBodyIReadOnlyCollectionModel<T>
+ {
+ /// <summary>
+ /// Gets or sets the value.
+ /// </summary>
+ [JsonConverter(typeof(JsonCommaDelimitedCollectionConverterFactory))]
+ public IReadOnlyCollection<T> Value { get; set; } = default!;
+ }
+}
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyListModel.cs b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyListModel.cs
index 7e6b97afe..eaa06a5dd 100644
--- a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyListModel.cs
+++ b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyIReadOnlyListModel.cs
@@ -13,7 +13,7 @@ namespace Jellyfin.Extensions.Tests.Json.Models
/// <summary>
/// Gets or sets the value.
/// </summary>
- [JsonConverter(typeof(JsonCommaDelimitedArrayConverterFactory))]
+ [JsonConverter(typeof(JsonCommaDelimitedCollectionConverterFactory))]
public IReadOnlyList<T> Value { get; set; } = default!;
}
}
diff --git a/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyListModel.cs b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyListModel.cs
new file mode 100644
index 000000000..463f9922f
--- /dev/null
+++ b/tests/Jellyfin.Extensions.Tests/Json/Models/GenericBodyListModel.cs
@@ -0,0 +1,22 @@
+#pragma warning disable CA1002 // Do not expose generic lists
+#pragma warning disable CA2227 // Collection properties should be read only
+
+using System.Collections.Generic;
+using System.Text.Json.Serialization;
+using Jellyfin.Extensions.Json.Converters;
+
+namespace Jellyfin.Extensions.Tests.Json.Models
+{
+ /// <summary>
+ /// The generic body <c>List</c> model.
+ /// </summary>
+ /// <typeparam name="T">The value type.</typeparam>
+ public sealed class GenericBodyListModel<T>
+ {
+ /// <summary>
+ /// Gets or sets the value.
+ /// </summary>
+ [JsonConverter(typeof(JsonCommaDelimitedCollectionConverterFactory))]
+ public List<T> Value { get; set; } = default!;
+ }
+}
diff --git a/tests/Jellyfin.Extensions.Tests/StringExtensionsTests.cs b/tests/Jellyfin.Extensions.Tests/StringExtensionsTests.cs
index 69d20bd3f..028f12afa 100644
--- a/tests/Jellyfin.Extensions.Tests/StringExtensionsTests.cs
+++ b/tests/Jellyfin.Extensions.Tests/StringExtensionsTests.cs
@@ -6,8 +6,8 @@ namespace Jellyfin.Extensions.Tests
public class StringExtensionsTests
{
[Theory]
- [InlineData("", "")] // Identity edge-case (no diactritics)
- [InlineData("Indiana Jones", "Indiana Jones")] // Identity (no diactritics)
+ [InlineData("", "")] // Identity edge-case (no diacritics)
+ [InlineData("Indiana Jones", "Indiana Jones")] // Identity (no diacritics)
[InlineData("a\ud800b", "ab")] // Invalid UTF-16 char stripping
[InlineData("åäö", "aao")] // Issue #7484
[InlineData("Jön", "Jon")] // Issue #7484
@@ -25,8 +25,8 @@ namespace Jellyfin.Extensions.Tests
}
[Theory]
- [InlineData("", false)] // Identity edge-case (no diactritics)
- [InlineData("Indiana Jones", false)] // Identity (no diactritics)
+ [InlineData("", false)] // Identity edge-case (no diacritics)
+ [InlineData("Indiana Jones", false)] // Identity (no diacritics)
[InlineData("a\ud800b", true)] // Invalid UTF-16 char stripping
[InlineData("åäö", true)] // Issue #7484
[InlineData("Jön", true)] // Issue #7484