예제 #1
0
        public void TestGetWeatherDataByName()
        {
            Location loc = new Location();

            loc.CityName = "Dimona";
            loc.Country  = "il";
            WeatherData weatherData = service.GetWeatherData(loc);

            Assert.That(weatherData.CityName, Is.EqualTo("Dimona"));
            Assert.That(weatherData.CityName, Is.Not.Null);
            Assert.That(weatherData.Temp, Is.GreaterThanOrEqualTo(0));
            Assert.That(weatherData.Humidity, Is.GreaterThanOrEqualTo(0));
            Assert.That(weatherData.WindSpeed, Is.GreaterThanOrEqualTo(0));
        }
예제 #2
0
        static void Main(string[] args)
        {
            // create the factory of services
            WeatherDataServiceFactory factory = new WeatherDataServiceFactory();
            // get one service from the factory by requested type
            IWeatherDataService weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OpenWeatherMap);

            Console.WriteLine("*************************************************");
            try
            {
                // create location object to get weather in
                Location location = new Location("London", "UK");
                // get the current weather
                WeatherData weatherData = weatherService.GetWeatherData(location);
                // print the weather data
                Console.WriteLine(weatherData.ToString());
            }
            catch (WeatherDataServiceException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("*************************************************");
            Console.WriteLine("\nDo you want to try get weather in your current location ?");
            Console.WriteLine("Press 'C' to continue or 'E' to exit.");
            string key = Console.ReadLine();

            while (key != null && key.Equals("c", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine("Enter your city name : ");
                string city = Console.ReadLine();
                Console.WriteLine("Enter your country name : ");
                string country = Console.ReadLine();
                Console.WriteLine("\n*************************************************\n");
                try
                {
                    WeatherData weatherData = weatherService.GetWeatherData(new Location(city, country));
                    Console.WriteLine(weatherData.ToString());
                }
                catch (WeatherDataServiceException e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.WriteLine("*************************************************\n");
                Console.WriteLine("Press 'C' to continue or 'E' to exit.");
                key = Console.ReadLine();
            }
        }
예제 #3
0
        public void GetWeatherDataTest()
        {
            Location            location = new Location("aaaaaaaaaaaaaaaaaaa");
            IWeatherDataService service  = OpenWeatherMap.Instance;

            Assert.AreNotEqual(null, service.GetWeatherData(location));
        }
예제 #4
0
        public void GetWeatherDataTest()
        {
            IWeatherDataService service = WeatherDataServiceFactory.GetWeatherDataService(
                WeatherDataServiceFactory.WeatherDataKind.OPEN_WEATHER_MAP);

            Location location = new Location("Hod Hasharon", "IL");

            WeatherData data = null;

            try
            {
                data = service.GetWeatherData(location);
            }
            catch (WeatherDataServiceException)
            {
                Assert.Fail();
            }

            Assert.IsNotNull(data);
            Assert.IsNotNull(data.Location);
            Assert.IsNotNull(data.Clouds);
            Assert.IsNotNull(data.Humidity);
            Assert.IsNotNull(data.Pressure);
            Assert.IsNotNull(data.Temperature);
            Assert.IsNotNull(data.Wind);
            Assert.IsNotNull(data.TimeSpan);
        }
        public void GetWeatherDataTest()
        {
            Location            location = new Location("Vladivostok");
            IWeatherDataService service  = OpenWeatherMap.Instance;

            Assert.IsNotNull(service.GetWeatherData(location));
        }
        private void GetData(object sender, RoutedEventArgs e)
        {
            //get data for given location
            string loc = locTxtBox.Text.ToString();

            try
            {
                if (!String.IsNullOrEmpty(loc))
                {
                    Location            location = new Location(loc);
                    IWeatherDataService service  = WeatherDataService.Instance;
                    WeatherData         data     = service.GetWeatherData(location);

                    line1Lbl.Content = String.Format("Location: {0}, {1}", data.Location.CityName, data.Location.Country);
                    line2Lbl.Content = String.Format("Last Update: {0}", data.LastUpdate.ToString());
                    line3Lbl.Content = String.Format("Temperature: {0} {1}, humidity: {2}{3}",
                                                     data.Temperature.AverageTemperature, data.Temperature.TemperatureUnit, data.HumidityValue, data.HumidityUnit);
                    line4Lbl.Content = String.Format("Pressure: {0} {1}",
                                                     data.PressureValue, data.PressureUnit);
                    line5Lbl.Content = String.Format("Wind speed {0} {1}, direction: {2}",
                                                     data.Wind.Speed, data.Wind.SpeedDescription, data.Wind.Direction);
                }
            }
            catch (WeatherDataServiceException)
            {
                MessageBoxResult result = MessageBox.Show(
                    String.Format("Provided location: \"{0}\" is invalid. Please try again!", loc),
                    "Error", MessageBoxButton.OK, MessageBoxImage.Question);
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            IWeatherDataService service = WeatherDataServiceFactory.
                                          GetWeatherDataService(WeatherDataServiceFactory.WeatherDataServiceSource.OPEN_WEATHER_MAP);

            var data = service.GetWeatherData(new Location("London", "uk"));
        }
예제 #8
0
        static void Main(string[] args)
        {
            //testing the program
            Location location;
            string   nameOfCity;

            IWeatherDataService service = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);

            for (;;)
            {
                Console.WriteLine("x.For exit.");
                Console.Write("Please enter the name of city: ");
                nameOfCity = Console.ReadLine();
                if (nameOfCity == "x")
                {
                    return;
                }

                location = new Location(nameOfCity);
                try
                {
                    WeatherData testWeather = service.GetWeatherData(location);

                    //place
                    Console.WriteLine("\nPlace: " + testWeather.City.Name
                                      + ", " + testWeather.City.Country + " ("
                                      + testWeather.City.Coord.Lon + ", " + testWeather.City.Coord.Lat + ")");

                    //temprature
                    Console.WriteLine("Temp: " + testWeather.Temprature.Value +
                                      " (min " + testWeather.Temprature.Min + ", max " + testWeather.Temprature.Max + ") " + testWeather.Temprature.Unit);

                    //huidity
                    Console.WriteLine("Humidity: " + testWeather.Humidity.Value + " " + testWeather.Humidity.Unit);

                    //pressure
                    Console.WriteLine("Pressure: " + testWeather.Pressure.Value + " " + testWeather.Pressure.Unit);

                    //wind
                    Console.WriteLine("Wind: " + testWeather.Wind.Speed.Name + " " +
                                      testWeather.Wind.Speed.Value);

                    //precipitation
                    Console.WriteLine("Precipitation: " + testWeather.PrecipitationMode);

                    //weather
                    Console.WriteLine("Weather: " + testWeather.WeatherValue);

                    //weather
                    Console.WriteLine("Last Update: " + testWeather.LastUpdateValue.ToLongTimeString());
                }
                catch (WeatherDataServiceException e)
                {
                    Console.WriteLine(e);
                }
                Console.WriteLine("\nPress any key to continue...\n");
                Console.ReadKey();
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            Console.Write("Please enter the name of city: ");
            Location            location = new Location(Console.ReadLine());
            IWeatherDataService service  = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);

            service.GetWeatherData(location);
            Console.ReadLine();
        }
        public void GetWeatherDataTest()
        {
            IWeatherDataService service = OWMWeatherDataService.Instance;

            var location = new Location("London", "uk");
            var data     = service.GetWeatherData(location);

            WeatherDataTestUtils.AssertValidWeatherData(data);
            Assert.AreEqual(data.City.Location.City, location.City);
        }
        public void GetWeatherDataServiceTest()
        {
            IWeatherDataService service = WeatherDataServiceFactory.
                                          GetWeatherDataService(WeatherDataServiceFactory.WeatherDataServiceSource.OPEN_WEATHER_MAP);

            var location = new Location("London", "uk");
            var data     = service.GetWeatherData(location);

            WeatherDataTestUtils.AssertValidWeatherData(data);
            Assert.AreEqual(data.City.Location.City, location.City);
        }
예제 #12
0
        static void Main(string[] args)
        {
            Location            location = new Location("Tel Aviv");
            IWeatherDataService service  = WeatherDataService.Instance;
            WeatherData         data     = service.GetWeatherData(location);

            Console.WriteLine(data.ToString());


            Console.ReadKey();
        }
예제 #13
0
        static void Main(string[] args)
        {
            WeatherDataServiceFactory serviceFactory = new WeatherDataServiceFactory();
            IWeatherDataService       newService     = serviceFactory.GetWeatherDataService(dataServices.OPEN_WEATHER_MAP);
            Location    location = new Location("Tel Aviv", "IL");
            WeatherData data     = newService.GetWeatherData(location);

            Console.WriteLine(data.ToString());
            Debug.WriteLine(data.ToString());

            Console.ReadLine();
        }
        public void GetWeatherDataValueTest()
        {
            // get the weather data in London using the GetWeatherData function
            WeatherDataServiceFactory factory        = new WeatherDataServiceFactory();
            IWeatherDataService       weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OpenWeatherMap);
            Location    locationTest      = new Location("London", "UK");
            WeatherData weatherDataToTest = weatherService.GetWeatherData(locationTest);
            // get the weather data in London from the website
            string      url        = "http://api.openweathermap.org/data/2.5/weather?q=" + locationTest.City + "," + locationTest.Country + "&mode=xml";
            WeatherData weatherSrc = GetWeatherByUrlForTesting(url);

            Assert.IsTrue(weatherSrc.Equals(weatherDataToTest));
        }
        public void GetWeatherDataTest_ValidDataObjectReturned_Positive()
        {
            Location location = new Location(2172797);

            WeatherDataServiceFactory factory = new WeatherDataServiceFactory();

            IWeatherDataService service
                = factory.getWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);

            WeatherData data = service.GetWeatherData(location);

            Assert.IsNotNull(data);
        }
