/// <summary> /// Checks the availability of MixRadio in a locale. /// Initializes MixRadio API if it is available. /// </summary> /// <param name="twoLetterCountryCode">An ISO 3166-2 country code</param> private async void InitializeMixRadioApi(string twoLetterCountryCode) { if (resolver == null) { resolver = new CountryResolver(MixRadio.TestApp.ApiKeys.ClientId); } if (twoLetterCountryCode != null) { bool response = await resolver.CheckAvailabilityAsync(twoLetterCountryCode.ToLower()); if (!response) { MessageBox.Show("Sorry, MixRadio is not available in this locale."); twoLetterCountryCode = null; } } // 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 async Task EnsureCheckAvailabilityIsTreatedAsErrorForNetworkFailure() { CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound())); bool result = await client.CheckAvailabilityAsync("xx"); }
public async Task EnsureCountryResolverPassesDefaultSettings() { MockApiRequestHandler mockHandler = new MockApiRequestHandler(Resources.country); ICountryResolver client = new CountryResolver("test1", mockHandler); bool result = await client.CheckAvailabilityAsync("xx"); Assert.AreEqual("test1", mockHandler.LastUsedSettings.ClientId); Assert.AreEqual(null, mockHandler.LastUsedSettings.CountryCode); Assert.AreEqual(false, mockHandler.LastUsedSettings.CountryCodeBasedOnRegionInfo); Assert.AreEqual(MusicClientCommand.DefaultBaseApiUri, mockHandler.LastUsedSettings.ApiBaseUrl); Assert.AreEqual(MusicClientCommand.DefaultSecureBaseApiUri, mockHandler.LastUsedSettings.SecureApiBaseUrl); }
public async Task EnsureCheckAvailabilityWorksForValidCountry() { CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country)); bool result = await client.CheckAvailabilityAsync("gb"); Assert.IsTrue(result, "Expected a true result"); }
public async Task EnsureCheckAvailabilityReturnsFailsForInvalidCountry() { CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound("{}"))); bool result = await client.CheckAvailabilityAsync("xx"); Assert.IsFalse(result, "Expected a false result"); }
public async Task EnsureInvalidApiCredentialsExceptionThrownWhenServerGives403() { CountryResolver client = new CountryResolver("badkey", new MockApiRequestHandler(FakeResponse.Forbidden())); await client.CheckAvailabilityAsync("gb"); }
public async Task EnsureCheckAvailabilityThrowsExceptionForNullCountryCode() { ICountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country)); await client.CheckAvailabilityAsync(null); }
public void EnsureDefaultRequestHandlerIsCreated() { CountryResolver client = new CountryResolver("test"); Assert.AreEqual(client.RequestHandler.GetType(), typeof(ApiRequestHandler), "Expected the default handler"); }
public async Task EnsureCheckAvailabilityReturnsErrorForFailedCall() { CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.GatewayTimeout())); bool result = await client.CheckAvailabilityAsync("gb"); }
public async Task EnsureCountryResolverWithInvalidContentTypeRaisesApiCallFailedException() { ICountryResolver client = new CountryResolver("test1", new MockApiRequestHandler(FakeResponse.Success(null, null))); bool result = await client.CheckAvailabilityAsync("xx"); }
public async Task EnsureCountryWithoutItemsRaisesApiCallFailedException() { MockApiRequestHandler mockHandler = new MockApiRequestHandler(System.Text.Encoding.UTF8.GetBytes("{ \"items\": [] }")); ICountryResolver client = new CountryResolver("test1", mockHandler); bool result = await client.CheckAvailabilityAsync("xx"); }
/// <summary> /// Validates the country code got from phone region settings. /// </summary> /// <param name="sender">Validate Device Country button</param> /// <param name="e">Event arguments</param> private async void ValidateDeviceCountry(object sender, RoutedEventArgs e) { this.ValidateDeviceCountryButton.IsEnabled = false; string countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName.ToLower(); CountryResolver resolver = new CountryResolver(ApiKeys.ClientId); string message = null; try { bool available = await resolver.CheckAvailabilityAsync(countryCode); if (available) { message = "Hooray! MixRadio is available in " + RegionInfo.CurrentRegion.DisplayName + "!"; } else { message = "Sorry, MixRadio is not available in your region - you won't be able to use the API features."; countryCode = null; } } catch (Exception ex) { message = ex.Message; countryCode = null; } MessageBox.Show(message); this.EnableCountrySpecificApiButtons(countryCode); App.SaveCountryCode(countryCode); this.ValidateDeviceCountryButton.IsEnabled = true; }