PremiereDateComparerTests.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using Emby.Server.Implementations.Sorting;
  3. using MediaBrowser.Controller.Entities;
  4. using MediaBrowser.Controller.Entities.Movies;
  5. using Xunit;
  6. namespace Jellyfin.Server.Implementations.Tests.Sorting
  7. {
  8. public class PremiereDateComparerTests
  9. {
  10. private readonly PremiereDateComparer _cmp = new PremiereDateComparer();
  11. [Theory]
  12. [ClassData(typeof(PremiereDateTestData))]
  13. public void PremiereDateCompareTest(BaseItem x, BaseItem y, int expected)
  14. {
  15. Assert.Equal(expected, _cmp.Compare(x, y));
  16. Assert.Equal(-expected, _cmp.Compare(y, x));
  17. }
  18. private sealed class PremiereDateTestData : TheoryData<BaseItem, BaseItem, int>
  19. {
  20. public PremiereDateTestData()
  21. {
  22. // Happy case - Both have premier date
  23. // Expected: x listed first
  24. Add(
  25. new Movie { PremiereDate = new DateTime(2018, 1, 1) },
  26. new Movie { PremiereDate = new DateTime(2018, 1, 3) },
  27. -1);
  28. // Both have premiere date, but y has invalid date
  29. // Expected: y listed first
  30. Add(
  31. new Movie { PremiereDate = new DateTime(2019, 1, 1) },
  32. new Movie { PremiereDate = new DateTime(03, 1, 1) },
  33. 1);
  34. // Only x has premiere date, with earlier year than y
  35. // Expected: x listed first
  36. Add(
  37. new Movie { PremiereDate = new DateTime(2020, 1, 1) },
  38. new Movie { ProductionYear = 2021 },
  39. -1);
  40. // Only x has premiere date, with same year as y
  41. // Expected: y listed first
  42. Add(
  43. new Movie { PremiereDate = new DateTime(2022, 1, 2) },
  44. new Movie { ProductionYear = 2022 },
  45. 1);
  46. // Only x has a premiere date, with later year than y
  47. // Expected: y listed first
  48. Add(
  49. new Movie { PremiereDate = new DateTime(2024, 3, 1) },
  50. new Movie { ProductionYear = 2023 },
  51. 1);
  52. // Only x has a premiere date, y has an invalid year
  53. // Expected: y listed first
  54. Add(
  55. new Movie { PremiereDate = new DateTime(2025, 1, 1) },
  56. new Movie { ProductionYear = 0 },
  57. 1);
  58. // Only x has a premiere date, y has neither date nor year
  59. // Expected: y listed first
  60. Add(
  61. new Movie { PremiereDate = new DateTime(2026, 1, 1) },
  62. new Movie(),
  63. 1);
  64. }
  65. }
  66. }
  67. }