public async Task ShouldRemoveSpecificOccurrencesOfItemsFromPlaylist() { // Arrange const string playlistId = "40C5k2GWBlficlUyQKmR0S"; const string snapshotId = "initialsnapshot"; var urisWithPositions = new[] { new UriWithPositions { Uri = SpotifyUri.OfTrack("3n3Ppam7vgaVa1iaRUc9Lp"), Positions = new[] { 1, 2 } }, new UriWithPositions { Uri = SpotifyUri.OfEpisode("512ojhOuo1ktJprKbVcKyQ"), Positions = null }, new UriWithPositions { Uri = SpotifyUri.OfTrack("3twNvmDtFQtAd5gMKedhLD"), Positions = new[] { 5 } }, }; this.MockHttp .ExpectSpotifyRequest(HttpMethod.Delete, $"playlists/{playlistId}/tracks") .WithExactQueryString(string.Empty) .WithJsonContent(j => { if (!(j.EnumerateObject().Count() == 2 && j.TryGetProperty("snapshot_id", out var snapshotProperty) && snapshotProperty.GetString() == snapshotId && j.TryGetProperty("tracks", out var array))) { return(false); } return (array.EnumerateArray().Count() == 3 && array[0].EnumerateObject().Count() == 2 && array[0].GetProperty("uri").GetString() == urisWithPositions[0].Uri && array[0].GetProperty("positions").EnumerateArray().Select(x => x.GetInt32()).SequenceEqual(urisWithPositions[0].Positions) && array[1].EnumerateObject().Count() == 1 && array[1].GetProperty("uri").GetString() == urisWithPositions[1].Uri && array[2].EnumerateObject().Count() == 2 && array[2].GetProperty("uri").GetString() == urisWithPositions[2].Uri && array[2].GetProperty("positions").EnumerateArray().Select(x => x.GetInt32()).SequenceEqual(urisWithPositions[2].Positions)); }) .Respond(HttpStatusCode.OK, "application/json", "{}"); // Act var result = await this.Client.Playlists(playlistId).Items.RemoveAsync(urisWithPositions, snapshotId); // Assert this.MockHttp.VerifyNoOutstandingExpectation(); result.Should().NotBeNull(); }
public async Task ShouldStartNewPlaybackForActiveDeviceFromUris() { // Arrange var uris = new[] { SpotifyUri.OfAlbum("6akEvsycLGftJxYudPjmqK"), SpotifyUri.OfEpisode("512ojhOuo1ktJprKbVcKyQ") }; this.MockHttp .ExpectSpotifyRequest(HttpMethod.Put, $"me/player/play") .WithExactQueryString(string.Empty) .WithJsonContent(j => j.EnumerateObject().Count() == 1 && j.TryGetProperty("uris", out var array) && array.EnumerateArray().ToArray().Select(x => x.GetString()).SequenceEqual(uris)) .Respond(HttpStatusCode.OK); // Act await this.Client.Me.Player.Playback().StartNewAsync(uris); // Assert this.MockHttp.VerifyNoOutstandingExpectation(); }
public async Task ShouldStartNewPlaybackForDeviceFromUrisWithAllParams() { // Arrange const string deviceId = "device1"; var positon = TimeSpan.FromSeconds(10); var uris = new[] { SpotifyUri.OfAlbum("6akEvsycLGftJxYudPjmqK"), SpotifyUri.OfEpisode("512ojhOuo1ktJprKbVcKyQ") }; var offset = uris[1]; this.MockHttp .ExpectSpotifyRequest(HttpMethod.Put, $"me/player/play") .WithExactQueryString(new Dictionary <string, string> { ["device_id"] = deviceId }) .WithJsonContent(j => j.EnumerateObject().Count() == 3 && j.TryGetProperty("uris", out var array) && array.EnumerateArray().ToArray().Select(x => x.GetString()).SequenceEqual(uris) && j.TryGetProperty("offset", out var offsetProperty) && offsetProperty.EnumerateObject().Count() == 1 && offsetProperty.TryGetProperty("uri", out var uriProperty) && uriProperty.GetString() == offset && j.TryGetProperty("position_ms", out var positionMs) && positionMs.GetInt32() == 10000) .Respond(HttpStatusCode.OK, "application/json", "{}"); // Act await this.Client.Me.Player.Playback(deviceId).StartNewAsync(uris, offset, positon); // Assert this.MockHttp.VerifyNoOutstandingExpectation(); }
public async Task ShouldReplacePlaylistItems() { // Arrange const string playlistId = "40C5k2GWBlficlUyQKmR0S"; var uris = new[] { SpotifyUri.OfTrack("3n3Ppam7vgaVa1iaRUc9Lp"), SpotifyUri.OfEpisode("512ojhOuo1ktJprKbVcKyQ") }; this.MockHttp .ExpectSpotifyRequest(HttpMethod.Put, $"playlists/{playlistId}/tracks") .WithExactQueryString(string.Empty) .WithJsonContent(j => j.EnumerateObject().Count() == 1 && j.TryGetProperty("uris", out var array) && array.EnumerateArray().ToArray().Select(x => x.GetString()).SequenceEqual(uris)) .Respond(HttpStatusCode.OK, "application/json", "{}"); // Act var result = await this.Client.Playlists(playlistId).Items.ReplaceAsync(uris); // Assert this.MockHttp.VerifyNoOutstandingExpectation(); result.Should().NotBeNull(); }