Files
jellyfin-jellyfin-1/tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs

36 lines
1.8 KiB
C#
Raw Normal View History

2025-03-27 20:05:03 -04:00
using System;
using Jellyfin.Data.Enums;
2025-03-27 19:46:45 -06:00
using Jellyfin.Database.Implementations.Entities;
2025-03-27 20:05:03 -04:00
using Jellyfin.Server.Implementations.Item;
using MediaBrowser.Controller.Entities;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Item;
public class OrderMapperTests
{
[Fact]
public void ShouldReturnMappedOrderForSortingByPremierDate()
{
2025-11-08 03:20:42 +02:00
var orderFunc = OrderMapper.MapOrderByField(ItemSortBy.PremiereDate, new InternalItemsQuery(), null!).Compile();
2025-03-27 20:05:03 -04:00
var expectedDate = new DateTime(1, 2, 3);
var expectedProductionYearDate = new DateTime(4, 1, 1);
var entityWithOnlyProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", ProductionYear = expectedProductionYearDate.Year };
var entityWithOnlyPremierDate = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", PremiereDate = expectedDate };
var entityWithBothPremierDateAndProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", PremiereDate = expectedDate, ProductionYear = expectedProductionYearDate.Year };
var entityWithoutEitherPremierDateOrProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test" };
var resultWithOnlyProductionYear = orderFunc(entityWithOnlyProductionYear);
var resultWithOnlyPremierDate = orderFunc(entityWithOnlyPremierDate);
var resultWithBothPremierDateAndProductionYear = orderFunc(entityWithBothPremierDateAndProductionYear);
var resultWithoutEitherPremierDateOrProductionYear = orderFunc(entityWithoutEitherPremierDateOrProductionYear);
Assert.Equal(resultWithOnlyProductionYear, expectedProductionYearDate);
Assert.Equal(resultWithOnlyPremierDate, expectedDate);
Assert.Equal(resultWithBothPremierDateAndProductionYear, expectedDate);
Assert.Null(resultWithoutEitherPremierDateOrProductionYear);
}
}