public WeatherApp() { InitializeComponent(); weatherSources[0] = new WebWeather(new TomorrowIOHandler(TomorrowIOResources.APIKey)); weatherSources[1] = new WebWeather(new StormglassIOHandler(StormglassIOResources.APIKey)); weatherBoxes[0] = tomorrowBox; weatherBoxes[1] = stormglassBox; weatherDataLabels[0] = new List <Label>(); weatherDataLabels[1] = new List <Label>(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 8; j++) { var label = new Label(); label.AutoSize = true; label.Location = j < 7 ? new Point(6, 45 * (j + 1)) : new Point(60, 395); label.Name = $"weatherInfoLabel{i}_{j}"; label.Size = new Size(60, 20); label.TabIndex = tabIndex; label.Text = "none"; if (j == 7) { label.Text = "loading..."; label.Font = new Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); } weatherDataLabels[i].Add(label); weatherBoxes[i].Controls.Add(label); tabIndex++; } } }
public void FetchWeatherDataTest() { var mock = new Mock <IWebServiceHandler>(); mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest); mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData); WebWeather weather = new WebWeather(mock.Object); var data = weather.FetchWeatherData(); Assert.NotNull(data); Assert.AreEqual(HumidityData.Humidity, data.Humidity); }
public void ErrorHandlingTest() { var mock = new Mock <IWebServiceHandler>(); mock.Setup(x => x.GetServiceRequestInfo()).Returns(UnauthorizedRequest); WebWeather weather = new WebWeather(mock.Object); weather.FetchWeatherData(); var status = weather.GetLastLog(); Assert.NotNull(status); Assert.AreEqual(FetchWeatherStatus.Error, status.Status); }
public void LastLogBehaviourTest() { var mock = new Mock <IWebServiceHandler>(); mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest); mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData); WebWeather weather = new WebWeather(mock.Object); Assert.Null(weather.GetLastLog()); weather.FetchWeatherData(); var status = weather.GetLastLog(); Assert.NotNull(status); Assert.AreEqual(FetchWeatherStatus.Success, status.Status); }
public void RequestsDelayTest() { var mock = new Mock <IWebServiceHandler>(); mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest); mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData); WebWeather weather = new WebWeather(mock.Object); weather.FetchWeatherData(); System.Threading.Thread.Sleep(100); weather.FetchWeatherData(); mock.Verify(mock => mock.ParseJSONObject(It.IsAny <string>()), Times.Once()); Assert.Pass(); }
public void ParseErrorDataTest() { var mock = new Mock <IWebServiceHandler>(); mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest); mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns((WeatherDataContainer?)null); WebWeather weather = new WebWeather(mock.Object); var data = weather.FetchWeatherData(); Assert.Null(data); var log = weather.GetLastLog(); Assert.NotNull(log); Assert.AreEqual(FetchWeatherStatus.Error, log.Status); }
/// <summary> /// 初始化天气 /// </summary> private void InitWeather() { //如果网络已连接,则获取最新的天气,否则读取本地天气 if (WebState.isConneted()) { //获取天气 WeatherStructure mWeather = WebWeather.getWeatherByCode(WebWeather.getCodeByIP()); SetWeather(mWeather); //更新本地数据 File.Delete(Config + "\\Weather.xml"); XmlDB mDB = XmlDBFactory.CreatXmlDB("Weather", Config + "\\Weather.xml", 1); mDB.Insert(mWeather); mDB.Commit(); } else { XmlDB mDB = XmlDBFactory.LoadXmlDB(Config + "\\Weather.xml"); List <object> mObjects = mDB.ReadByObject(new WeatherStructure()); WeatherStructure mWeather = (WeatherStructure)mObjects[0]; SetWeather(mWeather); } }
public MainWindow() { InitializeComponent(); weatherSources[0] = new WebWeather(new TomorrowIOHandler(TomorrowIOResources.APIKey)); weatherSources[1] = new WebWeather(new StormglassIOHandler(StormglassIOResources.APIKey)); weatherGrids[0] = tomorrowGrid; weatherGrids[1] = stormglassGrid; weatherDataLabels[0] = new List <Label>(); weatherDataLabels[1] = new List <Label>(); for (int i = 0; i < 2; i++) { foreach (Label label in weatherGrids[i].Children) { weatherDataLabels[i].Add(label); } } UpdateWeather(); }