Lowercase CollectionTypeOptions to match legacy experience (#11272)
parent
d9fe900952
commit
3ade3a8e63
@ -1,16 +1,49 @@
|
||||
#pragma warning disable CS1591
|
||||
#pragma warning disable SA1300 // Lowercase required for backwards compat.
|
||||
|
||||
namespace MediaBrowser.Model.Entities
|
||||
namespace MediaBrowser.Model.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// The collection type options.
|
||||
/// </summary>
|
||||
public enum CollectionTypeOptions
|
||||
{
|
||||
public enum CollectionTypeOptions
|
||||
{
|
||||
Movies = 0,
|
||||
TvShows = 1,
|
||||
Music = 2,
|
||||
MusicVideos = 3,
|
||||
HomeVideos = 4,
|
||||
BoxSets = 5,
|
||||
Books = 6,
|
||||
Mixed = 7
|
||||
}
|
||||
/// <summary>
|
||||
/// Movies.
|
||||
/// </summary>
|
||||
movies = 0,
|
||||
|
||||
/// <summary>
|
||||
/// TV Shows.
|
||||
/// </summary>
|
||||
tvshows = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Music.
|
||||
/// </summary>
|
||||
music = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Music Videos.
|
||||
/// </summary>
|
||||
musicvideos = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Home Videos (and Photos).
|
||||
/// </summary>
|
||||
homevideos = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Box Sets.
|
||||
/// </summary>
|
||||
boxsets = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Books.
|
||||
/// </summary>
|
||||
books = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Mixed Movies and TV Shows.
|
||||
/// </summary>
|
||||
mixed = 7
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Jellyfin.Extensions.Json.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an object to a lowercase string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The object type.</typeparam>
|
||||
public class JsonLowerCaseConverter<T> : JsonConverter<T>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(ref reader, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value?.ToString()?.ToLowerInvariant());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Jellyfin.Extensions.Json.Converters;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Extensions.Tests.Json.Converters
|
||||
{
|
||||
public class JsonLowerCaseConverterTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
}
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "{\"CollectionType\":null}")]
|
||||
[InlineData(CollectionTypeOptions.Movies, "{\"CollectionType\":\"movies\"}")]
|
||||
[InlineData(CollectionTypeOptions.MusicVideos, "{\"CollectionType\":\"musicvideos\"}")]
|
||||
public void Serialize_CollectionTypeOptions_Correct(CollectionTypeOptions? collectionType, string expected)
|
||||
{
|
||||
Assert.Equal(expected, JsonSerializer.Serialize(new TestContainer(collectionType), _jsonOptions));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"CollectionType\":null}", null)]
|
||||
[InlineData("{\"CollectionType\":\"movies\"}", CollectionTypeOptions.Movies)]
|
||||
[InlineData("{\"CollectionType\":\"musicvideos\"}", CollectionTypeOptions.MusicVideos)]
|
||||
public void Deserialize_CollectionTypeOptions_Correct(string json, CollectionTypeOptions? result)
|
||||
{
|
||||
var res = JsonSerializer.Deserialize<TestContainer>(json, _jsonOptions);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(result, res!.CollectionType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData(CollectionTypeOptions.Movies)]
|
||||
[InlineData(CollectionTypeOptions.MusicVideos)]
|
||||
public void RoundTrip_CollectionTypeOptions_Correct(CollectionTypeOptions? value)
|
||||
{
|
||||
var res = JsonSerializer.Deserialize<TestContainer>(JsonSerializer.Serialize(new TestContainer(value), _jsonOptions), _jsonOptions);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(value, res!.CollectionType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"CollectionType\":null}")]
|
||||
[InlineData("{\"CollectionType\":\"movies\"}")]
|
||||
[InlineData("{\"CollectionType\":\"musicvideos\"}")]
|
||||
public void RoundTrip_String_Correct(string json)
|
||||
{
|
||||
var res = JsonSerializer.Serialize(JsonSerializer.Deserialize<TestContainer>(json, _jsonOptions), _jsonOptions);
|
||||
Assert.Equal(json, res);
|
||||
}
|
||||
|
||||
private sealed class TestContainer
|
||||
{
|
||||
public TestContainer(CollectionTypeOptions? collectionType)
|
||||
{
|
||||
CollectionType = collectionType;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonLowerCaseConverter<CollectionTypeOptions?>))]
|
||||
public CollectionTypeOptions? CollectionType { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue