Ejemplo n.º 1
0
 public void EnsureGetArtistProductsReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new FailedMockApiRequestHandler());
     client.GetArtistProducts(
         (ListResponse<Product> 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-OK response");
             Assert.IsNotNull(result.Error, "Expected an error");
             Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException");
         },
         "test");
 }
Ejemplo n.º 2
0
 public void EnsureGetArtistProductsThrowsExceptionForNullCallback()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetArtistProducts(null, "test");
 }
Ejemplo n.º 3
0
 public void EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetArtistProducts(this.ProductResponse, new Artist() { Id = "test" }, Category.Album);
     client.GetArtistProducts(this.ProductResponse, "test");
 }
Ejemplo n.º 4
0
 public void EnsureGetArtistProductsThrowsExceptionForNullArtist()
 {
     Artist nullArtist = null;
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetArtistProducts((ListResponse<Product> result) => { }, nullArtist);
 }
 public void EnsureGetArtistProductsThrowsExceptionForNullCallback()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     client.GetArtistProducts(null, "test");
 }
 public void EnsureGetArtistProductsThrowsExceptionForNullArtistId()
 {
     string nullId = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     client.GetArtistProducts((ListResponse<Product> result) => { }, nullId);
 }
 public void EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     client.GetArtistProducts(this.ValidateProductListResponse, new Artist() { Id = "test" }, Category.Album);
     client.GetArtistProducts(this.ValidateProductListResponse, "test");
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieves 30 products for a selected artist from Nokia Music API.
        /// </summary>
        /// <param name="id">Id of the artist.</param>
        public void GetProductsForArtist(string id)
        {
            if (!initialized)
            {
                return;
            }

            App.ViewModel.TracksForArtist.Clear();
            App.ViewModel.AlbumsForArtist.Clear();
            App.ViewModel.SinglesForArtist.Clear();

            App.ViewModel.NoTracksVisibility  = Visibility.Visible;
            App.ViewModel.NoAlbumsVisibility  = Visibility.Visible;
            App.ViewModel.NoSinglesVisibility = Visibility.Visible;

            client.GetArtistProducts((ListResponse <Product> response) =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    // Use results
                    if (response != null && response.Result != null && response.Result.Count > 0)
                    {
                        foreach (Product p in response.Result)
                        {
                            string priceString = "";

                            if (p.Price != null)
                            {
                                priceString = p.Price.Value + p.Price.Currency;
                            }

                            string takenFromString = "";

                            if (p.TakenFrom != null)
                            {
                                takenFromString = p.TakenFrom.Name;
                            }

                            string performersString = "";

                            if (p.Performers != null && p.Performers.Length > 0)
                            {
                                performersString = p.Performers[0].Name;
                            }

                            string genresString = "";

                            if (p.Genres != null && p.Genres.Length > 0)
                            {
                                genresString = p.Genres[0].Name;
                            }

                            string categoryString = "Album";

                            string trackCountString = null;
                            if (p.TrackCount > 0)
                            {
                                trackCountString = p.TrackCount + " track";
                            }
                            if (p.TrackCount > 1)
                            {
                                trackCountString += "s";
                            }

                            if (p.Category == Category.Track)
                            {
                                categoryString = "Track";
                                App.ViewModel.TracksForArtist.Add(new ProductModel()
                                {
                                    Performers  = performersString,
                                    Name        = p.Name,
                                    TakenFrom   = takenFromString,
                                    Category    = categoryString,
                                    Thumb100Uri = p.Thumb100Uri,
                                    Thumb200Uri = p.Thumb200Uri,
                                    Thumb320Uri = p.Thumb320Uri,
                                    Id          = p.Id
                                });
                            }
                            else if (p.Category == Category.Single)
                            {
                                categoryString = "Single";
                                App.ViewModel.SinglesForArtist.Add(new ProductModel()
                                {
                                    Performers  = performersString,
                                    Name        = p.Name,
                                    TrackCount  = trackCountString,
                                    Category    = categoryString,
                                    Thumb100Uri = p.Thumb100Uri,
                                    Thumb200Uri = p.Thumb200Uri,
                                    Thumb320Uri = p.Thumb320Uri,
                                    Id          = p.Id
                                });
                            }
                            else
                            {
                                App.ViewModel.AlbumsForArtist.Add(new ProductModel()
                                {
                                    Performers  = performersString,
                                    Name        = p.Name,
                                    TrackCount  = trackCountString,
                                    Category    = categoryString,
                                    Thumb100Uri = p.Thumb100Uri,
                                    Thumb200Uri = p.Thumb200Uri,
                                    Thumb320Uri = p.Thumb320Uri,
                                    Id          = p.Id
                                });
                            }
                        }

                        if (App.ViewModel.TracksForArtist.Count > 0)
                        {
                            App.ViewModel.NoTracksVisibility = Visibility.Collapsed;
                        }

                        if (App.ViewModel.AlbumsForArtist.Count > 0)
                        {
                            App.ViewModel.NoAlbumsVisibility = Visibility.Collapsed;
                        }

                        if (App.ViewModel.SinglesForArtist.Count > 0)
                        {
                            App.ViewModel.NoSinglesVisibility = Visibility.Collapsed;
                        }
                    }

                    if (response != null && response.Error != null)
                    {
                        ShowNokiaMusicApiError();
                    }
                    HideProgressIndicator("GetProductsForArtist()");
                });
            }, id, null, 0, 30);
            ShowProgressIndicator("GetProductsForArtist()");
        }