Exemplo n.º 1
0
 public async Task EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     var t = await client.GetArtistProductsAsync("test", Category.Album);
     this.ValidateProductListResponse(t);
     t = await client.GetArtistProductsAsync("test");
     this.ValidateProductListResponse(t);
 }
Exemplo n.º 2
0
        public async Task EnsureGetArtistProductsReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
            var          t      = await client.GetArtistProductsAsync("test", Category.Album);

            this.ValidateProductListResponse(t);
            t = await client.GetArtistProductsAsync("test");

            this.ValidateProductListResponse(t);
        }
 public void EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     var task = client.GetArtistProductsAsync(new Artist() { Id = "test" }, Category.Album);
     task.Wait();
     this.ValidateProductListResponse(task.Result);
     task = client.GetArtistProductsAsync("test");
     task.Wait();
     this.ValidateProductListResponse(task.Result);
 }
 public void EnsureAsyncGetArtistProductsReturnsItems()
 {
     // Only test happy path, as the MusicClient tests cover the unhappy path
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_products));
     var artistProductByIdTask = client.GetArtistProductsAsync("test");
     var artistProductByArtistTask = client.GetArtistProductsAsync(new Artist() { Id = "test" });
     artistProductByIdTask.Wait();
     artistProductByArtistTask.Wait();
     this.ValidateProductListResponse(artistProductByIdTask.Result);
     this.ValidateProductListResponse(artistProductByArtistTask.Result);
 }
Exemplo n.º 5
0
        public void EnsureGetArtistProductsReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
            var          task   = client.GetArtistProductsAsync(new Artist()
            {
                Id = "test"
            }, Category.Album);

            task.Wait();
            this.ValidateProductListResponse(task.Result);
            task = client.GetArtistProductsAsync("test");
            task.Wait();
            this.ValidateProductListResponse(task.Result);
        }
Exemplo n.º 6
0
        public void EnsureGetArtistProductsThrowsExceptionForNullArtist()
        {
            Artist       nullArtist = null;
            IMusicClient client     = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));

            client.GetArtistProductsAsync(nullArtist).Wait();
        }
 public async Task EnsureGetArtistProductsReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
     ListResponse<Product> result = await client.GetArtistProductsAsync("test", orderBy: OrderBy.Name, sortOrder: SortOrder.Ascend);
     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");
 }
Exemplo n.º 8
0
        public async Task EnsureGetArtistProductsReturnsErrorForFailedCall()
        {
            IMusicClient           client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            ListResponse <Product> result = await client.GetArtistProductsAsync("test", orderBy : OrderBy.Name, sortOrder : SortOrder.Ascend);

            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");
        }
Exemplo n.º 9
0
        public async Task<bool> GetArtwork(string searchTerm, int numberItems)
        {
            var musicClient = new MusicClient(MixRadioApiConstants.MixRadioClientId);
            var artists = await musicClient.SearchArtistsAsync(searchTerm);
            if (artists.Succeeded && artists.Count > 0)
            {
                var chosenArtist = artists.FirstOrDefault(x => x.Name.Equals(searchTerm, StringComparison.CurrentCultureIgnoreCase));
                chosenArtist = chosenArtist ?? artists[0];

                var products = await musicClient.GetArtistProductsAsync(chosenArtist.Id, MixRadio.Types.Category.Album, MixRadio.Types.OrderBy.Relevance, itemsPerPage: 50);
                if (products.Succeeded && products.Count >= numberItems)
                {
                    _artwork = products.Result.Select(x => x.Thumb320Uri).OrderBy(x => Guid.NewGuid()).Take(numberItems).ToList();
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 10
0
 public async Task EnsureGetArtistProductsThrowsExceptionForNullArtistId()
 {
     string       nullId = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     await client.GetArtistProductsAsync(nullId);
 }
 public void EnsureGetArtistProductsAsyncThrowsExceptionForNullArtist()
 {
     Artist nullArtist = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     client.GetArtistProductsAsync(nullArtist);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Retrieves 30 products for a selected artist from MixRadio API.
        /// </summary>
        /// <param name="id">Id of the artist.</param>
        public async 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;

            ShowProgressIndicator("GetProductsForArtist()");

            ListResponse <Product> response = await client.GetArtistProductsAsync(id, itemsPerPage : 30);

            // 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)
            {
                ShowMixRadioApiError();
            }
            HideProgressIndicator("GetProductsForArtist()");
        }
Exemplo n.º 13
0
 public async Task EnsureGetArtistProductsThrowsExceptionForNullArtistId()
 {
     string nullId = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     await client.GetArtistProductsAsync(nullId);
 }