mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-04-27 03:53:10 -04:00
94 lines
3.0 KiB
C#
94 lines
3.0 KiB
C#
using System.Reflection;
|
|
using System.Text.Json;
|
|
using allstarr.Controllers;
|
|
using allstarr.Models.Jellyfin;
|
|
|
|
namespace allstarr.Tests;
|
|
|
|
public class JellyfinSearchResponseSerializationTests
|
|
{
|
|
[Fact]
|
|
public void SerializeSearchResponseJson_PreservesPascalCaseShape()
|
|
{
|
|
var payload = new JellyfinItemsResponse
|
|
{
|
|
Items =
|
|
[
|
|
new Dictionary<string, object?>
|
|
{
|
|
["Name"] = "BTS",
|
|
["Type"] = "MusicAlbum"
|
|
}
|
|
],
|
|
TotalRecordCount = 1,
|
|
StartIndex = 0
|
|
};
|
|
|
|
var method = typeof(JellyfinController).GetMethod(
|
|
"SerializeSearchResponseJson",
|
|
BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
Assert.NotNull(method);
|
|
|
|
var json = (string)method!.Invoke(null, new object?[] { payload })!;
|
|
|
|
Assert.Equal(
|
|
"{\"Items\":[{\"Name\":\"BTS\",\"Type\":\"MusicAlbum\"}],\"TotalRecordCount\":1,\"StartIndex\":0}",
|
|
json);
|
|
}
|
|
|
|
[Fact]
|
|
public void SerializeSearchResponseJson_FallsBackForMixedRuntimeShapes()
|
|
{
|
|
using var rawDoc = JsonDocument.Parse("""
|
|
{
|
|
"ServerId": "c17d351d3af24c678a6d8049c212d522",
|
|
"RunTimeTicks": 2234068710
|
|
}
|
|
""");
|
|
|
|
var payload = new JellyfinItemsResponse
|
|
{
|
|
Items =
|
|
[
|
|
new Dictionary<string, object?>
|
|
{
|
|
["Name"] = "Harleys in Hawaii",
|
|
["Type"] = "MusicAlbum",
|
|
["MediaSources"] = new Dictionary<string, object?>[]
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["RunTimeTicks"] = 2234068710L,
|
|
["MediaAttachments"] = new List<object>(),
|
|
["Formats"] = new List<string>(),
|
|
["RequiredHttpHeaders"] = new Dictionary<string, string>()
|
|
}
|
|
},
|
|
["ArtistItems"] = new List<object>
|
|
{
|
|
new Dictionary<string, object?> { ["Name"] = "Katy Perry" }
|
|
},
|
|
["RawItem"] = rawDoc.RootElement.Clone()
|
|
}
|
|
],
|
|
TotalRecordCount = 1,
|
|
StartIndex = 0
|
|
};
|
|
|
|
var method = typeof(JellyfinController).GetMethod(
|
|
"SerializeSearchResponseJson",
|
|
BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
Assert.NotNull(method);
|
|
|
|
var json = (string)method!.Invoke(null, new object?[] { payload })!;
|
|
|
|
Assert.Contains("\"Items\":[{", json);
|
|
Assert.Contains("\"MediaAttachments\":[]", json);
|
|
Assert.Contains("\"ArtistItems\":[{\"Name\":\"Katy Perry\"}]", json);
|
|
Assert.Contains("\"RawItem\":{\"ServerId\":\"c17d351d3af24c678a6d8049c212d522\",\"RunTimeTicks\":2234068710}", json);
|
|
Assert.Contains("\"TotalRecordCount\":1", json);
|
|
}
|
|
}
|