/// <summary> /// Checks the availability of Nokia Music in a locale. /// Initializes Nokia Music API if it is available. /// </summary> /// <param name="twoLetterCountryCode">An ISO 3166-2 country code</param> private void InitializeNokiaMusicApi(string twoLetterCountryCode) { if (resolver == null) { resolver = new CountryResolver(MusicApi.MUSIC_EXPLORER_APP_ID); } if (twoLetterCountryCode != null) { resolver.CheckAvailability((Response <bool> response) => { Deployment.Current.Dispatcher.BeginInvoke(() => { if (!response.Result) { MessageBox.Show("Sorry, Nokia Music is not available in this locale."); twoLetterCountryCode = null; } }); }, twoLetterCountryCode.ToLower()); } // If country code is null, phone region settings are used App.MusicApi.Initialize(twoLetterCountryCode); // Make initial requests to fill models App.MusicApi.GetArtistInfoForLocalAudio(); App.MusicApi.GetNewReleases(); App.MusicApi.GetTopArtists(); App.MusicApi.GetGenres(); App.MusicApi.GetMixGroups(); }
public void EnsureInvalidApiCredentialsExceptionThrownWhenServerGives403() { CountryResolver client = new CountryResolver("badkey", "test", new MockApiRequestHandler(FakeResponse.Forbidden())); client.CheckAvailability( (Response<bool> response) => { Assert.IsNotNull(response.Error, "Expected an Error"); Assert.AreEqual(typeof(InvalidApiCredentialsException), response.Error.GetType(), "Expected an InvalidApiCredentialsException"); }, "gb"); }
public void EnsureCountryResolverPassesDefaultSettings() { MockApiRequestHandler mockHandler = new MockApiRequestHandler(FakeResponse.NotFound()); ICountryResolver client = new CountryResolver("test1", mockHandler); client.CheckAvailability(result => Assert.IsNotNull(result, "Expected a result"), "xx"); Assert.AreEqual("test1", mockHandler.LastUsedSettings.AppId); Assert.AreEqual(null, mockHandler.LastUsedSettings.CountryCode); Assert.AreEqual(false, mockHandler.LastUsedSettings.CountryCodeBasedOnRegionInfo); }
public void EnsureCheckAvailabilityIsTreatedAsErrorForNetworkFailure() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound()), requestId); client.CheckAvailability( (Response<bool> result) => { Assert.IsNotNull(result.Error, "Expected an error"); }, "xx"); }
public void EnsureCheckAvailabilityIsTreatedAsErrorForNetworkFailure() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound()), requestId); client.CheckAvailability( (Response <bool> result) => { Assert.IsNotNull(result.Error, "Expected an error"); }, "xx"); }
public void EnsureCheckAvailabilityReturnsErrorForFailedCall() { ICountryResolver client = new CountryResolver("test", "test", new FailedMockApiRequestHandler()); client.CheckAvailability( (Response<bool> 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 200 response"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException"); }, "gb"); }
public void EnsureCheckAvailabilityReturnsFailsForInvalidCountry() { ICountryResolver client = new CountryResolver("test", "test", new FailedMockApiRequestHandler()); client.CheckAvailability( (Response<bool> 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.NotFound, result.StatusCode.Value, "Expected a 404 response"); Assert.IsNotNull(result.Result, "Expected a result"); Assert.IsFalse(result.Result, "Expected a false result"); Assert.IsNull(result.Error, "Expected no error"); }, "xx"); }
public void EnsureCheckAvailabilityReturnsErrorForFailedCall() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.GatewayTimeout()), requestId); client.CheckAvailability( (Response <bool> 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 200 response"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.AreEqual(requestId, result.RequestId, "Expected a matching request Id"); Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException"); }, "gb"); }
public void EnsureCheckAvailabilityReturnsFailsForInvalidCountry() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound("{}")), requestId); client.CheckAvailability( (Response <bool> 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.NotFound, result.StatusCode.Value, "Expected a 404 response"); Assert.IsNotNull(result.Result, "Expected a result"); Assert.IsFalse(result.Result, "Expected a false result"); Assert.AreEqual(requestId, result.RequestId, "Expected a matching request Id"); Assert.IsNull(result.Error, "Expected no error"); }, "xx"); }
public void EnsureCheckAvailabilityWorksForValidCountry() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country), requestId); client.CheckAvailability( (Response <bool> 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 result"); Assert.AreEqual(requestId, result.RequestId, "Expected a matching request Id"); Assert.IsTrue(result.Result, "Expected a true result"); Assert.IsNull(result.Error, "Expected no error"); }, "gb"); var task = client.CheckAvailabilityAsync("gb"); }
public void EnsureCheckAvailabilityWorksForValidCountry() { ICountryResolver client = new CountryResolver("test", "test", new SuccessfulMockApiRequestHandler()); client.CheckAvailability( (Response<bool> 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 result"); Assert.IsTrue(result.Result, "Expected a true result"); Assert.IsNull(result.Error, "Expected no error"); }, "gb"); }
public void EnsureCheckAvailabilityThrowsExceptionForNullCountryCode() { ICountryResolver client = new CountryResolver("test", "test", new SuccessfulMockApiRequestHandler()); client.CheckAvailability(null, null); }
public void EnsureCheckAvailabilityThrowsExceptionForNullCallback() { ICountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country)); client.CheckAvailability(null, "gb"); }
public void EnsureCheckAvailabilityThrowsExceptionForNullCallback() { ICountryResolver client = new CountryResolver("test", "test", new MockApiRequestHandler(Resources.country)); client.CheckAvailability(null, "gb"); }
public void EnsureCountryResolverPassesDefaultSettings() { MockApiRequestHandler mockHandler = new MockApiRequestHandler(FakeResponse.NotFound()); ICountryResolver client = new CountryResolver("test1", "test2", mockHandler); client.CheckAvailability(result => Assert.IsNotNull(result, "Expected a result"), "xx"); Assert.AreEqual("test1", mockHandler.LastUsedSettings.AppId); Assert.AreEqual("test2", mockHandler.LastUsedSettings.AppCode); Assert.AreEqual(null, mockHandler.LastUsedSettings.CountryCode); Assert.AreEqual(false, mockHandler.LastUsedSettings.CountryCodeBasedOnRegionInfo); }
public void EnsureCheckAvailabilityWorksForValidCountry() { Guid requestId = new Guid(); CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country), requestId); client.CheckAvailability( (Response<bool> 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 result"); Assert.AreEqual(requestId, result.RequestId, "Expected a matching request Id"); Assert.IsTrue(result.Result, "Expected a true result"); Assert.IsNull(result.Error, "Expected no error"); }, "gb"); var task = client.CheckAvailabilityAsync("gb"); }