예제 #16
0
        static void Main(string[] args)
        {
            //service
            IWeatherDataService service = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.WeatherService.OPEN_WEATHER_MAP);
            //data
            WeatherData weatherService = null;

            //location testing
            Location location;
            string   city;

            while (true)
            {
                Console.Write("Please enter the name of the city for temp info or type exit: ");
                city = Console.ReadLine();
                if (city == "exit" || city == "EXIT" || city == "Exit")
                {
                    return;
                }
                location = new Location(city);

                try
                {
                    weatherService = service.GetWeatherData(location);
                }
                catch (WeatherDataServiceException e) { Console.WriteLine(e); }

                if (weatherService != null)
                {
                    //ConsoleLog messages
                    //location
                    Console.WriteLine("\nLocation: " + weatherService.name + " (" + weatherService.coord.lon + "," + weatherService.coord.lat + ")");

                    //temp
                    Console.WriteLine("Temprature: " + weatherService.main.temp + " (min: " + weatherService.main.temp_min + ", max:" + weatherService.main.temp_max + ")");

                    //humidity and pressure
                    Console.WriteLine("Humidity: " + weatherService.main.humidity + ", Pressure: " + weatherService.main.pressure);

                    //wind and description
                    Console.WriteLine("Wind: " + weatherService.wind.speed + "\nWeather Description: " + weatherService.weather[0].description);
                }
                else
                {
                    Console.WriteLine("\nLocation not found!");
                }

                Console.WriteLine("\nPress any key to continue...\n");
                Console.ReadKey();
            }
        }
