jellyfin-server/tests/Jellyfin.Server.Implementations.Tests/Sorting/IndexNumberComparerTests.cs
Cody Robibero 04cac23a11 Merge pull request #7548 from 1337joe/comparer-null-fix
(cherry picked from commit 72aca1519132315a69d9dad53e4840f461e58285)
Signed-off-by: crobibero <cody@robibe.ro>
2022-04-07 12:54:58 -04:00

50 lines
1.4 KiB
C#

using System;
using Emby.Server.Implementations.Sorting;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Sorting;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Sorting;
public class IndexNumberComparerTests
{
private readonly IBaseItemComparer _cmp = new IndexNumberComparer();
private static TheoryData<BaseItem?, BaseItem?> Compare_GivenNull_ThrowsArgumentNullException_TestData()
=> new()
{
{ null, new Audio() },
{ new Audio(), null }
};
[Theory]
[MemberData(nameof(Compare_GivenNull_ThrowsArgumentNullException_TestData))]
public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y)
{
Assert.Throws<ArgumentNullException>(() => _cmp.Compare(x, y));
}
[Theory]
[InlineData(null, null, 0)]
[InlineData(0, null, 1)]
[InlineData(null, 0, -1)]
[InlineData(1, 1, 0)]
[InlineData(0, 1, -1)]
[InlineData(1, 0, 1)]
public void Compare_ValidIndices_SortsExpected(int? index1, int? index2, int expected)
{
BaseItem x = new Audio
{
IndexNumber = index1
};
BaseItem y = new Audio
{
IndexNumber = index2
};
Assert.Equal(expected, _cmp.Compare(x, y));
Assert.Equal(-expected, _cmp.Compare(y, x));
}
}