Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void GetWeatherDataIdNullTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(0000000);

            Assert.IsNull(target);
        }
        public void openWeatherMapTest()
        {
            IWeatherDataService ServiceTest1 = WeatherDataServiceFactory.openWeatherMap();
            IWeatherDataService ServiceTest2 = WeatherDataServiceFactory.openWeatherMap();

            Assert.AreEqual(ServiceTest1.GetHashCode(), ServiceTest2.GetHashCode());
        }
Exemplo n.º 4
0
        public void GetWeatherDataGeoNullTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new GeoCoordinations(10000000, 10000000));

            Assert.IsNull(target);
        }
        public void GetWeatherDataServiceTest()
        {
            IWeatherDataService ServiceTest1 = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
            IWeatherDataService ServiceTest2 = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);

            Assert.AreEqual(ServiceTest1.GetHashCode(), ServiceTest2.GetHashCode());
        }
Exemplo n.º 6
0
        public void GetWeatherDataLocNullTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new Location("0000000", ""));

            Assert.IsNull(target);
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            var location = new Location(textBox1.Text);

            OpenWeatherMapService.SetKey("7a27417787c2bea7d429df742eaf139d");
            var service =
                WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
            var history  = textBox1.Text;
            var data     = service.GetWeatherData(location);
            var dataText = data;

            //Convert.ToString(dataText);
            richTextBox1.AppendText(Convert.ToString(dataText));
            richTextBox2.AppendText("\n" + history);
            //richTextBox1.AppendText = data.ToString();
            Console.Write(data.ToString());

            /*
             * var c = Console.ReadKey();
             * Console.Clear();
             * if (c.KeyChar == 'n')
             * {
             *   Console.WriteLine("Bye Bye!");
             *   break;
             * }*/
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 9
0
    static void Main(string[] args)
    {
        WeatherDataServiceFactory factory = new WeatherDataServiceFactory();
        WeatherData wd = (WeatherData)factory.GetWeatherDataService(factory.OPEN_WEATHER_MAP);

        wd = wd.GetWeatherData(new Location("london"));
        wd.ShowMappedWeatherData();
    }
Exemplo n.º 10
0
        public void getWeatherDataTest()
        {
            Location            location    = new Location("London");
            IWeatherDataService service     = WeatherDataServiceFactory.getWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
            WeatherData         weatherData = service.getWeatherData(new Location("London"));

            Assert.AreEqual(weatherData.Location.City, location.City);
        }
Exemplo n.º 11
0
        public void FirstCharToUpperTest()
        {
            WeatherDataServiceFactory wdf  = new WeatherDataServiceFactory();
            IWeatherDataService       iwds = wdf.GetWeatherDataService(10);
            string test = iwds.FirstCharToUpper("united states");

            Assert.Equals(test, "United States");
        }
Exemplo n.º 12
0
        public void GetWeatherDataIdTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(524901);
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?id=524901&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Exemplo n.º 13
0
        public void GetWeatherDataGeoTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new GeoCoordinations(35, 139));
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Exemplo n.º 14
0
        public void GetWeatherDataLocTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new Location("Haifa", "il"));
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?q=haifa,il&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Exemplo n.º 15
0
        public void GetWeatherDataTest()
        {
            var location = new Location("Tel aviv");

            OpenWeatherMapService.SetKey("7ee2765dd79071b177532e10e1118cff");
            var service = WeatherDataServiceFactory.GetWeatherDataService(ServiceName.OpenWeatherMap);
            var data    = service.GetWeatherData(location);

            Assert.IsNotNull(data);
        }
        static void Main(string[] args)
        {
            Location            newlocation      = new Location("Israel");
            IWeatherDataService open_map_weather = WeatherDataServiceFactory.getWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);

            WeatherData opachki = open_map_weather.getWeatherData(newlocation);

            opachki.printAllCached();
            Console.WriteLine(" Max temp " + opachki.max_temperatur + " Min temp " + opachki.min_temperatur + " temp " + opachki.value_temperatur);
        }
        public void GetWeatherDataTest_ExceptionThrownOnWrongWeatherDataType_Negative()
        {
            const string WRONG_DATA_TYPE = "WrongWeatherType";

            Location location = new Location(2172797);

            WeatherDataServiceFactory factory = new WeatherDataServiceFactory();

            IWeatherDataService service
                = factory.getWeatherDataService(WRONG_DATA_TYPE);
        }
        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);
        }
