Пример #1
0
        /// <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! Nokia Music is available in " + RegionInfo.CurrentRegion.DisplayName + "!";
                }
                else
                {
                    message     = "Sorry, Nokia Music 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;
        }
Пример #2
0
        /// <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();
        }
Пример #3
0
        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");
        }
Пример #4
0
        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");
        }
Пример #5
0
        /// <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();
        }
Пример #6
0
 /// <summary>
 /// Ctor: init controller within app environment.
 /// </summary>
 public SmartsController(CountryResolver cres, LangRepo langRepo, SqlDict dict,
                         QueryLogger qlog, IConfiguration config)
 {
     this.cres     = cres;
     this.langRepo = langRepo;
     this.dict     = dict;
     this.qlog     = qlog;
 }
Пример #7
0
        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);
        }
 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");
 }
Пример #9
0
        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");
 }
Пример #11
0
        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");
        }
Пример #12
0
 /// <summary>
 /// Ctor: inject dependencies.
 /// </summary>
 public ApiController(ILoggerFactory lf,
                      CountryResolver countryResolver, PageProvider pageProvider,
                      Sampler sampler, ResultRepo resultRepo, IConfiguration config)
 {
     logger = lf.CreateLogger(GetType().FullName);
     this.countryResolver = countryResolver;
     this.pageProvider    = pageProvider;
     this.sampler         = sampler;
     this.resultRepo      = resultRepo;
     exportSecret         = config["exportSecret"];
     exportPath           = config["exportPath"];
 }
Пример #13
0
 /// <summary>
 /// Ctor: Infuse app services.
 /// </summary>
 /// <remarks>
 /// Default null values make controller accessible to <see cref="IndexController"/>.
 /// That way, functionality is limited to serving static pages.
 /// </remarks>
 public DynpageController(PageProvider pageProvider, IConfiguration config, ILoggerFactory loggerFactory,
                          Auth auth, SqlDict dict, CountryResolver cres, QueryLogger qlog, Sphinx sphinx, LangRepo langRepo)
 {
     this.cres         = cres;
     this.pageProvider = pageProvider;
     this.dict         = dict;
     this.sphinx       = sphinx;
     this.qlog         = qlog;
     this.config       = config;
     this.logger       = loggerFactory.CreateLogger("DynpageController");
     this.auth         = auth;
     this.langRepo     = langRepo;
 }
Пример #14
0
 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");
 }
Пример #15
0
 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");
 }
Пример #16
0
 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");
 }
Пример #17
0
        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");
        }
Пример #18
0
        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");
        }
Пример #19
0
        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 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);
 }
 public async Task EnsureCheckAvailabilityReturnsErrorForFailedCall()
 {
     CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.GatewayTimeout()));
     bool result = await client.CheckAvailabilityAsync("gb");
 }
Пример #22
0
 public async Task EnsureCheckAvailabilityIsTreatedAsErrorForNetworkFailure()
 {
     CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound()));
     bool            result = await client.CheckAvailabilityAsync("xx");
 }
Пример #23
0
        /// <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.AppId);
            Response<bool> response = await resolver.CheckAvailabilityAsync(countryCode);

            if (response.Result)
            {
                await MessageBox.Show("Hooray! Nokia Music is available in " + RegionInfo.CurrentRegion.DisplayName + "!");
            }
            else
            {
                if (response.Error != null)
                {
                    await MessageBox.Show(response.Error.Message);
                }
                else
                {
                    await MessageBox.Show("Sorry, Nokia Music is not available in your region - you won't be able to use the API features.");
                }

                countryCode = null;
            }

            this.EnableCountrySpecificApiButtons(countryCode);
            App.SaveCountryCode(countryCode);
            this.ValidateDeviceCountryButton.IsEnabled = true;
        }
 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");
 }
Пример #25
0
 public async Task EnsureCheckAvailabilityThrowsExceptionForNullCountryCode()
 {
     ICountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country));
     await client.CheckAvailabilityAsync(null);
 }
Пример #26
0
        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);
        }
Пример #27
0
        public void EnsureCheckAvailabilityThrowsExceptionForNullCallback()
        {
            ICountryResolver client = new CountryResolver("test", new MockApiRequestHandler(Resources.country));

            client.CheckAvailability(null, "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", "test");
     Assert.AreEqual(client.RequestHandler.GetType(), typeof(ApiRequestHandler), "Expected the default handler");
 }
Пример #30
0
        /// <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! Nokia MixRadio is available in " + RegionInfo.CurrentRegion.DisplayName + "!";
                }
                else
                {
                    message = "Sorry, Nokia 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;
            }

            await MessageBox.Show(message);

            this.EnableCountrySpecificApiButtons(countryCode);
            App.SaveCountryCode(countryCode);
            this.ValidateDeviceCountryButton.IsEnabled = true;
        }
Пример #31
0
 /// <summary>
 /// Ctor: init controller within app environment.
 /// </summary>
 public CorpusController(Sphinx sphinx, QueryLogger qlog, CountryResolver cres)
 {
     this.sphinx = sphinx;
     this.qlog   = qlog;
     this.cres   = cres;
 }
 public async Task EnsureInvalidApiCredentialsExceptionThrownWhenServerGives403()
 {
     CountryResolver client = new CountryResolver("badkey", new MockApiRequestHandler(FakeResponse.Forbidden()));
     await client.CheckAvailabilityAsync("gb");
 }
 public async Task EnsureCheckAvailabilityIsTreatedAsErrorForNetworkFailure()
 {
     CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.NotFound()));
     bool result = await client.CheckAvailabilityAsync("xx");
 }
Пример #34
0
 public void EnsureCheckAvailabilityThrowsExceptionForNullCallback()
 {
     ICountryResolver client = new CountryResolver("test", "test", new MockApiRequestHandler(Resources.country));
     client.CheckAvailability(null, "gb");
 }
Пример #35
0
 public async Task EnsureCheckAvailabilityReturnsErrorForFailedCall()
 {
     CountryResolver client = new CountryResolver("test", new MockApiRequestHandler(FakeResponse.GatewayTimeout()));
     bool            result = await client.CheckAvailabilityAsync("gb");
 }
Пример #36
0
        public void EnsureDefaultRequestHandlerIsCreated()
        {
            CountryResolver client = new CountryResolver("test");

            Assert.AreEqual(client.RequestHandler.GetType(), typeof(ApiRequestHandler), "Expected the default handler");
        }
Пример #37
0
 public void EnsureCheckAvailabilityThrowsExceptionForNullCountryCode()
 {
     ICountryResolver client = new CountryResolver("test", "test", new SuccessfulMockApiRequestHandler());
     client.CheckAvailability(null, null);
 }
Пример #38
0
 public async Task EnsureInvalidApiCredentialsExceptionThrownWhenServerGives403()
 {
     CountryResolver client = new CountryResolver("badkey", new MockApiRequestHandler(FakeResponse.Forbidden()));
     await client.CheckAvailabilityAsync("gb");
 }
Пример #39
0
 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");
 }
 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");
 }
Пример #41
0
 public async Task EnsureCountryResolverWithInvalidContentTypeRaisesApiCallFailedException()
 {
     ICountryResolver client = new CountryResolver("test1", new MockApiRequestHandler(FakeResponse.Success(null, null)));
     bool             result = await client.CheckAvailabilityAsync("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");
        }