ParentIndexNumberComparerTests.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using Emby.Server.Implementations.Sorting;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Entities.Audio;
  6. using MediaBrowser.Controller.Sorting;
  7. using Xunit;
  8. namespace Jellyfin.Server.Implementations.Tests.Sorting;
  9. public class ParentIndexNumberComparerTests
  10. {
  11. private readonly IBaseItemComparer _cmp = new ParentIndexNumberComparer();
  12. private static TheoryData<BaseItem?, BaseItem?> Compare_GivenNull_ThrowsArgumentNullException_TestData()
  13. => new()
  14. {
  15. { null, new Audio() },
  16. { new Audio(), null }
  17. };
  18. [Theory]
  19. [MemberData(nameof(Compare_GivenNull_ThrowsArgumentNullException_TestData))]
  20. public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y)
  21. {
  22. Assert.Throws<ArgumentNullException>(() => _cmp.Compare(x, y));
  23. }
  24. [Theory]
  25. [InlineData(null, null, 0)]
  26. [InlineData(0, null, 1)]
  27. [InlineData(null, 0, -1)]
  28. [InlineData(1, 1, 0)]
  29. [InlineData(0, 1, -1)]
  30. [InlineData(1, 0, 1)]
  31. public void Compare_ValidIndices_SortsExpected(int? parentIndex1, int? parentIndex2, int expected)
  32. {
  33. BaseItem x = new Audio
  34. {
  35. ParentIndexNumber = parentIndex1
  36. };
  37. BaseItem y = new Audio
  38. {
  39. ParentIndexNumber = parentIndex2
  40. };
  41. Assert.Equal(expected, _cmp.Compare(x, y));
  42. Assert.Equal(-expected, _cmp.Compare(y, x));
  43. }
  44. }