Exemplo n.º 19
0
        public void Test2GetWeatherData()
        {
            WeatherDataServiceFactory obj = WeatherDataServiceFactory.Instance;

            Location location = new Location();

            location.city = "Barcelona";

            CityWeather tmp = obj.GetWeatherDataService(location);                  //check if get worked

            Assert.IsNotNull(tmp);
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            string CodeName;
            IWeatherDataService service;

            //we used try and catch to demonstrate if the method
            //GetWeatherDataService (in WeatherDataServiceFactory) had been called with valid number
            //the number should choose the method of the service
            // in our case there is only one service OpenWeahterMap
            try
            {
                //calling the method with invalid number
                //for catching this error
                service = WeatherDataServiceFactory.GetWeatherDataService(3);
            }
            catch (WeatherDataServiceException ex)
            {
                Console.WriteLine(ex + "\nusing OPEN_WEATHER_MAP service for program continue to work");
                //next line is equal to:
                //service = OpenWeatherMap.Instance
                service = WeatherDataServiceFactory.GetWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
            }
            while (true)
            {
                Console.WriteLine("Please enter the city or Exit to exit...");
                CodeName = Console.ReadLine();
                if (CodeName.Equals("Exit") || CodeName.Equals("exit") || CodeName.Equals("EXIST"))
                {
                    break;
                }
                service.GetWeatherData(new Location(CodeName));
                if (service.GetWD() == null)
                {
                    continue;
                }
                Console.Clear();
                Console.WriteLine("Hey Sir, You requested to see the weather in {0} in country {1}", service.GetWD().cityName, service.GetWD().country);
                Console.WriteLine("Or to be more specific it's in coord {0} , {1} ", service.GetWD().coordLat, service.GetWD().coordLon);
                Console.WriteLine("The last update I have is from {0}", service.GetWD().lastupdate);
                Console.WriteLine("It seems to be {0} today ", service.GetWD().weather);
                Console.WriteLine("The sun will rise at {0} and set at {1}", service.GetWD().sunRise, service.GetWD().sunSet);
                Console.WriteLine("the tempature now is {0} and it should be between {1} - {2}", service.GetWD().tempature, service.GetWD().tempatureMin, service.GetWD().tempatureMax);
                Console.WriteLine("the wind speed is {0} MPH", service.GetWD().windSpeed);
                Console.WriteLine("the pressure is {0} hPa", service.GetWD().pressure);
                Console.WriteLine("cloud status is {0} and that's great", service.GetWD().clouds);
                Console.WriteLine("the humidity is {0}% \n\n", service.GetWD().humidity);
                service.ClearWeatherData();
            }

            Console.WriteLine("Copyrights Shenkar - Software Engineering");
            Console.WriteLine("Course Programming Languages Oct 2016 - By Mr. Life Michael ");
            Console.WriteLine("Written by Yogev Heskia and Nir Mekin ");
        }
        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);
        }
