public void EnsureGetNewReleasesReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new FailedMockApiRequestHandler());
     client.GetNewReleases(
         (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");
         },
         Category.Album);
 }
 public void EnsureGetNewReleasesReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetNewReleases(
         (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.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");
         },
         Category.Album);
 }
        public void EnsureGetNewReleasesReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
            client.GetNewReleases(
                (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.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 (Product productItem in result.Result)
                    {
                        Assert.IsFalse(string.IsNullOrEmpty(productItem.Id), "Expected Id to be populated");
                        Assert.IsFalse(string.IsNullOrEmpty(productItem.Name), "Expected Name to be populated");
                        Assert.AreNotEqual(Category.Unknown, productItem.Category, "Expected Category to be set");
                    }
                },
                Category.Album);
        }
 public void EnsureGetNewReleasesThrowsExceptionForNullCallback()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetNewReleases(null, Category.Album);
 }
 public void EnsureGetNewReleasesThrowsExceptionForUnsupportedCategory()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler());
     client.GetNewReleases((ListResponse<Product> result) => { }, Category.Unknown);
 }
 public void EnsureGetNewReleasesThrowsExceptionForNullCallback()
 {
     IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
     client.GetNewReleases(null, Category.Album);
 }
 public void EnsureGetNewReleasesReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
     client.GetNewReleases(this.ValidateNewReleasesResponse, Category.Album);
 }
Esempio n. 8
0
        /// <summary>
        /// Retrieves new releases (10 latest albums) from Nokia Music API.
        /// </summary>
        public void GetNewReleases()
        {
            if (!initialized)
            {
                return;
            }

            client.GetNewReleases((ListResponse <Product> response) =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    // Use results
                    if (response != null && response.Result != null && response.Result.Count > 0)
                    {
                        App.ViewModel.NewReleases.Clear();

                        // Insert a place holder for title text
                        App.ViewModel.NewReleases.Add(new ProductModel()
                        {
                            Performers = "TitlePlaceholderwhat's new",
                            ItemHeight = "110",
                            ItemWidth  = "450"
                        });

                        foreach (Product p in response.Result)
                        {
                            string categoryString = "Album";

                            if (p.Category == Category.Single)
                            {
                                categoryString = "Single";
                            }
                            else if (p.Category == Category.Track)
                            {
                                categoryString = "Track";
                            }

                            string performersString = "";

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

                            App.ViewModel.NewReleases.Add(new ProductModel()
                            {
                                Performers  = performersString,
                                Name        = p.Name,
                                Category    = categoryString,
                                Thumb100Uri = p.Thumb100Uri,
                                Thumb200Uri = p.Thumb200Uri,
                                Thumb320Uri = p.Thumb320Uri,
                                Id          = p.Id,
                                ItemWidth   = "205",
                                ItemHeight  = "205"
                            });
                        }
                    }

                    if (response != null && response.Error != null)
                    {
                        ShowNokiaMusicApiError();
                    }
                    HideProgressIndicator("GetNewReleases()");
                });
            }, Category.Album);
            ShowProgressIndicator("GetNewReleases()");
        }