diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2025-08-03 17:27:17 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-03 17:27:17 -0400 |
| commit | 4b6fb6c4bb2478badad068ce18aabe0c2955db48 (patch) | |
| tree | 15f986ee62327cceb8f5c8f009bcf08d10cfaa66 /tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs | |
| parent | e7bc86ebb8496615e0b3f73eb4f13ab4c0913dc8 (diff) | |
| parent | db7465e83d9cc07134a0bffad7ed17b1c7b873da (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs')
| -rw-r--r-- | tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs new file mode 100644 index 000000000..caf2b06b7 --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/Item/OrderMapperTests.cs @@ -0,0 +1,35 @@ +using System; +using Jellyfin.Data.Enums; +using Jellyfin.Database.Implementations.Entities; +using Jellyfin.Server.Implementations.Item; +using MediaBrowser.Controller.Entities; +using Xunit; + +namespace Jellyfin.Server.Implementations.Tests.Item; + +public class OrderMapperTests +{ + [Fact] + public void ShouldReturnMappedOrderForSortingByPremierDate() + { + var orderFunc = OrderMapper.MapOrderByField(ItemSortBy.PremiereDate, new InternalItemsQuery()).Compile(); + + 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); + } +} |
