public async Task <ActionResult> Command_TrackAsync( [Name("Track Name")] [Description("The track to search for.")] [Remainder] [DefaultValueDescription("The track that you're currently listening to.")] string trackQuery = null) { SpotifyTrack track; if (trackQuery != null) { var tracks = await _spotify.SearchAsync(trackQuery, SearchType.Track).ConfigureAwait(false); track = tracks.Tracks.Items.FirstOrDefault(); } else { if (!(Context.Invoker.Activity is SpotifyGame spot)) { return(BadRequest("You didn't supply a track, and you're not currently listening to anything!")); } track = await _spotify.GetTrackAsync(spot.TrackId).ConfigureAwait(false); } if (track == null) { return(BadRequest("Cannot find a track by that name.")); } return(Ok(CreateTrackEmbed(track))); }
public async Task Test_Track_Fetch() { var track = await _client.GetTrackAsync("2WDffjRjjtxHcHCHkLpB5p"); Assert.IsNotNull(track); Assert.AreEqual("2WDffjRjjtxHcHCHkLpB5p", track.Id.Id); Assert.AreEqual("Queen Of The Night", track.Name); Assert.AreEqual("Queen Of The Night", track.Album.Name); Assert.AreEqual("1BWJHMlxzPea13xJIgVxg0", track.Album.Id.Id); Assert.AreEqual("Hey Violet", track.Artists[0].Name); Assert.AreEqual("4JNfz6aO9ZFz0gp5GY88am", track.Artists[0].Id.Id); Assert.AreEqual(1, track.TrackNumber); Assert.AreEqual(TimeSpan.FromSeconds(197.497), track.Duration); Assert.IsTrue(track.HasExplicitLyrics); }