Files
pgsql-jellyfin/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs
T
wjones e81c127514 Add JSON config, DB-backed library options, and docs
- Add JSON-based config loading with XML fallback for DB and library options
- Implement LibraryOptionsRepository with EF Core, migrations, and entity
- Update CollectionFolder to use DB-backed options with XML fallback/backfill
- Register repository in DI and initialize at startup
- Use EF execution strategy for transactional DB operations
- Suppress code analysis warnings in .csproj and test files
- Add DATABASE_MIGRATION.md, LIBRARY_OPTIONS_DB_DESIGN.md, and WEBSOCKET_AUTHENTICATION.md
- Add database.json.example and improve migration docs
- Add tests for JSON config loader and update test naming warnings
2026-04-30 12:25:24 -04:00

136 lines
5.3 KiB
C#

// <copyright file="JsonCommaDelimitedIReadOnlyListTests.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#pragma warning disable CA1707 // Identifiers should not contain underscores - xUnit test naming convention
namespace Jellyfin.Extensions.Tests.Json.Converters
{
using System.Text.Json;
using System.Text.Json.Serialization;
using Jellyfin.Extensions.Tests.Json.Models;
using MediaBrowser.Model.Session;
using Xunit;
/// <summary>
/// Tests for JSON comma delimited IReadOnlyList converter.
/// </summary>
public class JsonCommaDelimitedIReadOnlyListTests
{
private readonly JsonSerializerOptions jsonOptions = new()
{
Converters =
{
new JsonStringEnumConverter(),
},
};
/// <summary>
/// Tests that deserializing comma-delimited string succeeds.
/// </summary>
[Fact]
public void Deserialize_String_Valid_Success()
{
GenericBodyIReadOnlyListModel<string> desiredValue = new()
{
Value = ["a", "b", "c"],
};
GenericBodyIReadOnlyListModel<string>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a,b,c"" }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that deserializing comma-delimited string with spaces succeeds.
/// </summary>
[Fact]
public void Deserialize_String_Space_Valid_Success()
{
GenericBodyIReadOnlyListModel<string> desiredValue = new()
{
Value = ["a", "b", "c"],
};
GenericBodyIReadOnlyListModel<string>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a, b, c"" }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that deserializing comma-delimited enum string succeeds.
/// </summary>
[Fact]
public void Deserialize_GenericCommandType_Valid_Success()
{
GenericBodyIReadOnlyListModel<GeneralCommandType> desiredValue = new()
{
Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown],
};
GenericBodyIReadOnlyListModel<GeneralCommandType>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that deserializing comma-delimited enum string with spaces succeeds.
/// </summary>
[Fact]
public void Deserialize_GenericCommandType_Space_Valid_Success()
{
GenericBodyIReadOnlyListModel<GeneralCommandType> desiredValue = new()
{
Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown],
};
GenericBodyIReadOnlyListModel<GeneralCommandType>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that deserializing JSON array of strings succeeds.
/// </summary>
[Fact]
public void Deserialize_String_Array_Valid_Success()
{
GenericBodyIReadOnlyListModel<string> desiredValue = new()
{
Value = ["a", "b", "c"],
};
GenericBodyIReadOnlyListModel<string>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that deserializing JSON array of enums succeeds.
/// </summary>
[Fact]
public void Deserialize_GenericCommandType_Array_Valid_Success()
{
GenericBodyIReadOnlyListModel<GeneralCommandType> desiredValue = new()
{
Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown],
};
GenericBodyIReadOnlyListModel<GeneralCommandType>? value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", this.jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
/// <summary>
/// Tests that serializing IReadOnlyList succeeds.
/// </summary>
[Fact]
public void Serialize_GenericCommandType_IReadOnlyList_Valid_Success()
{
GenericBodyIReadOnlyListModel<GeneralCommandType> valueToSerialize = new()
{
Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown],
};
string value = JsonSerializer.Serialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(valueToSerialize, this.jsonOptions);
Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value);
}
}
}
#pragma warning restore CA1707