/// <summary> /// Retrieves available mix groups from Nokia Music API. /// </summary> public void GetMixGroups() { if (!initialized) { return; } client.GetMixGroups((ListResponse <MixGroup> response) => { Deployment.Current.Dispatcher.BeginInvoke(() => { // Use results if (response != null && response.Result != null && response.Result.Count > 0) { App.ViewModel.MixGroups.Clear(); foreach (MixGroup mg in response.Result) { App.ViewModel.MixGroups.Add(new MixGroupModel() { Name = mg.Name, Id = mg.Id }); } } if (response != null && response.Error != null) { ShowNokiaMusicApiError(); } HideProgressIndicator("GetMixGroups()"); }); }); ShowProgressIndicator("GetMixGroups()"); }
public void EnsureGetMixGroupsReturnsErrorForFailedCall() { IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(FakeResponse.NotFound())); client.GetMixGroups( (ListResponse<MixGroup> 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"); }); }
public void EnsureGetMixGroupsReturnsItems() { IMusicClient client = new MusicClient("test", "test", "gb", new SuccessfulMockApiRequestHandler()); client.GetMixGroups( (ListResponse<MixGroup> 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"); }); }
public void EnsureGetMixGroupsReturnsItems() { IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(Resources.mixgroups)); client.GetMixGroups( (ListResponse<MixGroup> 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 (MixGroup mixGroup in result.Result) { Assert.IsFalse(string.IsNullOrEmpty(mixGroup.Id), "Expected Id to be populated"); Assert.IsFalse(string.IsNullOrEmpty(mixGroup.Name), "Expected Name to be populated"); } }); }
public void EnsureGetMixGroupsThrowsExceptionForNullCallback() { IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(Resources.mixgroups)); client.GetMixGroups(null); }