Projekt

Obecné

Profil

« Předchozí | Další » 

Revize bfd5a848

Přidáno uživatelem Alex Konig před téměř 4 roky(ů)

re #8934 Creating unit tests for json parser

Zobrazit rozdíly:

Server/ServerApp/DataDownload/DataDownloader.cs
85 85
		}
86 86

  
87 87
		/// <summary>
88
		/// Downloads json file
88
		/// Downloads json file - returns contents of said file
89 89
		/// </summary>
90 90
		/// <returns> Path to file </returns>
91
		public string DownloadWeatherPrediction()
91
		virtual public string DownloadWeatherPrediction()
92 92
		{
93 93
			// TODO either set this path as attribute or if parameter JsonParser needs an attribute that would be set through constructor
94 94
			string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
95 95

  
96 96
			DateTime now = DateTime.Now;
97 97
			WebClient webClient = new WebClient();
98
			webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
98
			string data = webClient.DownloadString(predictionSite);
99 99

  
100
			return $"data/{now.Year}{now.Month}{now.Day}.json";
100
			return data;
101 101
		}
102 102

  
103 103
		/// <summary>
Server/ServerApp/Parser/OutputInfo/ValueToConditions.cs
57 57
        /// </summary>
58 58
        /// <param name="cloudCover">Value expected between 0-100</param>
59 59
        /// <returns>WeatherConditions</returns>
60
        internal static WeatherConditions CloudCoverToConditions(int cloudCover)
60
        public static WeatherConditions CloudCoverToConditions(int cloudCover)
