2021-08-07 15:07:12 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
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-08-15 15:23:18 -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
|
|
|
}
|
|
|
|
|
|
|
|
private class EpisodeBadData : IEnumerable<object?[]>
|
|
|
|
{
|
|
|
|
public IEnumerator<object?[]> GetEnumerator()
|
2021-08-07 15:07:12 -07:00
|
|
|
{
|
2021-08-11 09:56:36 -07:00
|
|
|
yield return new object?[] { null, new Episode() };
|
2021-08-15 15:26:00 -07:00
|
|
|
yield return new object?[] { new Episode(), null };
|
2021-08-07 15:07:12 -07:00
|
|
|
}
|
2021-08-11 09:56:36 -07:00
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
2021-08-07 15:07:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private class EpisodeTestData : IEnumerable<object?[]>
|
|
|
|
{
|
|
|
|
public IEnumerator<object?[]> GetEnumerator()
|
|
|
|
{
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Movie(),
|
|
|
|
new Movie(),
|
|
|
|
0
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Movie(),
|
|
|
|
new Episode(),
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
// Good cases
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode(),
|
|
|
|
new Episode(),
|
|
|
|
0
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 2, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
// Good Specials
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
|
|
|
|
// Specials to Episodes
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 2 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 3, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 3, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
|
2021-08-15 15:31:58 -07:00
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 2 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
|
|
|
1
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
yield return new object?[]
|
|
|
|
{
|
|
|
|
new Episode { ParentIndexNumber = 1, IndexNumber = 3 },
|
|
|
|
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
|
|
|
|
1
|
|
|
|
};
|
2021-08-07 15:07:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|