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 |
c45404fb
|
A-Konig
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 13, 29, 0), 4, 100, 3.611, ValueToConditions.CloudCoverToConditions(100), 0), current);
|
310 |
8a243ab2
|
A-Konig
|
}
|
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 |
de139774
|
A-Konig
|
|
433 |
|
|
[TestMethod]
|
434 |
|
|
public void GetPredictionForTimeOne()
|
435 |
|
|
{
|
436 |
|
|
string data = "";
|
437 |
|
|
|
438 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
439 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
440 |
|
|
|
441 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
442 |
|
|
|
443 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
444 |
|
|
|
445 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
446 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
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, 3, 0, 0), new DateTime(2000, 1, 1, 3, 0, 0));
|
459 |
|
|
|
460 |
|
|
Assert.AreEqual(1, retVal.Count);
|
461 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
462 |
|
|
}
|
463 |
|
|
|
464 |
8a243ab2
|
A-Konig
|
[TestMethod]
|
465 |
|
|
public void GetPredictionForTimeFilter()
|
466 |
|
|
{
|
467 |
|
|
string data = "";
|
468 |
27aa66b5
|
A-Konig
|
|
469 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
470 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
471 |
8a243ab2
|
A-Konig
|
|
472 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
473 |
|
|
|
474 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
475 |
|
|
|
476 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
477 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
478 |
|
|
|
479 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
480 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
481 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
482 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
483 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
484 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
485 |
|
|
|
486 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
487 |
|
|
|
488 |
|
|
target.Predictions = pred;
|
489 |
|
|
|
490 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 3, 0, 0, 0));
|
491 |
|
|
|
492 |
|
|
Assert.AreEqual(6, retVal.Count);
|
493 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
494 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
495 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[2]);
|
496 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[3]);
|
497 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15), retVal[4]);
|
498 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[5]);
|
499 |
|
|
}
|
500 |
|
|
|
501 |
de139774
|
A-Konig
|
[TestMethod]
|
502 |
|
|
public void GetPredictionForTimeFilterII()
|
503 |
|
|
{
|
504 |
|
|
string data = "";
|
505 |
|
|
|
506 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
507 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
508 |
|
|
|
509 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
510 |
|
|
|
511 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
512 |
|
|
|
513 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
514 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
515 |
|
|
|
516 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
517 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
518 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
519 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
520 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
521 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
522 |
|
|
|
523 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
524 |
|
|
|
525 |
|
|
target.Predictions = pred;
|
526 |
|
|
|
527 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 1, 18, 0, 0));
|
528 |
|
|
|
529 |
|
|
Assert.AreEqual(3, retVal.Count);
|
530 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
531 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
532 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[2]);
|
533 |
|
|
}
|
534 |
|
|
|
535 |
8a243ab2
|
A-Konig
|
[TestMethod]
|
536 |
|
|
public void GetPredictionForTimeInvalidInput()
|
537 |
|
|
{
|
538 |
|
|
string data = "";
|
539 |
27aa66b5
|
A-Konig
|
|
540 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
541 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
542 |
8a243ab2
|
A-Konig
|
|
543 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
544 |
|
|
|
545 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
546 |
|
|
|
547 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
548 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
549 |
|
|
|
550 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
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 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
555 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
556 |
|
|
|
557 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
558 |
|
|
|
559 |
|
|
target.Predictions = pred;
|
560 |
|
|
|
561 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 3, 0, 0, 0), new DateTime(2000, 1, 1, 6, 0, 0));
|
562 |
|
|
Assert.AreEqual(null, retVal);
|
563 |
|
|
}
|
564 |
|
|
|
565 |
|
|
[TestMethod]
|
566 |
|
|
public void GetPredictionForTimeAllTo()
|
567 |
|
|
{
|
568 |
|
|
string data = "";
|
569 |
27aa66b5
|
A-Konig
|
|
570 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
571 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
572 |
8a243ab2
|
A-Konig
|
|
573 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
574 |
|
|
|
575 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
576 |
|
|
|
577 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
578 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
579 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
580 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
581 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
582 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
583 |
|
|
|
584 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
585 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
586 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
587 |
|
|
|
588 |
|
|
target.Predictions = pred;
|
589 |
|
|
|
590 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, new DateTime(2000, 1, 2, 6, 0, 0));
|
591 |
|
|
|
592 |
|
|
Assert.AreEqual(5, retVal.Count);
|
593 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
594 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
595 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
596 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
597 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
598 |
|
|
}
|
599 |
|
|
|
600 |
|
|
[TestMethod]
|
601 |
|
|
public void GetPredictionForTimeAllFrom()
|
602 |
|
|
{
|
603 |
|
|
string data = "";
|
604 |
27aa66b5
|
A-Konig
|
|
605 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
606 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
607 |
8a243ab2
|
A-Konig
|
|
608 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
609 |
|
|
|
610 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
611 |
|
|
|
612 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
613 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
614 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
615 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
616 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 8, 1, 2, 60_000, 3));
|
617 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
618 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
619 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
620 |
|
|
|
621 |
|
|
target.Predictions = pred;
|
622 |
|
|
|
623 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 12, 0, 0), DateTime.MaxValue);
|
624 |
|
|
|
625 |
|
|
Assert.AreEqual(3, retVal.Count);
|
626 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
627 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[1]);
|
628 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[2]);
|
629 |
|
|
}
|
630 |
|
|
|
631 |
|
|
public void GetPredictionForTimeAll()
|
632 |
|
|
{
|
633 |
|
|
|
634 |
|
|
// TODO make an input file
|
635 |
|
|
string data = "";
|
636 |
27aa66b5
|
A-Konig
|
|
637 |
|
|
Mock<IDataDownloader> dl = new Mock<IDataDownloader>();
|
638 |
|
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
|
639 |
8a243ab2
|
A-Konig
|
|
640 |
|
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
641 |
|
|
|
642 |
|
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
643 |
|
|
|
644 |
|
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
645 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
646 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
647 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
648 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
649 |
|
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
650 |
|
|
|
651 |
|
|
target.Predictions = pred;
|
652 |
|
|
|
653 |
|
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, DateTime.MaxValue);
|
654 |
|
|
|
655 |
|
|
Assert.AreEqual(5, retVal.Count);
|
656 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
657 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
658 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
659 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
660 |
|
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
661 |
|
|
}
|
662 |
|
|
#endregion
|
663 |
|
|
|
664 |
|
|
#endregion
|
665 |
|
|
}
|
666 |
|
|
}
|