/// <summary> /// Retrieves top artists of a selected genre from Nokia Music API. /// </summary> /// <param name="id">Id of the genre.</param> public void GetTopArtistsForGenre(string id) { if (!initialized) { return; } client.GetTopArtistsForGenre((ListResponse <Artist> response) => { Deployment.Current.Dispatcher.BeginInvoke(() => { // Use results if (response != null && response.Result != null && response.Result.Count > 0) { App.ViewModel.TopArtistsForGenre.Clear(); foreach (Artist a in response.Result) { App.ViewModel.TopArtistsForGenre.Add(new ArtistModel() { Name = a.Name, Country = CountryCodes.CountryNameFromTwoLetter(a.Country), Genres = a.Genres[0].Name, Thumb100Uri = a.Thumb100Uri, Thumb200Uri = a.Thumb200Uri, Thumb320Uri = a.Thumb320Uri, Id = a.Id, ItemWidth = "205", ItemHeight = "205" }); } } if (response != null && response.Error != null) { ShowNokiaMusicApiError(); } HideProgressIndicator("GetTopArtistsForGenre()"); }); }, id); ShowProgressIndicator("GetTopArtistsForGenre()"); }
public void EnsureGetTopArtistsForGenreReturnsErrorForFailedCall() { IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound())); client.GetTopArtistsForGenre( (ListResponse<Artist> result) => { Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.StatusCode, "Expected a status code"); Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code"); Assert.AreNotEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a non-200 response"); Assert.IsNull(result.Result, "Expected no results"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException"); }, "rock"); }
public void EnsureGetTopArtistsForGenreReturnsArtists() { IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.top_artists_genre)); client.GetTopArtistsForGenre( (ListResponse<Artist> result) => { Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.StatusCode, "Expected a status code"); Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code"); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response"); Assert.IsNotNull(result.Result, "Expected a list of results"); Assert.IsNull(result.Error, "Expected no error"); Assert.Greater(result.Result.Count, 0, "Expected more than 0 results"); }, new Genre() { Id = "rock" }); }
public void EnsureGetTopArtistsForGenreThrowsExceptionForNullCallback() { IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.top_artists_genre)); client.GetTopArtistsForGenre(null, "rock"); }
public void EnsureGetTopArtistsForGenreThrowsExceptionForNullGenre() { Genre nullGenre = null; IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.top_artists_genre)); client.GetTopArtistsForGenre((ListResponse<Artist> result) => { }, nullGenre); }
public void EnsureGetTopArtistsForGenreThrowsExceptionForNullCallback() { IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler()); client.GetTopArtistsForGenre(null, "rock"); }
public void EnsureGetTopArtistsForGenreThrowsExceptionForNullGenreId() { string nullId = null; IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler()); client.GetTopArtistsForGenre((ListResponse<Artist> result) => { }, nullId); }