Пример #1
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());
 }
 public void GetWeatherDataNullValueTest()
 {
     WeatherDataServiceFactory factory = new WeatherDataServiceFactory();
     IWeatherDataService weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OpenWeatherMap);
     try
     {
         WeatherData weatherDataToTest = weatherService.GetWeatherData(new Location(null, null));
         Assert.Fail("Expected exception");
     }
     catch (WeatherDataServiceException e)
     {
         Console.WriteLine(e.Message);
     }
 }
Пример #3
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());
        }
Пример #4
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();
            }
        }
Пример #5
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();
            }
        }
 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));
 }