2021-01-24 10:43:05 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Jellyfin.Api.Helpers;
|
|
|
|
using Jellyfin.Data.Enums;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Tests.Helpers
|
|
|
|
{
|
2021-02-11 16:46:27 +00:00
|
|
|
public static class RequestHelpersTests
|
2021-01-24 10:43:05 +00:00
|
|
|
{
|
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(GetOrderBy_Success_TestData))]
|
2021-02-11 16:46:27 +00:00
|
|
|
public static void GetOrderBy_Success(IReadOnlyList<string> sortBy, IReadOnlyList<SortOrder> requestedSortOrder, (string, SortOrder)[] expected)
|
2021-01-24 10:43:05 +00:00
|
|
|
{
|
|
|
|
Assert.Equal(expected, RequestHelpers.GetOrderBy(sortBy, requestedSortOrder));
|
|
|
|
}
|
|
|
|
|
2021-09-11 20:31:24 +00:00
|
|
|
public static TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]> GetOrderBy_Success_TestData()
|
2021-01-24 10:43:05 +00:00
|
|
|
{
|
2021-09-11 20:31:24 +00:00
|
|
|
var data = new TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]>();
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 10:43:05 +00:00
|
|
|
Array.Empty<string>(),
|
|
|
|
Array.Empty<SortOrder>(),
|
2021-09-11 20:31:24 +00:00
|
|
|
Array.Empty<(string, SortOrder)>());
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 10:43:05 +00:00
|
|
|
new string[]
|
|
|
|
{
|
|
|
|
"IsFavoriteOrLiked",
|
|
|
|
"Random"
|
|
|
|
},
|
|
|
|
Array.Empty<SortOrder>(),
|
|
|
|
new (string, SortOrder)[]
|
|
|
|
{
|
|
|
|
("IsFavoriteOrLiked", SortOrder.Ascending),
|
|
|
|
("Random", SortOrder.Ascending),
|
2021-09-11 20:31:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 10:43:05 +00:00
|
|
|
new string[]
|
|
|
|
{
|
|
|
|
"SortName",
|
|
|
|
"ProductionYear"
|
|
|
|
},
|
|
|
|
new SortOrder[]
|
|
|
|
{
|
|
|
|
SortOrder.Descending
|
|
|
|
},
|
|
|
|
new (string, SortOrder)[]
|
|
|
|
{
|
|
|
|
("SortName", SortOrder.Descending),
|
2021-01-24 16:55:25 +00:00
|
|
|
("ProductionYear", SortOrder.Descending),
|
2021-09-11 20:31:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
2021-01-24 10:43:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|