Skip to content

Commit

Permalink
chore: Bump version (4.0.0-beta.3-6)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Nov 15, 2023
1 parent d7b2b66 commit 4badb94
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/Lavalink4NET.Tests/Players/QueuedLavalinkPlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,84 @@ await listener
apiClientMock.Verify();
}

[Fact]
public async Task TestQueueItemRetainedOnTrackEndAsync()
{
// Arrange
var sessionId = "abc";
var guildId = 0UL;

var apiClientMock = new Mock<ILavalinkApiClient>(MockBehavior.Strict);

var playerModel = new PlayerInformationModel(
GuildId: guildId,
CurrentTrack: new TrackModel(
Data: "track1",
Information: CreateDummyTrack(),
AdditionalInformation: ImmutableDictionary<string, JsonElement>.Empty),
Volume: 1F,
IsPaused: false,
VoiceState: CreateVoiceState(),
Filters: new PlayerFilterMapModel());

var resultModel = playerModel with
{
CurrentTrack = new TrackModel(
Data: "track2",
Information: CreateDummyTrack(),
AdditionalInformation: ImmutableDictionary<string, JsonElement>.Empty),
};

apiClientMock
.Setup(x => x.UpdatePlayerAsync(
sessionId,
guildId,
It.IsAny<PlayerUpdateProperties>(),
It.IsAny<CancellationToken>()))
.Callback(static (string sessionId, ulong guildId, PlayerUpdateProperties properties, CancellationToken token) =>
{
Assert.True(properties.Identifier.IsPresent);
Assert.Equal("track2", properties.Identifier.Value);
})
.ReturnsAsync(resultModel)
.Verifiable();

var discordClientMock = new Mock<IDiscordClientWrapper>();

var sessionProvider = Mock.Of<ILavalinkSessionProvider>(x
=> x.GetSessionAsync(guildId, It.IsAny<CancellationToken>())
== ValueTask.FromResult(new LavalinkPlayerSession(apiClientMock.Object, "abc", "abc")));

var playerProperties = new PlayerProperties<QueuedLavalinkPlayer, QueuedLavalinkPlayerOptions>(
Context: new PlayerContext(
ServiceProvider: null,
SessionProvider: sessionProvider,
DiscordClient: discordClientMock.Object,
SystemClock: new SystemClock(),
LifecycleNotifier: null),
Lifecycle: Mock.Of<IPlayerLifecycle>(),
ApiClient: apiClientMock.Object,
InitialState: playerModel,
Label: "Player",
VoiceChannelId: 0,
SessionId: sessionId,
Options: Options.Create(new QueuedLavalinkPlayerOptions()),
Logger: NullLogger<QueuedLavalinkPlayer>.Instance);

var player = new QueuedLavalinkPlayer(playerProperties);
await player.PlayAsync(new CustomTrackQueueItem(new TrackReference("track2")));

var listener = (ILavalinkPlayerListener)player;

// Act
await listener
.NotifyTrackEndedAsync(player.CurrentTrack!, TrackEndReason.Finished)
.ConfigureAwait(false);

// Assert
Assert.IsType<CustomTrackQueueItem>(player.CurrentItem);
}

[Fact]
public async Task TestPlayerRepeatsTrackIfRepeatModeIsTrackAsync()
{
Expand Down Expand Up @@ -570,3 +648,5 @@ private static VoiceStateModel CreateVoiceState()
SessionId: "abc");
}
}

public sealed record class CustomTrackQueueItem(TrackReference Reference) : ITrackQueueItem;

0 comments on commit 4badb94

Please sign in to comment.