Exemplo n.º 1
0
        public void EnsureGetSimilarArtistsAsyncThrowsExceptionForNullArtist()
        {
            Artist       nullArtist = null;
            IMusicClient client     = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));

            client.GetSimilarArtistsAsync(nullArtist).Wait();
        }
Exemplo n.º 2
0
 public async Task EnsureGetSimilarArtistsReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
     ListResponse<Artist> result = await client.GetSimilarArtistsAsync("test");
     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.º 3
0
        public async Task EnsureGetSimilarArtistsReturnsErrorForFailedCall()
        {
            IMusicClient          client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            ListResponse <Artist> result = await client.GetSimilarArtistsAsync("test");

            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.º 4
0
        public async Task EnsureGetSimilarArtistsReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
            ListResponse<Artist> result = await client.GetSimilarArtistsAsync("test");
            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");

            foreach (Artist artist in result.Result)
            {
                Assert.IsFalse(string.IsNullOrEmpty(artist.Id), "Expected Id to be populated");
                Assert.IsFalse(string.IsNullOrEmpty(artist.Name), "Expected Name to be populated");
                Assert.IsNotNull(artist.Genres, "Expected a genre list");
                Assert.Greater(artist.Genres.Length, 0, "Expected more than 0 genres");
            }
        }
Exemplo n.º 5
0
        public async Task EnsureGetSimilarArtistsReturnsItems()
        {
            IMusicClient          client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
            ListResponse <Artist> result = await client.GetSimilarArtistsAsync("test");

            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");

            foreach (Artist artist in result.Result)
            {
                Assert.IsFalse(string.IsNullOrEmpty(artist.Id), "Expected Id to be populated");
                Assert.IsFalse(string.IsNullOrEmpty(artist.Name), "Expected Name to be populated");
                Assert.IsNotNull(artist.Genres, "Expected a genre list");
                Assert.Greater(artist.Genres.Length, 0, "Expected more than 0 genres");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Builds the recommended artists lists.
        /// This method initiates a chain of requests, which requests similar
        /// artists information for each of the local artists one after another.
        /// </summary>
        private async Task FetchRecommendations()
        {
            if (!initialized || localArtists.Count <= recommendResponses)
            {
                if (initialized && App.ViewModel.Recommendations.Count <= 0)
                {
                    App.ViewModel.NoRecommendedVisibility = Visibility.Visible;
                }
                else
                {
                    App.ViewModel.NoRecommendedVisibility = Visibility.Collapsed;
                }

                // limit the number of recommended artists to 10
                if (localArtists.Count == recommendResponses)
                {
                    int i = App.ViewModel.Recommendations.Count - 1;
                    while (i > 20)
                    {
                        App.ViewModel.Recommendations.RemoveAt(i);
                        i--;
                    }
                }

                return;
            }

            ShowProgressIndicator("FetchRecommendations()");
            ListResponse <Artist> response = await client.GetSimilarArtistsAsync(localArtists[recommendResponses].Id);

            if (response != null && response.Result != null && response.Result.Count > 0)
            {
                foreach (Artist a in response.Result)
                {
                    bool handled = false;

                    // Don't recommend artists already stored in device.
                    if (App.ViewModel.IsLocalArtist(a.Name))
                    {
                        handled = true;
                    }

                    // Check if the artist has already been recommended -> add some weight
                    // to recommendation.
                    if (!handled)
                    {
                        for (int i = 0; i < App.ViewModel.Recommendations.Count; i++)
                        {
                            if (App.ViewModel.Recommendations[i].Name == a.Name)
                            {
                                handled = true;
                                App.ViewModel.Recommendations[i].SimilarArtistCount++;

                                // position according to weight
                                if (i > 1)
                                {
                                    int j = 1;

                                    for (j = i - 1; j > 1; j--)
                                    {
                                        if (App.ViewModel.Recommendations[j].SimilarArtistCount >=
                                            App.ViewModel.Recommendations[i].SimilarArtistCount)
                                        {
                                            j++; // This item (j) has been ranked higher or equal - correct index is one more
                                            break;
                                        }
                                    }

                                    if (i > j)
                                    {
                                        ArtistModel artist = App.ViewModel.Recommendations[i];
                                        App.ViewModel.Recommendations.RemoveAt(i);
                                        App.ViewModel.Recommendations.Insert(j, artist);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // If the artist is not present in the device and has not yet been
                    // recommended, do it now.
                    if (!handled)
                    {
                        App.ViewModel.Recommendations.Add(new ArtistModel()
                        {
                            Name               = a.Name,
                            Country            = CountryCodes.CountryNameFromTwoLetter(a.Country),
                            Genres             = a.Genres == null ? null : a.Genres[0].Name,
                            Thumb100Uri        = a.Thumb100Uri,
                            Thumb200Uri        = a.Thumb200Uri,
                            Thumb320Uri        = a.Thumb320Uri,
                            Id                 = a.Id,
                            SimilarArtistCount = 1,
                            ItemWidth          = "205",
                            ItemHeight         = "205"
                        });
                    }
                }
            }

            if (response != null && response.Error != null)
            {
                ShowMixRadioApiError();
            }
            HideProgressIndicator("FetchRecommendations()");

            recommendResponses++;
            await FetchRecommendations();
        }
Exemplo n.º 7
0
 public async Task EnsureGetSimilarArtistsThrowsExceptionForNullArtistId()
 {
     string nullId = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
     await client.GetSimilarArtistsAsync(nullId);
 }
 public void EnsureGetSimilarArtistsAsyncThrowsExceptionForNullArtist()
 {
     Artist nullArtist = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
     client.GetSimilarArtistsAsync(nullArtist);
 }
        public async void EnsureAsyncGetSimilarArtistsReturnsItems()
        {
            // Only test happy path, as the MusicClient tests cover the unhappy path
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
            ListResponse<Artist> result = await client.GetSimilarArtistsAsync("test");
            Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");

            result = await client.GetSimilarArtistsAsync(new Artist() { Id = "test" });
            Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
        }
Exemplo n.º 10
0
 public async Task EnsureGetSimilarArtistsThrowsExceptionForNullArtistId()
 {
     string       nullId = null;
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));
     await client.GetSimilarArtistsAsync(nullId);
 }