2021-08-07 15:07:12 -07:00
|
|
|
using System;
|
|
|
|
using Emby.Server.Implementations.Sorting;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Implementations.Tests.Sorting
|
|
|
|
{
|
|
|
|
public class AiredEpisodeOrderComparerTests
|
|
|
|
{
|
2021-08-11 09:56:36 -07:00
|
|
|
[Theory]
|
|
|
|
[ClassData(typeof(EpisodeBadData))]
|
2021-09-11 13:31:24 -07:00
|
|
|
public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y)
|
2021-08-11 09:56:36 -07:00
|
|
|
{
|
|
|
|
var cmp = new AiredEpisodeOrderComparer();
|
|
|
|
Assert.Throws<ArgumentNullException>(() => cmp.Compare(x, y));
|
|
|
|
}
|
|
|
|
|
2021-08-07 15:07:12 -07:00
|
|
|
[Theory]
|
|
|
|
[ClassData(typeof(EpisodeTestData))]
|
2021-08-11 09:56:36 -07:00
|
|
|
public void AiredEpisodeOrderCompareTest(BaseItem x, BaseItem y, int expected)
|
2021-08-07 15:07:12 -07:00
|
|
|
{
|
|
|
|
var cmp = new AiredEpisodeOrderComparer();
|
2021-08-11 09:56:36 -07:00
|
|
|
|
|
|
|
Assert.Equal(expected, cmp.Compare(x, y));
|
2021-08-15 15:48:01 -07:00
|
|
|
Assert.Equal(-expected, cmp.Compare(y, x));
|
2021-08-11 09:56:36 -07:00
|
|
|
}
|
|
|
|
|
2022-12-14 14:03:03 -07:00
|
|
|
private sealed class EpisodeBadData : TheoryData<BaseItem?, BaseItem?>
|
2021-08-11 09:56:36 -07:00
|
|
|
{
|
2021-09-11 13:31:24 -07:00
|
|
|
public EpisodeBadData()
|
2021-08-07 15:07:12 -07:00
|
|
|
{
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(null, new Episode());
|
|
|
|
Add(new Episode(), null);
|
2021-08-07 15:07:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:03:03 -07:00
|
|
|
private sealed class EpisodeTestData : TheoryData<BaseItem, BaseItem, int>
|
2021-08-07 15:07:12 -07:00
|
|
|
{
|
2021-09-11 13:31:24 -07:00
|
|
|
public EpisodeTestData()
|
2021-08-07 15:07:12 -07:00
|
|
|
{
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Movie(),
|
|
|
|
new Movie(),
|
2021-09-11 13:31:24 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Movie(),
|
|
|
|
new Episode(),
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
2021-08-07 15:07:12 -07:00
|
|
|
// Good cases
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode(),
|
|
|
|
new Episode(),
|
2021-09-11 13:31:24 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 2, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
2021-08-07 15:07:12 -07:00
|
|
|
// Good Specials
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
|
|
|
|
// Specials to Episodes
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 3, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 3, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-09-11 13:31:24 -07:00
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-08-15 15:31:58 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 3 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
2021-09-11 13:31:24 -07:00
|
|
|
1);
|
2021-09-25 13:24:57 -07:00
|
|
|
|
2021-09-12 15:05:37 -07:00
|
|
|
// Premiere Date
|
2021-09-25 13:24:57 -07:00
|
|
|
Add(
|
2021-09-12 15:05:37 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) },
|
2021-09-25 13:24:57 -07:00
|
|
|
0);
|
|
|
|
|
|
|
|
Add(
|
2021-09-12 15:05:37 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 11, 0, 0, 0) },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) },
|
2021-09-25 13:24:57 -07:00
|
|
|
-1);
|
|
|
|
|
|
|
|
Add(
|
2021-09-12 15:05:37 -07:00
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 11, 0, 0, 0) },
|
2021-09-25 13:24:57 -07:00
|
|
|
1);
|
2021-08-07 15:07:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|