예제 #17
0
        public void GetWeatherDataTest()
        {
            Location loc = new Location();

            loc.Country     = "Israel";
            loc.CountryCode = "il";
            loc.City        = "holon";
            WeatherDataServiceFactory wdf  = new WeatherDataServiceFactory();
            IWeatherDataService       iwds = wdf.GetWeatherDataService(10);
            WeatherData wd = iwds.GetWeatherData(loc);

            Assert.AreNotEqual(wd.Temapture, -99);
            Assert.AreNotEqual(wd.Humidity, -99);
        }
예제 #18
0
        /// <summary>
        /// The main core of the application which handels all the classes
        /// and eventually print the details wich the user chosen into the screen
        /// </summary>

        static void Main(string[] args)
        {
            string site = "OPEN_WEATHER_MAP";
            // using the site value within the WeatherDataServiceFactory which implemented by the Factory Design Pattern
            IWeatherDataService iw = WeatherDataServiceFactory.GetWeatherDataService(site);

            Console.WriteLine("For weather details, please Enter the name of the required city: \n");
            string      locCity = Console.ReadLine(); // location value from the user
            Location    locMain = new Location(locCity);
            WeatherData wd      = iw.GetWeatherData(locMain);

            wd.PrintDetails();
            Console.ReadKey();
        }
예제 #19
0
        static void Main(string[] args)
        {
            // create the factory of services
            WeatherDataServiceFactory factory = new WeatherDataServiceFactory();
            // get one service from the factory by requested type
            IWeatherDataService weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OPEN_WEATHER_MAP);
            // use the weather service
            Location location = new Location("london", "UK");
            // get the current weather
            WeatherData weatherData = weatherService.GetWeatherData(location);

            // print the weather data
            Console.WriteLine(weatherData.ToString());
        }
예제 #20
0
 static void Main(string[] args)
 {
     try
     {
         IWeatherDataService service     = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
         WeatherData         weatherData = service.GetWeatherData(new Location("London"));
         weatherData.PrintData();
     }
     catch (WeatherDataServiceException e)
     {
         throw new WeatherDataServiceException(e, "XmlException");
     }
     return;
 }
        public void GetWeatherDataNotExistTest()
        {
            WeatherDataServiceFactory factory        = new WeatherDataServiceFactory();
            IWeatherDataService       weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OpenWeatherMap);

            try
            {
                WeatherData weatherDataToTest = weatherService.GetWeatherData(new Location(";", ";"));
                Assert.Fail("Expected exception");
            }
            catch (WeatherDataServiceException e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #22
0
        public static void Main()
        {
            try
            {
                IWeatherDataService service = WeatherDataServiceFactory.
                                              GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
                WeatherData weatherData = service.GetWeatherData(new Location("London"));
                Console.WriteLine(weatherData + "\n");

                IWeatherDataService service2 = WeatherDataServiceFactory.
                                               GetWeatherDataService(WeatherDataServiceFactory.APIXU);
                WeatherData weatherData2 = service2.GetWeatherData(new Location(51.52, -0.11));
                Console.WriteLine(weatherData2);
            }
            catch (WeatherDataServiceException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.Read();                 //Remove it if you are using Window Application output type.
        }
        static void Main(string[] args)
        {
            IWeatherDataService service = WeatherDataServiceFactory.GetWeatherDataService(
                WeatherDataServiceFactory.WeatherDataKind.OPEN_WEATHER_MAP);

            try
            {
                WeatherData weatherData = service.GetWeatherData(new Location("Hod Hasharon", "IL"));

                Console.WriteLine(weatherData);

                List <WeatherData> forecast = service.GetForecast(new Location("Hod Hasharon", "IL"));

                foreach (var t in forecast)
                {
                    Console.WriteLine(t);
                }
            }
            catch (WeatherDataServiceException e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
            }
        }