コード例 #1
0
 public void GetWeatherDataTest()
 {
     try
     {
         Location location            = new Location("London");
         OpenWeatherMapDataService wd = OpenWeatherMapDataService.GetInstance();
         WeatherData actual           = wd.GetWeatherData(location);
         Assert.AreEqual("London", actual.Location.City);
     }
     catch (WeatherDataServiceException)
     {
         Assert.Fail();                  //if an exception is caught, the test is fail.
     }
 }
コード例 #2
0
        //To add more weather web services add more consts here and expand the switch case.

        /// <summary>
        /// Checks what weather REStful web service the user sent and returns the requested service.
        /// </summary>
        /// <param name="weatherDataService"></param>
        /// <returns>An object represents a weather REStful web service</returns>
        public static IWeatherDataService GetWeatherDataService(int weatherDataService)
        {
            switch (weatherDataService)
            {
            case 1:
                return(OpenWeatherMapDataService.GetInstance());

            case 2:
                return(ApixuDataService.GetInstance());

            /*
             *      case 3:
             *              return another WeatherService.GetInstance();
             */
            default:
                throw new WeatherDataServiceException("You should send one of the constants that" +
                                                      " defined in WeatherDataServiceFactory");
            }
        }