Exemplo n.º 1
0
        public async Task Test_WebCamsTravelService_GetBestWebCam_Return_Null_When_Country_Does_Not_Exist()
        {
            WebCamsTravelService    service = new WebCamsTravelService(new HRGeonameRestClient_FRA_Paris_Only_Stub(), new HRWebCamsTravelRestClientStub());
            WebCamsTravelRootObject retour  = await service.GetBestWebCam("ZZZZZZZZ", "Paris");

            Assert.IsNull(retour);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public WebCamsTravelRootObject GetBestWebCam(string country, string capital)
        {
            WebCamsTravelRootObject retour = new WebCamsTravelRootObject();
            var geonameClient = new RestClient(_connectGeoNamesURL);
            //geonameClient.Authenticator = new HttpBasicAuthenticator(_webcamsTravelLogin, _webcamsTravelPwd);
            GeonameRestRequestGenerator geonameGenerator = new GeonameRestRequestGenerator();

            IRestResponse <HRGeoNameRootObject> geonameResponse = geonameClient.Execute <HRGeoNameRootObject>(geonameGenerator.Generate(capital, country, "jean.ecard"));
            GeonameRestResponseAnalyser         analyser        = new GeonameRestResponseAnalyser();//!Structure Map
            //!Tester null
            Geoname pCode    = analyser.GetBestFittingPlaceName(capital, geonameResponse.Data.geonames);
            double  parisLat = 0;
            double  parisLon = 0;

            if (pCode != null)
            {
                Double.TryParse(pCode.lat.Replace('.', ','), out parisLat);
                Double.TryParse(pCode.lng.Replace('.', ','), out parisLon);
            }

            //WEBCAMSTRAVEL
            var webCamClient = new RestClient(_connectWebcamsTravelsURL);

            webCamClient.Authenticator = new HttpBasicAuthenticator(_webcamsTravelLogin, _webcamsTravelPwd);

            WebCamsTravelRestRequestGenerator webcamGenerator = new WebCamsTravelRestRequestGenerator();

            var webCamRequest = webcamGenerator.Generate(parisLat, parisLon, country);
            // execute the request
            IRestResponse <WebCamsTravelRootObject> webcamsTravelResponse = webCamClient.Execute <WebCamsTravelRootObject>(webCamRequest);

            if (webcamsTravelResponse != null && webcamsTravelResponse.Data != null && webcamsTravelResponse.Data.result != null)
            {
                WebCamsTravelRestResponseAnalyser webcamsTravelAnalyser = new WebCamsTravelRestResponseAnalyser();
                Webcam bestWebCam = webcamsTravelAnalyser.GetBestFittingWebCam(webcamsTravelResponse.Data.result.webcams);
                if (bestWebCam != null && bestWebCam.player != null)
                {
                    retour.status         = "OK";
                    retour.result         = new Result();
                    retour.result.limit   = 0;
                    retour.result.offset  = 0;
                    retour.result.total   = 1;
                    retour.result.webcams = new List <Webcam>();
                    retour.result.webcams.Add(bestWebCam);
                }
                else
                {
                    retour.status        = "OK";
                    retour.result        = new Result();
                    retour.result.limit  = 0;
                    retour.result.offset = 0;
                    retour.result.total  = 0;
                }
            }
            return(retour);
        }
Exemplo n.º 3
0
        public async Task Test_WebCamsTravelService_GetBestWebCam_Return_ParisWebCam_When_Paris_France_Queried()
        {
            WebCamsTravelService    service = new WebCamsTravelService(new HRGeonameRestClient_FRA_Paris_Only_Stub(), new HRWebCamsTravelRestClientStub());
            WebCamsTravelRootObject retour  = await service.GetBestWebCam("FRA", "Paris");

            Assert.IsNotNull(retour);
            Assert.IsNotNull(retour.result);
            Assert.IsNotNull(retour.result.webcams);
            Assert.IsNotNull(retour.result.webcams[0]);
            Assert.IsNotNull(retour.result.webcams[0].player);
            Assert.IsNotNull(retour.result.webcams[0].player.lifetime);
            Assert.AreEqual("Embeded", retour.result.webcams[0].player.lifetime.embed);
            Assert.AreEqual(true, retour.result.webcams[0].player.lifetime.available);
        }
        /// <summary>
        /// Get the nearest bests webcams at given lat lon.
        /// Return null if data can not be found.
        /// </summary>
        /// <returns></returns>
        public async Task <WebCamsTravelRootObject> ExecuteBestWebCam()
        {
            WebCamsTravelRootObject retour = null;

            _clientProvider.ConnectionURL = _connectWebcamsTravelsURL;
            _clientProvider.Login         = _webcamsTravelLogin;
            _clientProvider.Password      = _webcamsTravelPwd;
            var webCamClient = _clientProvider.CreateRestClient();

            var webCamRequest = _restRequestGenerator.Generate(Lat, Lon);
            // execute the request
            IRestResponse <WebCamsTravelRootObject> webcamsTravelResponse = await webCamClient.ExecuteGetTaskAsync <WebCamsTravelRootObject>(webCamRequest);

            if (webcamsTravelResponse != null && webcamsTravelResponse.Data != null && webcamsTravelResponse.Data.result != null)
            {
                List <Webcam> bestWebCams = _restResponseAnalyser.GetBestFittingWebCam(webcamsTravelResponse.Data.result.webcams);
                if (bestWebCams != null)
                {
                    retour                = new WebCamsTravelRootObject();
                    retour.status         = "OK";
                    retour.result         = new Result();
                    retour.result.limit   = 0;
                    retour.result.offset  = 0;
                    retour.result.total   = 0;
                    retour.result.webcams = new List <Webcam>();
                    foreach (Webcam iterator in bestWebCams)
                    {
                        if (iterator.player != null)
                        {
                            retour.result.webcams.Add(iterator);
                            retour.result.limit++;
                            retour.result.total++;
                        }
                    }
                    return(retour);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        public async Task <WebCamsTravelRootObject> ExecuteBestWebCam()
        {
            //Fake await.
            await Task.Delay(10);

            WebCamsTravelRootObject retour = null;

            if (_lat == 10.0 && _lon == 10.0)
            {
                retour                = new WebCamsTravelRootObject();
                retour.status         = "OK";
                retour.result         = new Result();
                retour.result.webcams = new List <Webcam>();
                Webcam webCam = new Webcam();
                webCam.player                    = new Player();
                webCam.player.lifetime           = new Lifetime();
                webCam.player.lifetime.available = true;
                webCam.player.lifetime.embed     = "Embeded";
                retour.result.webcams.Add(webCam);
            }
            return(retour);
        }