Browse Source

play all items in playlist before starting again (#1711)

pull/1712/head
Jason Dove 2 years ago committed by GitHub
parent
commit
f5038c2b66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 151
      ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs
  2. 2
      ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs

151
ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs

@ -0,0 +1,151 @@ @@ -0,0 +1,151 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Scheduling;
using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
namespace ErsatzTV.Core.Tests.Scheduling;
[TestFixture]
public class PlaylistEnumeratorTests
{
[Test]
public async Task Test_PlayAll_Before_Last_PlaylistItem()
{
// test a 1 item, b 2 items play all, c 2 items
// a1, b1, b2, c1, a1, b1, b2, c2
// this isn't needed for chronological, so no need to implement anything
IMediaCollectionRepository repo = Substitute.For<IMediaCollectionRepository>();
var playlistItemMap = new Dictionary<PlaylistItem, List<MediaItem>>
{
{
new PlaylistItem
{
Id = 1,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = false,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 1
},
[FakeMovie(10)]
},
{
new PlaylistItem
{
Id = 2,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = true,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 2
},
[FakeMovie(20), FakeMovie(21)]
},
{
new PlaylistItem
{
Id = 3,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = false,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 3
},
[FakeMovie(30), FakeMovie(31)]
}
};
PlaylistEnumerator enumerator = await PlaylistEnumerator.Create(
repo,
playlistItemMap,
new CollectionEnumeratorState(),
CancellationToken.None);
enumerator.MoveNext();
var totalLength = 1;
while (enumerator.State.Index > 0)
{
enumerator.MoveNext();
totalLength += 1;
}
totalLength.Should().Be(8);
}
[Test]
public async Task Test_PlayAll_Last_PlaylistItem()
{
// test a 1 item, b 2 items, c 2 items play all
// a1, b1, c1, c2, a1, b2, c1, c2
// this isn't needed for chronological, so no need to implement anything
IMediaCollectionRepository repo = Substitute.For<IMediaCollectionRepository>();
var playlistItemMap = new Dictionary<PlaylistItem, List<MediaItem>>
{
{
new PlaylistItem
{
Id = 1,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = false,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 1
},
[FakeMovie(10)]
},
{
new PlaylistItem
{
Id = 2,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = false,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 2
},
[FakeMovie(20), FakeMovie(21)]
},
{
new PlaylistItem
{
Id = 3,
PlaybackOrder = PlaybackOrder.Chronological,
PlayAll = true,
CollectionType = ProgramScheduleItemCollectionType.Collection,
CollectionId = 3
},
[FakeMovie(30), FakeMovie(31)]
}
};
PlaylistEnumerator enumerator = await PlaylistEnumerator.Create(
repo,
playlistItemMap,
new CollectionEnumeratorState(),
CancellationToken.None);
enumerator.MoveNext();
var totalLength = 1;
while (enumerator.State.Index > 0)
{
enumerator.MoveNext();
totalLength += 1;
}
totalLength.Should().Be(8);
}
private static Movie FakeMovie(int id) => new()
{
Id = id,
MediaVersions = [],
MovieMetadata =
[
new MovieMetadata
{
ReleaseDate = new DateTime(2020, 1, id)
}
]
};
}

2
ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs

@ -59,7 +59,7 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator @@ -59,7 +59,7 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator
}
State.Index += 1;
if (_remainingMediaItemIds.Count == 0)
if (_remainingMediaItemIds.Count == 0 && _enumeratorIndex == 0 && _sortedEnumerators[0].State.Index == 0)
{
State.Index = 0;
_remainingMediaItemIds.UnionWith(_allMediaItemIds);

Loading…
Cancel
Save