61 61
        {
62 62
            if (cloudCover >= 66)
63 63
                return WeatherConditions.Overcast;
Server/ServerApp/Parser/OutputInfo/WeatherInfo.cs
94 94
        {
95 95
            WeatherInfo other = (WeatherInfo) obj;
96 96

  
97
            if (startTime == other.startTime && temp == other.temp && wind == other.wind && rain == other.rain && condition == other.condition)
98
                return true;
97
            if (startTime == other.startTime && rain == other.rain && condition == other.condition)
98
            {
99
                if ((int)(temp * 1000) == (int)(other.temp *1000) && (int)(wind*1000) == (int)(other.wind*1000))
100
                    return true;
101
            }
99 102

  
100 103
            return false;
101 104
        }
Server/ServerApp/Program.cs
131 131

  
132 132
            // PARSE DATA
133 133

  
134

  
135

  
136
            JsonParser jsonP = new JsonParser(null);
134
            JsonParser jsonP = new JsonParser(dd);
137 135
			jsonP.ParsePrediction();
138 136

  
139 137
			var res = jsonP.GetPredictionForTime(jsonP.Predictions[5].startTime, jsonP.Predictions[20].startTime);
......
146 144
			// TODO nastavit čas
147 145
			IDataParser p = new DataParser(dd);
148 146
            IPredictionController predictionController = new PredictionController(p);
149
            predictionController.Train();
147
            //predictionController.Train();
150 148
            //var results = predictionController.Predict()
151 149
			
152 150

  
Server/ServerApp/WeatherPredictionParser/JsonParser.cs
25 25
        /// <summary> Currently parsed day </summary>
26 26
        DateTime currParsedDay;
27 27
        /// <summary> Sunrise time of currently parsed day </summary>
28
        DateTime sunriseTime;
28
        List<DateTime> sunriseTime;
29 29
        /// <summary> Sunset time of currently parsed day </summary>
30
        DateTime sunsetTime;
30
        List<DateTime> sunsetTime;
31 31

  
32 32
        /// <summary>
33 33
        /// Constructor
......
103 103
        /// </summary>
104 104
        override public void ParsePrediction()
105 105
        {
106
            // TODO ask DataDownloader for download said file and return path to it
107
            
106
            sunriseTime = new List<DateTime>();
107
            sunsetTime = new List<DateTime>();
108

  
108 109
            // get file
109
            string file = loader.DownloadWeatherPrediction();
110
            string data = loader.DownloadWeatherPrediction();
110 111
            DateTime now = DateTime.Now;
111
            Console.WriteLine(File.Exists(file));
112 112

  
113 113
            Current = new WeatherInfo();
114 114
            Predictions = new List<WeatherInfo>();
115 115

  
116
            if (!File.Exists(file))
117
                return;
118

  
119
            // read file
120
            string data = File.ReadAllText(file);
121

  
122 116
            // parse
123 117
            JsonDocument doc = JsonDocument.Parse(data);
124 118
            JsonElement root = doc.RootElement;
......
173 167
        /// </summary>
174 168
        private void EncompassSunRiseSetTimes()
175 169
        {
170
            if (sunsetTime.Count < 1 || sunriseTime.Count < 0)
171
                return;
172

  
176 173
            // change current weather
177
            if ((Current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (Current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
174
            if ((Current.startTime.TimeOfDay > sunsetTime[0].TimeOfDay) || (Current.startTime.TimeOfDay < sunriseTime[0].TimeOfDay))
178 175
                Current.condition = WeatherConditions.Dark;
179 176

  
180 177
            // change prediction
178
            int index = 0;
181 179
            for (int i = 0; i < Predictions.Count - 1; i++)
182 180
            {
183 181
                WeatherInfo w = Predictions[i];
......
186 184
                // if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan
187 185
                int timespan = wNext.startTime.Hour - w.startTime.Hour;
188 186
                if (wNext.startTime.Hour < w.startTime.Hour)
189
                    timespan = (wNext.startTime.Hour+24) - w.startTime.Hour;
187
                {
188
                    timespan = (wNext.startTime.Hour + 24) - w.startTime.Hour;
189
                }
190 190
                
191 191
                w.intervalLength = timespan;
192 192

  
193 193
                // if start under sunset
194
                if (w.startTime.TimeOfDay > sunsetTime.TimeOfDay)
194
                if (w.startTime.TimeOfDay > sunsetTime[index].TimeOfDay)
195 195
                    w.condition = WeatherConditions.Dark;
196 196

  
197 197
                // if start under sunrise
198
                if (w.startTime.TimeOfDay < sunriseTime.TimeOfDay)
198
                if (w.startTime.TimeOfDay < sunriseTime[index].TimeOfDay)
199 199
                {
200
                    double howMuch = ((sunriseTime.Hour * 60 + sunriseTime.Minute) - (w.startTime.Hour * 60 + w.startTime.Minute)) / 60.0;
200
                    double howMuch = ((sunriseTime[index].Hour * 60 + sunriseTime[index].Minute) - (w.startTime.Hour * 60 + w.startTime.Minute)) / 60.0;
201 201

  
202 202
                    if (howMuch >= timespan / 2.0)
203 203
                        w.condition = WeatherConditions.Dark;
......
205 205

  
206 206
                // if start under sunrise
207 207
                TimeSpan endTime = new TimeSpan(w.startTime.TimeOfDay.Hours + timespan, w.startTime.TimeOfDay.Minutes, 0);
208
                if (endTime > sunsetTime.TimeOfDay)
208
                if (endTime > sunsetTime[index].TimeOfDay)
209 209
                {
210
                    double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunsetTime.Hour * 60 + sunsetTime.Minute)) / 60.0;
210
                    double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunsetTime[index].Hour * 60 + sunsetTime[index].Minute)) / 60.0;
211 211

  
212 212
                    if (howMuch >= timespan / 2.0)
213 213
                        w.condition = WeatherConditions.Dark;
214 214
                }
215

  
216
                if (Predictions[i].startTime.Date !=  Predictions[i + 1].startTime.Date)
217
                    index++;
215 218
            }
216 219

  
217 220
            // last prediction
......
221 224
            wLast.intervalLength = timespanLast;
222 225

  
223 226
            // if start under sunset
224
            if (wLast.startTime.TimeOfDay > sunsetTime.TimeOfDay)
227
            if (wLast.startTime.TimeOfDay > sunsetTime[sunsetTime.Count-1].TimeOfDay)
225 228
                wLast.condition = WeatherConditions.Dark;
226 229

  
227 230
            // if start under sunrise
228
            if (wLast.startTime.TimeOfDay < sunriseTime.TimeOfDay)
231
            if (wLast.startTime.TimeOfDay < sunriseTime[sunriseTime.Count - 1].TimeOfDay)
229 232
            {
230
                double howMuch = ((sunriseTime.Hour * 60 + sunriseTime.Minute) - (wLast.startTime.Hour * 60 + wLast.startTime.Minute)) / 60.0;
233
                double howMuch = ((sunriseTime[sunriseTime.Count - 1].Hour * 60 + sunriseTime[sunriseTime.Count - 1].Minute) - (wLast.startTime.Hour * 60 + wLast.startTime.Minute)) / 60.0;
231 234

  
232 235
                if (howMuch >= timespanLast / 2.0)
233 236
                    wLast.condition = WeatherConditions.Dark;
234 237
            }
235 238

  
236 239
            // if start under sunrise
237
            if (endTimeW > sunsetTime.TimeOfDay)
240
            if (endTimeW > sunsetTime[sunsetTime.Count - 1].TimeOfDay)
238 241
            {
239
                double howMuch = ((endTimeW.Hours * 60 + endTimeW.Minutes) - (sunsetTime.Hour * 60 + sunsetTime.Minute)) / 60.0;
242
                double howMuch = ((endTimeW.Hours * 60 + endTimeW.Minutes) - (sunsetTime[sunsetTime.Count - 1].Hour * 60 + sunsetTime[sunsetTime.Count - 1].Minute)) / 60.0;
240 243

  
241 244
                if (howMuch >= timespanLast / 2.0)
242 245
                    wLast.condition = WeatherConditions.Dark;
......
296 299
                    {
297 300
                        case "sunrise":
298 301
                            {
299
                                DateTime.TryParseExact(astrInfo.Current.Value.GetString(), "hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out sunriseTime);
300
                                Console.WriteLine("\t sunrise time : " + sunriseTime + " " + astrInfo.Current.Value.GetString());
302
                                DateTime newSunrise = new DateTime();
303
                                DateTime.TryParseExact(astrInfo.Current.Value.GetString(), "hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out newSunrise);
304
                                sunriseTime.Add(newSunrise);
305
                                //Console.WriteLine("\t sunrise time : " + sunriseTime + " " + astrInfo.Current.Value.GetString());
301 306
                                break;
302 307
                            }
303 308
                        case "sunset":
304 309
                            {
305
                                DateTime.TryParseExact(astrInfo.Current.Value.GetString(), "hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out sunsetTime);
306
                                Console.WriteLine("\t sunset time : " + sunsetTime + " " + astrInfo.Current.Value.GetString());
310
                                DateTime newSunset = new DateTime();
311
                                DateTime.TryParseExact(astrInfo.Current.Value.GetString(), "hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out newSunset);
312
                                sunsetTime.Add(newSunset);
313
                                //Console.WriteLine("\t sunset time : " + sunsetTime + " " + astrInfo.Current.Value.GetString());
307 314
                                break;
308 315
                            }
309 316
                    }
......
337 344
                                int cloudCover;
338 345
                                Int32.TryParse(oneH.Current.Value.GetString(), out cloudCover);
339 346
                                weather.condition = ValueToConditions.CloudCoverToConditions(cloudCover);
347
                                weather.lum = ValueToConditions.TransferConditionsToLux(weather.condition);
340 348
                                break;
341 349
                            }
342 350
                        // take into account highest value from "chanceofrain" and "chaceofsnow"
......
355 363
                                break;
356 364
                            }
357 365
                        // wind kmph has to be translated to mps
358
                        case "WindGustKmph":
366
                        case "windspeedKmph":
359 367
                            {
360 368
                                double windkmh;
361 369
                                Double.TryParse(oneH.Current.Value.GetString(), out windkmh);
......
388 396
        private WeatherInfo ParseCurrentWeather(ArrayEnumerator currentWeather)
389 397
        {
390 398
            WeatherInfo res = new WeatherInfo();
399
            res.intervalLength = 0;
391 400
            //res.current = true;
392 401

  
393 402
            while (currentWeather.MoveNext())
......
434 443

  
435 444
            }
436 445

  
446
            res.lum = ValueToConditions.TransferConditionsToLux(res.condition);
437 447
            return res;
438 448
        }
439 449

  
Server/TestProject/ParserTests/TestingParser.cs
8 8
using ServerApp.WeatherPredictionParser;
9 9
using ServerApp.DataDownload;
10 10

  
11
// 1h
12
// 0.5h to edit parsers 
13

  
14 11
namespace TestProject
15 12
{
16 13

  
......
1012 1009

  
1013 1010
        #region Json parser
1014 1011

  
1012
        #region Parsing
1013

  
1014
        string SetBasicData()
1015
        {
1016
            return
1017
@"{
1018
    ""current_condition"": [
1019
        {
1020
            ""FeelsLikeC"": ""4"",
1021
            ""cloudcover"": ""100"",
1022
            ""localObsDateTime"": ""2021-05-25 01:29 PM"",
1023
            ""observation_time"": ""11:29 AM"",
1024
            ""precipMM"": ""0.1"",
1025
            ""temp_C"": ""8"",
1026
            ""windspeedKmph"": ""13""
1027
        }
1028
    ],
1029
    ""weather"": [
1030
        {
1031
                ""astronomy"": [
1032
                    {
1033
                    ""sunrise"": ""05:10 AM"",
1034
                    ""sunset"": ""08:58 PM""
1035
                    }
1036
            ],
1037
            ""date"": ""2021-05-25"",
1038
            ""hourly"": [
1039
                {
1040
                    ""FeelsLikeC"": ""7"",
1041
                    ""WindGustKmph"": ""31"",
1042
                    ""chanceofrain"": ""87"",
1043
                    ""chanceofsnow"": ""0"",
1044
                    ""cloudcover"": ""92"",
1045
                    ""precipMM"": ""4.5"",
1046
                    ""tempC"": ""9"",
1047
                    ""time"": ""0"",
1048
                    ""windspeedKmph"": ""19""
1049
                },
1050
                {
1051
                    ""FeelsLikeC"": ""8"",
1052
                    ""WindGustKmph"": ""10"",
1053
                    ""chanceofrain"": ""50"",
1054
                    ""chanceofsnow"": ""0"",
1055
                    ""cloudcover"": ""60"",
1056
                    ""precipMM"": ""2.0"",
1057
                    ""tempC"": ""9"",
1058
                    ""time"": ""1200"",
1059
                    ""windspeedKmph"": ""10""
1060
                }
1061
            ]
1062
        },
1063
        {
1064
                ""astronomy"": [
1065
                    {
1066
                    ""sunrise"": ""05:09 AM"",
1067
                    ""sunset"": ""08:59 PM""
1068
                    }
1069
            ],
1070
            ""date"": ""2021-05-26"",
1071
            ""hourly"": [
1072
                {
1073
                    ""FeelsLikeC"": ""10"",
1074
                    ""WindGustKmph"": ""31"",
1075
                    ""chanceofrain"": ""0"",
1076
                    ""chanceofsnow"": ""0"",
1077
                    ""cloudcover"": ""0"",
1078
                    ""precipMM"": ""0"",
1079
                    ""tempC"": ""12"",
1080
                    ""time"": ""1200"",
1081
                    ""windspeedKmph"": ""19""
1082
                },
1083
                                {
1084
                    ""FeelsLikeC"": ""12"",
1085
                    ""WindGustKmph"": ""31"",
1086
                    ""chanceofrain"": ""0"",
1087
                    ""chanceofsnow"": ""80"",
1088
                    ""cloudcover"": ""92"",
1089
                    ""precipMM"": ""4.5"",
1090
                    ""tempC"": ""19"",
1091
                    ""time"": ""2100"",
1092
                    ""windspeedKmph"": ""19""
1093
                }
1094
            ]
1095
        },
1096
        {
1097
                ""astronomy"": [
1098
                    {
1099
                    ""sunrise"": ""05:08 AM"",
1100
                    ""sunset"": ""09:00 PM""
1101
                    }
1102
            ],
1103
            ""date"": ""2021-05-27"",
1104
            ""hourly"": [
1105
                {
1106
                    ""FeelsLikeC"": ""17"",
1107
                    ""WindGustKmph"": ""3"",
1108
                    ""chanceofrain"": ""7"",
1109
                    ""chanceofsnow"": ""0"",
1110
                    ""cloudcover"": ""10"",
1111
                    ""precipMM"": ""0"",
1112
                    ""tempC"": ""20"",
1113
                    ""time"": ""1800"",
1114
                    ""windspeedKmph"": ""9""
1115
                },
1116
                {
1117
                    ""FeelsLikeC"": ""9"",
1118
                    ""WindGustKmph"": ""31"",
1119
                    ""chanceofrain"": ""87"",
1120
                    ""chanceofsnow"": ""0"",
1121
                    ""cloudcover"": ""32"",
1122
                    ""precipMM"": ""4.5"",
1123
                    ""tempC"": ""9"",
1124
                    ""time"": ""2100"",
1125
                    ""windspeedKmph"": ""10""
1126
                }
1127
            ]
1128
        }
1129
    ]
1130
}";
1131
        }
1132

  
1133
        string SetAstronomyData()
1134
        {
1135
            return
1136
    @"{
1137
    ""current_condition"": [
1138
        {
1139
            ""FeelsLikeC"": ""4"",
1140
            ""cloudcover"": ""100"",
1141
            ""localObsDateTime"": ""2021-05-25 01:29 PM"",
1142
            ""observation_time"": ""11:29 AM"",
1143
            ""precipMM"": ""0.1"",
1144
            ""temp_C"": ""8"",
1145
            ""windspeedKmph"": ""13""
1146
        }
1147
    ],
1148
    ""weather"": [
1149
        {
1150
                ""astronomy"": [
1151
                    {
1152
                    ""sunrise"": ""08:10 AM"",
1153
                    ""sunset"": ""06:58 PM""
1154
                    }
1155
            ],
1156
            ""date"": ""2021-05-25"",
1157
            ""hourly"": [
1158
                {
1159
                    ""FeelsLikeC"": ""7"",
1160
                    ""WindGustKmph"": ""31"",
1161
                    ""chanceofrain"": ""87"",
1162
                    ""chanceofsnow"": ""0"",
1163
                    ""cloudcover"": ""92"",
1164
                    ""precipMM"": ""4.5"",
1165
                    ""tempC"": ""9"",
1166
                    ""time"": ""0"",
1167
                    ""windspeedKmph"": ""19""
1168
                },
1169
                {
1170
                    ""FeelsLikeC"": ""8"",
1171
                    ""WindGustKmph"": ""10"",
1172
                    ""chanceofrain"": ""50"",
1173
                    ""chanceofsnow"": ""0"",
1174
                    ""cloudcover"": ""60"",
1175
                    ""precipMM"": ""2.0"",
1176
                    ""tempC"": ""9"",
1177
                    ""time"": ""300"",
1178
                    ""windspeedKmph"": ""10""
1179
                },
1180
                {
1181
                    ""FeelsLikeC"": ""8"",
1182
                    ""WindGustKmph"": ""10"",
1183
                    ""chanceofrain"": ""50"",
1184
                    ""chanceofsnow"": ""0"",
1185
                    ""cloudcover"": ""60"",
1186
                    ""precipMM"": ""2.0"",
1187
                    ""tempC"": ""9"",
1188
                    ""time"": ""600"",
1189
                    ""windspeedKmph"": ""10""
1190
                },
1191
                {
1192
                    ""FeelsLikeC"": ""8"",
1193
                    ""WindGustKmph"": ""10"",
1194
                    ""chanceofrain"": ""50"",
1195
                    ""chanceofsnow"": ""0"",
1196
                    ""cloudcover"": ""60"",
1197
                    ""precipMM"": ""2.0"",
1198
                    ""tempC"": ""9"",
1199
                    ""time"": ""1500"",
1200
                    ""windspeedKmph"": ""10""
1201
                },
1202
                {
1203
                    ""FeelsLikeC"": ""8"",
1204
                    ""WindGustKmph"": ""10"",
1205
                    ""chanceofrain"": ""50"",
1206
                    ""chanceofsnow"": ""0"",
1207
                    ""cloudcover"": ""60"",
1208
                    ""precipMM"": ""2.0"",
1209
                    ""tempC"": ""9"",
1210
                    ""time"": ""1800"",
1211
                    ""windspeedKmph"": ""10""
1212
                },
1213
                {
1214
                    ""FeelsLikeC"": ""8"",
1215
                    ""WindGustKmph"": ""10"",
1216
                    ""chanceofrain"": ""50"",
1217
                    ""chanceofsnow"": ""0"",
1218
                    ""cloudcover"": ""60"",
1219
                    ""precipMM"": ""2.0"",
1220
                    ""tempC"": ""9"",
1221
                    ""time"": ""2100"",
1222
                    ""windspeedKmph"": ""10""
1223
                }
1224
            ]
1225
        },
1226
        {
1227
                ""astronomy"": [
1228
                    {
1229
                    ""sunrise"": ""05:09 AM"",
1230
                    ""sunset"": ""08:59 PM""
1231
                    }
1232
            ],
1233
            ""date"": ""2021-05-26"",
1234
            ""hourly"": [
1235
                {
1236
                    ""FeelsLikeC"": ""10"",
1237
                    ""WindGustKmph"": ""31"",
1238
                    ""chanceofrain"": ""0"",
1239
                    ""chanceofsnow"": ""0"",
1240
                    ""cloudcover"": ""0"",
1241
                    ""precipMM"": ""0"",
1242
                    ""tempC"": ""12"",
1243
                    ""time"": ""1200"",
1244
                    ""windspeedKmph"": ""19""
1245
                },
1246
                                {
1247
                    ""FeelsLikeC"": ""12"",
1248
                    ""WindGustKmph"": ""31"",
1249
                    ""chanceofrain"": ""0"",
1250
                    ""chanceofsnow"": ""80"",
1251
                    ""cloudcover"": ""92"",
1252
                    ""precipMM"": ""4.5"",
1253
                    ""tempC"": ""19"",
1254
                    ""time"": ""2100"",
1255
                    ""windspeedKmph"": ""19""
1256
                }
1257
            ]
1258
        }
1259
    ]
1260
}";
1261
        }
1262

  
1015 1263
        [TestMethod]
1016
        public void JsonParser()
1264
        public void JsonParserTestCurrent()
1017 1265
        {
1018
            /*
1019 1266
            TagInfo.CreateDictionaries();
1020 1267

  
1021
            // TODO make an input file
1022
            string data = "";
1268
            string data = SetBasicData();
1023 1269

  
1024
            Mock<DataDownloader> dl = new Mock<DataDownloader>();
1270
            Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
1025 1271
            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
1026 1272

  
1027 1273
            JsonParser target = new JsonParser(dl.Object);
1028 1274

  
1029 1275
            target.ParsePrediction();
1030 1276
            WeatherInfo current = target.Current;
1277

  
1278
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 13, 29, 0), 4, 0, 3.611, ValueToConditions.CloudCoverToConditions(100), 0), current);
1279
        }
1280

  
1281
        [TestMethod]
1282
        public void JsonParserTestPrediction()
1283
        {
1284
            string data = SetBasicData();
1285

  
1286
            Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
1287
            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
1288

  
1289
            JsonParser target = new JsonParser(dl.Object);
1290

  
1291
            target.ParsePrediction();
1292
            List<WeatherInfo> retVal = target.Predictions;
1293

  
1294
            Assert.AreEqual(6, retVal.Count);
1295
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 0, 0, 0), 7, 87, 5.277, ValueToConditions.CloudCoverToConditions(92), 12), retVal[0]);
1296
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 12, 0, 0), 8, 50, 2.77778, ValueToConditions.CloudCoverToConditions(60), 24), retVal[1]);
1297
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 12, 0, 0), 10, 0, 5.27778, ValueToConditions.CloudCoverToConditions(0), 9), retVal[2]);
1298
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 21, 0, 0), 12, 80, 5.27778, ValueToConditions.CloudCoverToConditions(92), 21), retVal[3]);
1299
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 18, 0, 0), 17, 7, 2.5, ValueToConditions.CloudCoverToConditions(10), 3), retVal[4]);
1300
            Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 21, 0, 0), 9, 87, 2.77778, WeatherConditions.Dark, 24), retVal[5]);
1301
        }
1302

  
1303
        [TestMethod]
1304
        public void JsonParserEncompassSunRiseSetTimes()
1305
        {
1306
            string data = SetAstronomyData();
1307

  
1308
            Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
1309
            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
1310

  
1311
            JsonParser target = new JsonParser(dl.Object);
1312

  
1313
            target.ParsePrediction();
1031 1314
            List<WeatherInfo> retVal = target.Predictions;
1032 1315

  
1033 1316
            Assert.AreEqual(8, retVal.Count);
1034
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
1035
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
1036
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
1037
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
1038
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[4]);
1039
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[5]);
1040
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[6]);
1041
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[7]);
1042
            */
1317
            Assert.AreEqual(WeatherConditions.Dark, retVal[0].condition);
1318
            Assert.AreEqual(WeatherConditions.Dark, retVal[1].condition);
1319
            Assert.AreNotEqual(WeatherConditions.Dark, retVal[2].condition);
1320
            Assert.AreNotEqual(WeatherConditions.Dark, retVal[3].condition);
1321
            Assert.AreEqual(WeatherConditions.Dark, retVal[4].condition);
1322
            Assert.AreEqual(WeatherConditions.Dark, retVal[5].condition);
1323

  
1324
            Assert.AreNotEqual(WeatherConditions.Dark, retVal[6].condition);
1325
            Assert.AreEqual(WeatherConditions.Dark, retVal[7].condition);
1043 1326
        }
1044 1327

  
1328
        #endregion
1045 1329

  
1330
        #region GetPredictionForTime
1046 1331
        [TestMethod]
1047 1332
        public void GetPredictionForTimeFilter()
1048 1333
        {
......
1193 1478
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
1194 1479
        }
1195 1480
        #endregion
1481

  
1482
        #endregion
1196 1483
    }
1197 1484
}

Také k dispozici: Unified diff