public void GetCurrentSong() { // TODO: Finish figuring out best way to unit test the third party api CurrentSongDTO currentSongDto = new CurrentSongDTO { Album = "", AlbumArtUrl = "", Artist = "", ProgressMs = 0, Title = "", TrackUri = "" }; HttpResponseMessage responseMessage = new HttpResponseMessage { Content = new StringContent("", Encoding.UTF8, "application/json") }; _spotifyAuthentication.Setup(p => p.GetAuthenticationHeaderForPartyGoerAsync(PARTY_GOER_ID)).Returns(Task.FromResult(new AuthenticationHeaderValue("Bearer"))); _httpClient.Setup(p => p.SendAsync(It.IsAny <HttpRequestMessage>())).Returns(Task.FromResult(new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent("") } )); //var currentSong = await _spotifyHttpClient.GetCurrentSongAsync(PARTY_GOER_ID); Assert.Inconclusive(); }
public async Task <ServiceResult <UpdateSongError> > UpdateCurrentSongForEveryoneInPartyAsync(Party party, PartyGoer user) { try { if (party is null) { throw new Exception($"Obtaining a party with ID {party.Id} returned null from the database"); } if (!party.Host.Id.Equals(user.Id, StringComparison.CurrentCultureIgnoreCase) && !party.Listeners.Exists(p => p.Id.Equals(user.Id, StringComparison.CurrentCultureIgnoreCase))) { throw new Exception($"A non host or party attendee tried to change the song for the party with ID {party.Id}. Attempted user ID: {user.Id}"); } // Get the current song from the host CurrentSongDTO song = await _spotifyHttpClient.GetCurrentSongAsync(user.Id); List <Task <ServiceResult <UpdateSongError> > > updateSongForPartyTask = new List <Task <ServiceResult <UpdateSongError> > >(); foreach (PartyGoer attendee in party.Listeners) { updateSongForPartyTask.Add(_spotifyHttpClient.UpdateSongForPartyGoerAsync(attendee.Id, new List <string> { song.TrackUri }, song.ProgressMs)); } await Task.WhenAll(updateSongForPartyTask); ServiceResult <UpdateSongError> errors = new ServiceResult <UpdateSongError>(); // Verify all the updates worked foreach (Task <ServiceResult <UpdateSongError> > task in updateSongForPartyTask) { if (task.IsCompletedSuccessfully && !task.Result.Success) { foreach (var error in task.Result.Errors) { errors.AddError(error); } } } return(errors); } catch (Exception ex) { await _logService.LogExceptionAsync(ex, "Error occurred in UpdateCurrentSongForEveryoneInPartyAsync"); ServiceResult <UpdateSongError> error = new ServiceResult <UpdateSongError>(); error.AddError(new UpdateSongError("Unable to update everyone's song.")); return(error); } }