1 |
8a243ab2
|
A-Konig
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2 |
|
|
using System;
|
3 |
|
|
using ServerApp.Parser.Parsers;
|
4 |
|
|
using System.Collections.Generic;
|
5 |
|
|
using ServerApp.Parser.OutputInfo;
|
6 |
|
|
using Moq;
|
7 |
|
|
using ServerApp.Parser.InputData;
|
8 |
|
|
using ServerApp.WeatherPredictionParser;
|
9 |
|
|
using ServerApp.DataDownload;
|
10 |
|
|
|
11 |
847434c6
|
Roman Kalivoda
|
namespace ServerAppFunctionalTests.ParserTests
|
12 |
8a243ab2
|
A-Konig
|
{
|
13 |
|
|
/// <summary>
|
14 |
23e8ae04
|
A-Konig
|
/// Testing class for JsonParser
|
15 |
8a243ab2
|
A-Konig
|
/// </summary>
|
16 |
|
|
[TestClass]
|
17 |
|
|
public class JsonParserTesting
|
18 |
|
|
{
|
19 |
|
|
|
20 |
|
|
#region Json parser
|
21 |
|
|
|
22 |
|
|
#region Parsing
|
23 |
|
|
|
24 |
|
|
string SetBasicData()
|
25 |
|
|
{
|
26 |
|
|
return
|
27 |
|
|
@"{
|
28 |
|
|
""current_condition"": [
|
29 |
|
|
{
|
30 |
|
|
""FeelsLikeC"": ""4"",
|
31 |
|
|
""cloudcover"": ""100"",
|
32 |
|
|
""localObsDateTime"": ""2021-05-25 01:29 PM"",
|
33 |
|
|
""observation_time"": ""11:29 AM"",
|
34 |
|
|
""precipMM"": ""0.1"",
|
35 |
|
|
""temp_C"": ""8"",
|
36 |
|
|
""windspeedKmph"": ""13""
|
37 |
|
|
}
|
38 |
|
|
],
|
39 |
|
|
""weather"": [
|
40 |
|
|
{
|
41 |
|
|
""astronomy"": [
|
42 |
|
|
{
|
43 |
|
|
""sunrise"": ""05:10 AM"",
|
44 |
|
|
""sunset"": ""08:58 PM""
|
45 |
|
|
}
|
46 |
|
|
],
|
47 |
|
|
""date"": ""2021-05-25"",
|
48 |
|
|
""hourly"": [
|
49 |
|
|
{
|
50 |
|
|
""FeelsLikeC"": ""7"",
|
51 |
|
|
""WindGustKmph"": ""31"",
|
52 |
|
|
""chanceofrain"": ""87"",
|
53 |
|
|
""chanceofsnow"": ""0"",
|
54 |
|
|
""cloudcover"": ""92"",
|
55 |
|
|
""precipMM"": ""4.5"",
|
56 |
|
|
""tempC"": ""9"",
|
57 |
|
|
""time"": ""0"",
|
58 |
|
|
""windspeedKmph"": ""19""
|
59 |
|
|
},
|
60 |
|
|
{
|
61 |
|
|
""FeelsLikeC"": ""8"",
|
62 |
|
|
""WindGustKmph"": ""10"",
|
63 |
|
|
""chanceofrain"": ""50"",
|
64 |
|
|
""chanceofsnow"": ""0"",
|
65 |
|
|
""cloudcover"": ""60"",
|
66 |
|
|
""precipMM"": ""2.0"",
|
67 |
|
|
""tempC"": ""9"",
|
68 |
|
|
""time"": ""1200"",
|
69 |
|
|
""windspeedKmph"": ""10""
|
70 |
|
|
}
|
71 |
|
|
]
|
72 |
|
|
},
|
73 |
|
|
{
|
74 |
|
|
""astronomy"": [
|
75 |
|
|
{
|
76 |
|
|
""sunrise"": ""05:09 AM"",
|
77 |
|
|
""sunset"": ""08:59 PM""
|
78 |
|
|
}
|
79 |
|
|
],
|
80 |
|
|
""date"": ""2021-05-26"",
|
81 |
|
|
""hourly"": [
|
82 |
|
|
{
|
83 |
|
|
""FeelsLikeC"": ""10"",
|
84 |
|
|
""WindGustKmph"": ""31"",
|
85 |
|
|
""chanceofrain"": ""0"",
|
86 |
|
|
""chanceofsnow"": ""0"",
|
87 |
|
|
""cloudcover"": ""0"",
|
88 |
|
|
""precipMM"": ""0"",
|
89 |
|
|
""tempC"": ""12"",
|
90 |
|
|
""time"": ""1200"",
|
91 |
|
|
""windspeedKmph"": ""19""
|
92 |
|
|
},
|
93 |
|
|
{
|
94 |
|
|
""FeelsLikeC"": ""12"",
|
95 |
|
|
""WindGustKmph"": ""31"",
|
96 |
|
|
""chanceofrain"": ""0"",
|
97 |
|
|
""chanceofsnow"": ""80"",
|
98 |
|
|
""cloudcover"": ""92"",
|
99 |
|
|
""precipMM"": ""4.5"",
|
100 |
|
|
""tempC"": ""19"",
|
101 |
|
|
""time"": ""2100"",
|
102 |
|
|
""windspeedKmph"": ""19""
|
103 |
|
|
}
|
104 |
|
|
]
|
105 |
|
|
},
|
106 |
|
|
{
|
107 |
|
|
""astronomy"": [
|
108 |
|
|
{
|
109 |
|
|
""sunrise"": ""05:08 AM"",
|
110 |
|
|
""sunset"": ""09:00 PM""
|
111 |
|
|
}
|
112 |
|
|
],
|
113 |
|
|
""date"": ""2021-05-27"",
|
114 |
|
|
""hourly"": [
|
115 |
|
|
{
|
116 |
|
|
""FeelsLikeC"": ""17"",
|
117 |
|
|
""WindGustKmph"": ""3"",
|
118 |
|
|
""chanceofrain"": ""7"",
|
119 |
|
|
""chanceofsnow"": ""0"",
|
120 |
|
|
""cloudcover"": ""10"",
|
121 |
|
|
""precipMM"": ""0"",
|
122 |
|
|
""tempC"": ""20"",
|
123 |
|
|
""time"": ""1800"",
|
124 |
|
|
""windspeedKmph"": ""9""
|
125 |
|
|
},
|
126 |
|
|
{
|
127 |
|
|
""FeelsLikeC"": ""9"",
|
128 |
|
|
""WindGustKmph"": ""31"",
|
129 |
|
|
""chanceofrain"": ""87"",
|
130 |
|
|
""chanceofsnow"": ""0"",
|
131 |
|
|
""cloudcover"": ""32"",
|
132 |
|
|
""precipMM"": ""4.5"",
|
133 |
|
|
""tempC"": ""9"",
|
134 |
|
|
""time"": ""2100"",
|
135 |
|
|
""windspeedKmph"": ""10""
|
136 |
|
|
}
|
137 |
|
|
]
|
138 |
|
|
}
|
139 |
|
|
]
|
140 |
|
|
}";
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
string SetAstronomyData()
|
144 |
|
|
{
|
145 |
|
|
return
|
146 |
|
|
@"{
|
147 |
|
|
""current_condition"": [
|
148 |
|
|
{
|
149 |
|
|
""FeelsLikeC"": ""4"",
|
150 |
|
|
""cloudcover"": ""100"",
|
151 |
|
|
""localObsDateTime"": ""2021-05-25 01:29 PM"",
|
152 |
|
|
""observation_time"": ""11:29 AM"",
|
153 |
|
|
""precipMM"": ""0.1"",
|
154 |
|
|
""temp_C"": ""8"",
|
155 |
|
|
""windspeedKmph"": ""13""
|
156 |
|
|
}
|
157 |
|
|
],
|
158 |
|
|
""weather"": [
|
159 |
|
|
{
|
160 |
|
|
""astronomy"": [
|
161 |
|
|
{
|
162 |
|
|
""sunrise"": ""08:10 AM"",
|
163 |
|
|
""sunset"": ""06:58 PM""
|
164 |
|
|
}
|
165 |
|
|
],
|
166 |
|
|
""date"": ""2021-05-25"",
|
167 |
|
|
""hourly"": [
|
168 |
|
|
{
|
169 |
|
|
""FeelsLikeC"": ""7"",
|
170 |
|
|
""WindGustKmph"": ""31"",
|
171 |
|
|
""chanceofrain"": ""87"",
|
172 |
|
|
""chanceofsnow"": ""0"",
|
173 |
|
|
""cloudcover"": ""92"",
|
174 |
|
|
""precipMM"": ""4.5"",
|
175 |
|
|
""tempC"": ""9"",
|
176 |
|
|
""time"": ""0"",
|
177 |
|
|
""windspeedKmph"": ""19""
|
178 |
|
|
},
|
179 |
|
|
{
|
180 |
|
|
""FeelsLikeC"": ""8"",
|
181 |
|
|
""WindGustKmph"": ""10"",
|
182 |
|
|
""chanceofrain"": ""50"",
|
183 |
|
|
""chanceofsnow"": ""0"",
|
184 |
|
|
""cloudcover"": ""60"",
|
185 |
|
|
""precipMM"": ""2.0"",
|
186 |
|
|
""tempC"": ""9"",
|
187 |
|
|
""time"": ""300"",
|
188 |
|
|
""windspeedKmph"": ""10""
|
189 |
|
|
},
|
190 |
|
|
{
|
191 |
|
|
""FeelsLikeC"": ""8"",
|
192 |
|
|
""WindGustKmph"": ""10"",
|
193 |
|
|
""chanceofrain"": ""50"",
|
194 |
|
|
""chanceofsnow"": ""0"",
|
195 |
|
|
""cloudcover"": ""60"",
|
196 |
|
|
""precipMM"": ""2.0"",
|
197 |
|
|
""tempC"": ""9"",
|
198 |
|
|
""time"": ""600"",
|
199 |
|
|
""windspeedKmph"": ""10""
|
200 |
|
|
},
|
201 |
|
|
{
|
202 |
|
|
""FeelsLikeC"": ""8"",
|
203 |
|
|
""WindGustKmph"": ""10"",
|
204 |
|
|
""chanceofrain"": ""50"",
|
205 |
|
|
""chanceofsnow"": ""0"",
|
206 |
|
|
""cloudcover"": ""60"",
|
207 |
|
|
""precipMM"": ""2.0"",
|
208 |
|
|
""tempC"": ""9"",
|
209 |
|
|
""time"": ""1500"",
|
210 |
|
|
""windspeedKmph"": ""10""
|
211 |
|
|
},
|
212 |
|
|
{
|
213 |
|
|
""FeelsLikeC"": ""8"",
|
214 |
|
|
""WindGustKmph"": ""10"",
|
215 |
|
|
""chanceofrain"": ""50"",
|
216 |
|
|
""chanceofsnow"": ""0"",
|
217 |
|
|
""cloudcover"": ""60"",
|
218 |
|
|
""precipMM"": ""2.0"",
|
219 |
|
|
""tempC"": ""9"",
|
220 |
|
|
""time"": ""1800"",
|
221 |
|
|
""windspeedKmph"": ""10""
|
222 |
|
|
},
|
223 |
|
|
{
|
224 |
|
|
""FeelsLikeC"": ""8"",
|
225 |
|
|
""WindGustKmph"": ""10"",
|
226 |
|
|
""chanceofrain"": ""50"",
|
227 |
|
|
""chanceofsnow"": ""0"",
|
228 |
|
|
""cloudcover"": ""60"",
|
229 |
|
|
""precipMM"": ""2.0"",
|
230 |
|
|
""tempC"": ""9"",
|
231 |
|
|
""time"": ""2100"",
|
232 |
|
|
""windspeedKmph"": ""10""
|
233 |
|
|
}
|
234 |
|
|
]
|
235 |
|
|
},
|
236 |
|
|
{
|
237 |
|
|
""astronomy"": [
|
238 |
|
|
{
|
239 |
|
|
""sunrise"": ""05:09 AM"",
|
240 |
|
|
""sunset"": ""08:59 PM""
|
241 |
|
|
}
|
242 |
|
|
],
|
243 |
|
|
""date"": ""2021-05-26"",
|
244 |
|
|
""hourly"": [
|
245 |
|
|
{
|
246 |
|
|
""FeelsLikeC"": ""10"",
|
247 |
|
|
""WindGustKmph"": ""31"",
|
248 |
|
|
""chanceofrain"": ""0"",
|
249 |
|
|
""chanceofsnow"": ""0"",
|
250 |
|
|
""cloudcover"": ""0"",
|
251 |
|
|
""precipMM"": ""0"",
|
252 |
|
|
""tempC"": ""12"",
|
253 |
|
|
""time"": ""1200"",
|
254 |
|
|
""windspeedKmph"": ""19""
|
255 |
|
|
},
|
256 |
|
|
{
|
257 |
|
|
""FeelsLikeC"": ""12"",
|
258 |
|
|
""WindGustKmph"": ""31"",
|
259 |
|
|
""chanceofrain"": ""0"",
|
260 |
|
|
""chanceofsnow"": ""80"",
|
261 |
|
|
""cloudcover"": ""92"",
|
262 |
|
|
""precipMM"": ""4.5"",
|
263 |
|
|
""tempC"": ""19"",
|
264 |
|
|
""time"": ""2100"",
|
265 |
|
|
""windspeedKmph"": ""19""
|
266 |
|
|
}
|
267 |
|
|
]
|
268 |
|
|
}
|
269 |
|
|
]
|
270 |
|
|
}";
|
271 |
|
|
}
|
272 |
|
|
|
273 |
27aa66b5
|
A-Konig
|
string SetIncorrectInput()
|
274 |
|
|
{
|
275 |
23e8ae04
|
A-Konig
|
return
|
276 |
|
|
@"{
|
277 |
|
|
""cnd"": [
|
278 |
|
|
{
|
279 |
|
|
""FeelsLikeC"": ""4"",
|
280 |
|
|
""cloudcover"": ""100"",
|
281 |
|
|
""localObsDateTime"": ""2021-05-25 01:29 PM"",
|
282 |
|
|
""observation_time"": ""11:29 AM"",
|
283 |
|
|
""precipMM"": ""0.1"",
|
284 |
|
|
""temp_C"": ""8"",
|
285 |
|
|
""windspeedKmph"": ""13""
|
286 |
|
|
}
|
287 |
|
|
]
|
288 |
|
|
}
|
289 |
|
|
}";
|
290 |
27aa66b5
|
A-Konig
|
}
|
291 |
|
|
|
292 |
8a243ab2
|
A-Konig
|
[TestMethod]
|
293 |
|
|
public void JsonParserTestCurrent()
|
294 |
|
|
{
|
295 |
|
|
TagInfo.CreateDictionaries();
|
296 |
|
|
|
297 |
|
|
string data = SetBasicData();
|
298 |
|
|
|
299 |
27aa66b5
|
A-Konig
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
300 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
301 |
8a243ab2
|
A-Konig
|
|
302 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
303 |
|
|
|
304 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
305 |
|
|
|
306 |
|
|
target.ParsePrediction();
|
307 |
|
|
WeatherInfo current = target.Current;
|
308 |
|
|
|
309 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 13, 29, 0), 4, 0, 3.611, ValueToConditions.CloudCoverToConditions(100), 0), current);
|
310 |
|
|
}
|
311 |
|
|
|
312 |
27aa66b5
|
A-Konig
|
[TestMethod]
|
313 |
|
|
public void JsonParserNoneInput()
|
314 |
|
|
{
|
315 |
|
|
TagInfo.CreateDictionaries();
|
316 |
|
|
|
317 |
|
|
string data = "";
|
318 |
|
|
|
319 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
320 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
321 |
|
|
|
322 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
323 |
|
|
|
324 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
325 |
|
|
|
326 |
|
|
target.ParsePrediction();
|
327 |
|
|
WeatherInfo current = target.Current;
|
328 |
|
|
List<WeatherInfo> res = target.Predictions;
|
329 |
|
|
|
330 |
|
|
Assert.AreEqual(0, res.Count);
|
331 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(), 0, 0, 0, WeatherConditions.Dark, 0), current);
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
[TestMethod]
|
335 |
|
|
public void JsonParserNullInput()
|
336 |
|
|
{
|
337 |
|
|
TagInfo.CreateDictionaries();
|
338 |
|
|
|
339 |
|
|
string data = null;
|
340 |
|
|
|
341 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
342 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
343 |
|
|
|
344 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
345 |
|
|
|
346 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
347 |
|
|
|
348 |
|
|
target.ParsePrediction();
|
349 |
|
|
WeatherInfo current = target.Current;
|
350 |
|
|
List<WeatherInfo> res = target.Predictions;
|
351 |
|
|
|
352 |
|
|
Assert.AreEqual(0, res.Count);
|
353 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(), 0, 0, 0, WeatherConditions.Dark, 0), current);
|
354 |
|
|
}
|
355 |
|
|
|
356 |
|
|
[TestMethod]
|
357 |
|
|
public void JsonParserIncorrectInput()
|
358 |
|
|
{
|
359 |
|
|
TagInfo.CreateDictionaries();
|
360 |
|
|
|
361 |
|
|
string data = SetIncorrectInput();
|
362 |
|
|
|
363 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
364 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
365 |
|
|
|
366 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
367 |
|
|
|
368 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
369 |
|
|
|
370 |
|
|
target.ParsePrediction();
|
371 |
|
|
WeatherInfo current = target.Current;
|
372 |
|
|
List<WeatherInfo> res = target.Predictions;
|
373 |
|
|
|
374 |
|
|
Assert.AreEqual(0, res.Count);
|
375 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(), 0, 0, 0, WeatherConditions.Dark, 0), current);
|
376 |
|
|
}
|
377 |
|
|
|
378 |
8a243ab2
|
A-Konig
|
[TestMethod]
|
379 |
|
|
public void JsonParserTestPrediction()
|
380 |
|
|
{
|
381 |
|
|
string data = SetBasicData();
|
382 |
|
|
|
383 |
27aa66b5
|
A-Konig
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
384 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
385 |
8a243ab2
|
A-Konig
|
|
386 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
387 |
|
|
|
388 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
389 |
|
|
|
390 |
|
|
target.ParsePrediction();
|
391 |
|
|
List<WeatherInfo> retVal = target.Predictions;
|
392 |
|
|
|
393 |
|
|
Assert.AreEqual(6, retVal.Count);
|
394 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 0, 0, 0), 7, 87, 5.277, ValueToConditions.CloudCoverToConditions(92), 12), retVal[0]);
|
395 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 12, 0, 0), 8, 50, 2.77778, ValueToConditions.CloudCoverToConditions(60), 24), retVal[1]);
|
396 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 12, 0, 0), 10, 0, 5.27778, ValueToConditions.CloudCoverToConditions(0), 9), retVal[2]);
|
397 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 21, 0, 0), 12, 80, 5.27778, ValueToConditions.CloudCoverToConditions(92), 21), retVal[3]);
|
398 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 18, 0, 0), 17, 7, 2.5, ValueToConditions.CloudCoverToConditions(10), 3), retVal[4]);
|
399 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 21, 0, 0), 9, 87, 2.77778, WeatherConditions.Dark, 24), retVal[5]);
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
[TestMethod]
|
403 |
|
|
public void JsonParserEncompassSunRiseSetTimes()
|
404 |
|
|
{
|
405 |
|
|
string data = SetAstronomyData();
|
406 |
|
|
|
407 |
27aa66b5
|
A-Konig
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
408 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
409 |
8a243ab2
|
A-Konig
|
|
410 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
411 |
|
|
|
412 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
413 |
|
|
|
414 |
|
|
target.ParsePrediction();
|
415 |
|
|
List<WeatherInfo> retVal = target.Predictions;
|
416 |
|
|
|
417 |
|
|
Assert.AreEqual(8, retVal.Count);
|
418 |
|
|
Assert.AreEqual(WeatherConditions.Dark, retVal[0].condition);
|
419 |
|
|
Assert.AreEqual(WeatherConditions.Dark, retVal[1].condition);
|
420 |
|
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[2].condition);
|
421 |
|
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[3].condition);
|
422 |
|
|
Assert.AreEqual(WeatherConditions.Dark, retVal[4].condition);
|
423 |
|
|
Assert.AreEqual(WeatherConditions.Dark, retVal[5].condition);
|
424 |
|
|
|
425 |
|
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[6].condition);
|
426 |
|
|
Assert.AreEqual(WeatherConditions.Dark, retVal[7].condition);
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
#endregion
|
430 |
|
|
|
431 |
|
|
#region GetPredictionForTime
|
432 |
|
|
[TestMethod]
|
433 |
|
|
public void GetPredictionForTimeFilter()
|
434 |
|
|
{
|
435 |
|
|
string data = "";
|
436 |
27aa66b5
|
A-Konig
|
|
437 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
438 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
439 |
8a243ab2
|
A-Konig
|
|
440 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
441 |
|
|
|
442 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
443 |
|
|
|
444 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
445 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
446 |
|
|
|
447 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
448 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
449 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
450 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
451 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
452 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
453 |
|
|
|
454 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
455 |
|
|
|
456 |
|
|
target.Predictions = pred;
|
457 |
|
|
|
458 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 3, 0, 0, 0));
|
459 |
|
|
|
460 |
|
|
Assert.AreEqual(6, retVal.Count);
|
461 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
462 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
463 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[2]);
|
464 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[3]);
|
465 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15), retVal[4]);
|
466 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[5]);
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
[TestMethod]
|
470 |
|
|
public void GetPredictionForTimeInvalidInput()
|
471 |
|
|
{
|
472 |
|
|
string data = "";
|
473 |
27aa66b5
|
A-Konig
|
|
474 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
475 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
476 |
8a243ab2
|
A-Konig
|
|
477 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
478 |
|
|
|
479 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
480 |
|
|
|
481 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
482 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
483 |
|
|
|
484 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
485 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
486 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
487 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
488 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
489 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
490 |
|
|
|
491 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
492 |
|
|
|
493 |
|
|
target.Predictions = pred;
|
494 |
|
|
|
495 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 3, 0, 0, 0), new DateTime(2000, 1, 1, 6, 0, 0));
|
496 |
|
|
Assert.AreEqual(null, retVal);
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
[TestMethod]
|
500 |
|
|
public void GetPredictionForTimeAllTo()
|
501 |
|
|
{
|
502 |
|
|
string data = "";
|
503 |
27aa66b5
|
A-Konig
|
|
504 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
505 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
506 |
8a243ab2
|
A-Konig
|
|
507 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
508 |
|
|
|
509 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
510 |
|
|
|
511 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
512 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
513 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
514 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
515 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
516 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
517 |
|
|
|
518 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
519 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
520 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
521 |
|
|
|
522 |
|
|
target.Predictions = pred;
|
523 |
|
|
|
524 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, new DateTime(2000, 1, 2, 6, 0, 0));
|
525 |
|
|
|
526 |
|
|
Assert.AreEqual(5, retVal.Count);
|
527 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
528 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
529 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
530 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
531 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
532 |
|
|
}
|
533 |
|
|
|
534 |
|
|
[TestMethod]
|
535 |
|
|
public void GetPredictionForTimeAllFrom()
|
536 |
|
|
{
|
537 |
|
|
string data = "";
|
538 |
27aa66b5
|
A-Konig
|
|
539 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
540 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
541 |
8a243ab2
|
A-Konig
|
|
542 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
543 |
|
|
|
544 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
545 |
|
|
|
546 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
547 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
548 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
549 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
550 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 8, 1, 2, 60_000, 3));
|
551 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
552 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
553 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
554 |
|
|
|
555 |
|
|
target.Predictions = pred;
|
556 |
|
|
|
557 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 12, 0, 0), DateTime.MaxValue);
|
558 |
|
|
|
559 |
|
|
Assert.AreEqual(3, retVal.Count);
|
560 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
561 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[1]);
|
562 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[2]);
|
563 |
|
|
}
|
564 |
|
|
|
565 |
|
|
public void GetPredictionForTimeAll()
|
566 |
|
|
{
|
567 |
|
|
|
568 |
|
|
// TODO make an input file
|
569 |
|
|
string data = "";
|
570 |
27aa66b5
|
A-Konig
|
|
571 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
572 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
573 |
8a243ab2
|
A-Konig
|
|
574 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
575 |
|
|
|
576 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
577 |
|
|
|
578 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
579 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
580 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
581 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
582 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
583 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
584 |
|
|
|
585 |
|
|
target.Predictions = pred;
|
586 |
|
|
|
587 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, DateTime.MaxValue);
|
588 |
|
|
|
589 |
|
|
Assert.AreEqual(5, retVal.Count);
|
590 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
591 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
592 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
593 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
594 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
595 |
|
|
}
|
596 |
|
|
#endregion
|
597 |
|
|
|
598 |
|
|
#endregion
|
599 |
|
|
}
|
600 |
|
|
}
|