OrderMapperTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using Jellyfin.Data.Enums;
  3. using Jellyfin.Database.Implementations.Entities;
  4. using Jellyfin.Server.Implementations.Item;
  5. using MediaBrowser.Controller.Entities;
  6. using Xunit;
  7. namespace Jellyfin.Server.Implementations.Tests.Item;
  8. public class OrderMapperTests
  9. {
  10. [Fact]
  11. public void ShouldReturnMappedOrderForSortingByPremierDate()
  12. {
  13. var orderFunc = OrderMapper.MapOrderByField(ItemSortBy.PremiereDate, new InternalItemsQuery()).Compile();
  14. var expectedDate = new DateTime(1, 2, 3);
  15. var expectedProductionYearDate = new DateTime(4, 1, 1);
  16. var entityWithOnlyProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", ProductionYear = expectedProductionYearDate.Year };
  17. var entityWithOnlyPremierDate = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", PremiereDate = expectedDate };
  18. var entityWithBothPremierDateAndProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test", PremiereDate = expectedDate, ProductionYear = expectedProductionYearDate.Year };
  19. var entityWithoutEitherPremierDateOrProductionYear = new BaseItemEntity { Id = Guid.NewGuid(), Type = "Test" };
  20. var resultWithOnlyProductionYear = orderFunc(entityWithOnlyProductionYear);
  21. var resultWithOnlyPremierDate = orderFunc(entityWithOnlyPremierDate);
  22. var resultWithBothPremierDateAndProductionYear = orderFunc(entityWithBothPremierDateAndProductionYear);
  23. var resultWithoutEitherPremierDateOrProductionYear = orderFunc(entityWithoutEitherPremierDateOrProductionYear);
  24. Assert.Equal(resultWithOnlyProductionYear, expectedProductionYearDate);
  25. Assert.Equal(resultWithOnlyPremierDate, expectedDate);
  26. Assert.Equal(resultWithBothPremierDateAndProductionYear, expectedDate);
  27. Assert.Null(resultWithoutEitherPremierDateOrProductionYear);
  28. }
  29. }