/// <summary>
        /// args[0] represent OpenWeatherMapApiClientUri. Ex: https://api.openweathermap.org/data/2.5/
        /// args[1] represent OpenWeatherMapApiClientAppId Ex: 63d35ff6068c3103ccd1227526935675
        /// args[2] represent OpenWeatherDataPersistenceClientFilePath Ex: C://Users/Agallardol/Documents/database.db
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            openWeatherMapBaseAddress = args[0];
            openWeatherMapAppId       = args[1];
            openWeatherDataPersistenceClientFilePath = args[2];

            currentWeatherService            = new CurrentWeatherService(openWeatherMapBaseAddress, openWeatherMapAppId);
            openWeatherDataPersistenceClient = new OpenWeatherDataStoreClient(openWeatherDataPersistenceClientFilePath);

            EventLog.WriteEntry($"Service started\nOpenWeatherMapAddress: {openWeatherMapBaseAddress}\nOpenWeatherMapAppId: {openWeatherMapAppId}", EventLogEntryType.Information);

            GeoCoordinate currentGeoCoordinate = locationService.GetCurrentGeoCoordinate().Result;

            EventLog.WriteEntry($"GeoCoordinate\n Latitude: {currentGeoCoordinate.Latitude}\n Longitude: {currentGeoCoordinate.Longitude}", EventLogEntryType.Information);


            WeatherData weatherData = currentWeatherService.GetCurrentWeather(currentGeoCoordinate.Latitude, currentGeoCoordinate.Longitude).Result;

            EventLog.WriteEntry($"Weather data\n Country: {weatherData.Sys.Country}\n Location: {weatherData.Name}\n Temp: {weatherData.Main.Temp}", EventLogEntryType.Information);

            openWeatherDataPersistenceClient.AddWeatherData(new WeatherDataModel()
            {
                Latitude  = currentGeoCoordinate.Latitude,
                Longitude = currentGeoCoordinate.Longitude,
                Temp      = weatherData.Main.Temp.Value,
                Location  = weatherData.Name,
                Country   = weatherData.Sys.Country
            });
        }
        public void HumidtyCheck()
        {
            CurrentWeatherService cws = new CurrentWeatherService();
            var result = cws.HumidCheck();

            Assert.That(result);
        }
示例#3
0
        public void TestCityNotFoundException()
        {
            CurrentWeatherService currentWeatherService = new CurrentWeatherService();
            string location = "ojfwbwovbwqobi";
            CurrentWeatherModel currentWeatherModel = new CurrentWeatherModel();

            Assert.Throws <ArgumentException>(() => (currentWeatherService.GetCurrentWeather(location)));
        }
        public void WebCallFailDueToIncorrectCity()
        {
            CurrentWeatherService cw = new CurrentWeatherService();
            var currentW             = cw.weatherCallManager.GetCurrentWeather();
            var expected             = currentW.ToString();

            Assert.AreEqual(expected, currentW);
        }
示例#5
0
        public void GetCurrentWeatherTest()
        {
            CurrentWeatherService currentWeatherService = new CurrentWeatherService();
            string location = "Stuttgart";
            CurrentWeatherModel currentWeatherModel = new CurrentWeatherModel();

            currentWeatherModel = currentWeatherService.GetCurrentWeather(location);
            Assert.NotNull(currentWeatherModel);
        }
        public void GetCurrentWeatherByCityIdAsync_WhenGivenCityId_ReturnCorrectResult()
        {
            Mock <IHttpClient> httpClientMock = TestHelper.GetHttpClientMock();
            Mock <IConfig>     configMock     = TestHelper.GetConfigMock();

            var           currentWeatherService = new CurrentWeatherService(httpClientMock.Object, configMock.Object, TestHelper.GetMemoryCache());
            WeatherDetail weatherDetail         = currentWeatherService.GetCurrentWeatherByCityIdAsync(123).Result;

            Assert.NotNull(weatherDetail);
        }
        public MainViewModel()
        {
            loginservice           = new LoginServiceSQL();
            iconPick               = new IconPick();
            calcuteConverter       = new CalcuteConverter();
            currentWeatherService  = new CurrentWeatherService();
            ShowWeatherCommand     = new ButtonCommandBase(ShowWeather);
            SetFavoriteCityCommand = new ButtonCommandBase(addFavoriteCity);
            forecastService        = new ForecastService();
            CityOutput             = new ObservableCollection <string>();

            ShowWeatherStartup();
        }