mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.0 KiB
100 lines
3.0 KiB
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Scheduling; |
|
using Shouldly; |
|
using NUnit.Framework; |
|
|
|
namespace ErsatzTV.Core.Tests.Scheduling; |
|
|
|
public class CustomOrderContentTests |
|
{ |
|
private CancellationToken _cancellationToken; |
|
|
|
[SetUp] |
|
public void SetUp() => _cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token; |
|
|
|
[Test] |
|
public void MediaItems_Should_Sort_By_CustomOrder() |
|
{ |
|
Collection collection = CreateCollection(10); |
|
List<MediaItem> contents = Episodes(10); |
|
var state = new CollectionEnumeratorState(); |
|
|
|
var customOrderContent = new CustomOrderCollectionEnumerator(collection, contents, state); |
|
|
|
for (var i = 10; i >= 1; i--) |
|
{ |
|
customOrderContent.Current.IsSome.ShouldBeTrue(); |
|
customOrderContent.Current.Map(x => x.Id).IfNone(-1).ShouldBe(i); |
|
customOrderContent.MoveNext(); |
|
} |
|
} |
|
|
|
[Test] |
|
public void State_Index_Should_Increment() |
|
{ |
|
Collection collection = CreateCollection(10); |
|
List<MediaItem> contents = Episodes(10); |
|
var state = new CollectionEnumeratorState(); |
|
|
|
var customOrderContent = new CustomOrderCollectionEnumerator(collection, contents, state); |
|
|
|
for (var i = 0; i < 10; i++) |
|
{ |
|
customOrderContent.State.Index.ShouldBe(i % 10); |
|
customOrderContent.MoveNext(); |
|
} |
|
} |
|
|
|
[Test] |
|
public void State_Should_Impact_Iterator_Start() |
|
{ |
|
Collection collection = CreateCollection(10); |
|
List<MediaItem> contents = Episodes(10); |
|
var state = new CollectionEnumeratorState { Index = 5 }; |
|
|
|
var customOrderContent = new CustomOrderCollectionEnumerator(collection, contents, state); |
|
|
|
for (var i = 5; i >= 1; i--) |
|
{ |
|
customOrderContent.Current.IsSome.ShouldBeTrue(); |
|
customOrderContent.Current.Map(x => x.Id).IfNone(-1).ShouldBe(i); |
|
customOrderContent.State.Index.ShouldBe(5 - i + 5); // 5 through 10 |
|
customOrderContent.MoveNext(); |
|
} |
|
} |
|
|
|
private static Collection CreateCollection(int episodeCount) |
|
{ |
|
var collection = new Collection { CollectionItems = new List<CollectionItem>() }; |
|
|
|
for (var i = 1; i <= episodeCount; i++) |
|
{ |
|
collection.CollectionItems.Add( |
|
new CollectionItem |
|
{ |
|
MediaItemId = i, |
|
// reverse order |
|
CustomIndex = episodeCount - i |
|
}); |
|
} |
|
|
|
return collection; |
|
} |
|
|
|
|
|
private static List<MediaItem> Episodes(int count) => |
|
Range(1, count).Map( |
|
i => (MediaItem)new Episode |
|
{ |
|
Id = i, |
|
EpisodeMetadata = new List<EpisodeMetadata> |
|
{ |
|
new() |
|
{ |
|
ReleaseDate = new DateTime(2020, 1, i) |
|
} |
|
} |
|
}) |
|
.Reverse() |
|
.ToList(); |
|
}
|
|
|