Exemplo n.º 22
0
        public void checkCityAndCountryTest()
        {
            Location loc = new Location();

            loc.Country     = "Israel";
            loc.CountryCode = "il";
            loc.City        = "holon";
            WeatherDataServiceFactory wdf  = new WeatherDataServiceFactory();
            IWeatherDataService       iwds = wdf.GetWeatherDataService(10);
            bool test = iwds.checkCityAndCountry(loc);

            Assert.Equals(test, true);
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            WeatherDataServiceFactory obj = WeatherDataServiceFactory.Instance;                     //get instance of weather data service factory

            Location location = new Location();                                                     //create location object

            location.city = "London";

            var tmp = obj.GetWeatherDataService(location);

            System.Console.WriteLine("Country: " + tmp.Sys.Country.ToString() + "\nCity: " + tmp.Name.ToString() + "\nTempreture: " + tmp.Main.Temp.ToString() + " (Kelvin)" + "\nWind Speed: " + tmp.Wind.Speed.ToString() + "\nPressure: " + tmp.Main.Pressure.ToString() + " (Kelvin)" + "\nHumidity: " + tmp.Main.Humidity.ToString());
            System.Console.Read();
        }
        public void TestMethod1()
        {
            Location newlocation = new Location("Haim Michael !");

            try
            {
                IWeatherDataService open_map_weather = WeatherDataServiceFactory.getWeatherDataService(WeatherDataServiceFactory.OPEN_WEATHER_MAP);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.Message, "No data was fetch by ProcessResponse function using city ID");
            }
        }
Exemplo n.º 25
0
        private void btnWeather_Click(object sender, EventArgs e)
        {
            WeatherDataServiceFactory obj = WeatherDataServiceFactory.Instance;                     //get instance of weather data service factory

            Location location = new Location();                                                     //create location object

            location.city = "Boston";

            var tmp = obj.GetWeatherDataService(location);

            System.Console.WriteLine("Country: " + tmp.Sys.Country.ToString() + "\nCity: " + tmp.Name.ToString() + "\nTempreture: " + tmp.Main.Temp.ToString() + " (Kelvin)" + "\nWind Speed: " + tmp.Wind.Speed.ToString() + "\nPressure: " + tmp.Main.Pressure.ToString() + " (Kelvin)" + "\nHumidity: " + tmp.Main.Humidity.ToString());
            synthesizer.Speak("The temperature in " + location.city + " is " + KelvinToCelsius((int)tmp.Main.Temp).ToString() + " degrees Celsius");
        }
        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));
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        public void getWeatherDataServiceTest()
        {
            String BadValue = "OPEN_WEATHER_MAP_False", GoodValue = "OPEN_WEATHER_MAP", TestingValue;

            try
            {
                WeatherDataServiceFactory service = WeatherDataServiceFactory.getWeatherDataService(BadValue);
                TestingValue = GoodValue;
            }
            catch (WeatherDataException e)
            {
                TestingValue = BadValue;
            }
            Assert.AreEqual(BadValue, TestingValue);
        }
        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);
            }
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            /*loc will hold the location we want to check the tempature*/
            Location loc = new Location();

            WeatherData wd = new WeatherData();

            /*Factory to generate objects from different REStful Web Services*/
            WeatherDataServiceFactory wdf = new WeatherDataServiceFactory();

            /*iwds will hold an object that represent the chosen REStful web service*/
            IWeatherDataService iwds;

            /*option will hold the option the user chose from the menu*/
            int option;

            while (true)
            {
                Console.WriteLine("Please choose the desired action:\n1. Check tempature\n2. Exit program\n");
                option = Int32.Parse(Console.ReadLine());
                if (option == 2)
                {
                    System.Environment.Exit(1);
                }
                if (option != 1)
                {
                    continue;
                }
                /*Getting location data from user*/
                Console.WriteLine("Please enter the country full name: ");
                loc.Country = Console.ReadLine();
                Console.WriteLine("Please enter the country code: ");
                loc.CountryCode = Console.ReadLine();
                Console.WriteLine("Please enter the city name: ");
                loc.City = Console.ReadLine();

                /*Getting the right REStful Web Service and checking the tempature and humidity*/
                iwds = wdf.GetWeatherDataService(10);
                wd   = iwds.GetWeatherData(loc);
                Console.WriteLine("The tempature in " + loc.Country + " - " + loc.City + " is :  " + wd.Temapture + "C |" + " Humidity is: " + wd.Humidity + "%\n");
            }
        }