1
|
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
|
namespace ServerAppFunctionalTests.ParserTests
|
12
|
{
|
13
|
/// <summary>
|
14
|
/// Summary description for WeatherParserTesting
|
15
|
/// </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
|
[TestMethod]
|
274
|
public void JsonParserTestCurrent()
|
275
|
{
|
276
|
TagInfo.CreateDictionaries();
|
277
|
|
278
|
string data = SetBasicData();
|
279
|
|
280
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
281
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
282
|
|
283
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
284
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
285
|
|
286
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
287
|
|
288
|
target.ParsePrediction();
|
289
|
WeatherInfo current = target.Current;
|
290
|
|
291
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 13, 29, 0), 4, 0, 3.611, ValueToConditions.CloudCoverToConditions(100), 0), current);
|
292
|
}
|
293
|
|
294
|
[TestMethod]
|
295
|
public void JsonParserTestPrediction()
|
296
|
{
|
297
|
string data = SetBasicData();
|
298
|
|
299
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
300
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
301
|
|
302
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
303
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
304
|
|
305
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
306
|
|
307
|
target.ParsePrediction();
|
308
|
List<WeatherInfo> retVal = target.Predictions;
|
309
|
|
310
|
Assert.AreEqual(6, retVal.Count);
|
311
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 0, 0, 0), 7, 87, 5.277, ValueToConditions.CloudCoverToConditions(92), 12), retVal[0]);
|
312
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 12, 0, 0), 8, 50, 2.77778, ValueToConditions.CloudCoverToConditions(60), 24), retVal[1]);
|
313
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 12, 0, 0), 10, 0, 5.27778, ValueToConditions.CloudCoverToConditions(0), 9), retVal[2]);
|
314
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 21, 0, 0), 12, 80, 5.27778, ValueToConditions.CloudCoverToConditions(92), 21), retVal[3]);
|
315
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 18, 0, 0), 17, 7, 2.5, ValueToConditions.CloudCoverToConditions(10), 3), retVal[4]);
|
316
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 21, 0, 0), 9, 87, 2.77778, WeatherConditions.Dark, 24), retVal[5]);
|
317
|
}
|
318
|
|
319
|
[TestMethod]
|
320
|
public void JsonParserEncompassSunRiseSetTimes()
|
321
|
{
|
322
|
string data = SetAstronomyData();
|
323
|
|
324
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
325
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
326
|
|
327
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
328
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
329
|
|
330
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
331
|
|
332
|
target.ParsePrediction();
|
333
|
List<WeatherInfo> retVal = target.Predictions;
|
334
|
|
335
|
Assert.AreEqual(8, retVal.Count);
|
336
|
Assert.AreEqual(WeatherConditions.Dark, retVal[0].condition);
|
337
|
Assert.AreEqual(WeatherConditions.Dark, retVal[1].condition);
|
338
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[2].condition);
|
339
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[3].condition);
|
340
|
Assert.AreEqual(WeatherConditions.Dark, retVal[4].condition);
|
341
|
Assert.AreEqual(WeatherConditions.Dark, retVal[5].condition);
|
342
|
|
343
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[6].condition);
|
344
|
Assert.AreEqual(WeatherConditions.Dark, retVal[7].condition);
|
345
|
}
|
346
|
|
347
|
#endregion
|
348
|
|
349
|
#region GetPredictionForTime
|
350
|
[TestMethod]
|
351
|
public void GetPredictionForTimeFilter()
|
352
|
{
|
353
|
string data = "";
|
354
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
355
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
356
|
|
357
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
358
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
359
|
|
360
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
361
|
|
362
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
363
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
364
|
|
365
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
366
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
367
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
368
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
369
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
370
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
371
|
|
372
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
373
|
|
374
|
target.Predictions = pred;
|
375
|
|
376
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 3, 0, 0, 0));
|
377
|
|
378
|
Assert.AreEqual(6, retVal.Count);
|
379
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
380
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
381
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[2]);
|
382
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[3]);
|
383
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15), retVal[4]);
|
384
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[5]);
|
385
|
}
|
386
|
|
387
|
[TestMethod]
|
388
|
public void GetPredictionForTimeInvalidInput()
|
389
|
{
|
390
|
string data = "";
|
391
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
392
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
393
|
|
394
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
395
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
396
|
|
397
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
398
|
|
399
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
400
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
401
|
|
402
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
403
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
404
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
405
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
406
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
407
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
408
|
|
409
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
410
|
|
411
|
target.Predictions = pred;
|
412
|
|
413
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 3, 0, 0, 0), new DateTime(2000, 1, 1, 6, 0, 0));
|
414
|
Assert.AreEqual(null, retVal);
|
415
|
}
|
416
|
|
417
|
[TestMethod]
|
418
|
public void GetPredictionForTimeAllTo()
|
419
|
{
|
420
|
string data = "";
|
421
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
422
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
423
|
|
424
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
425
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
426
|
|
427
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
428
|
|
429
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
430
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
431
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
432
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
433
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
434
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
435
|
|
436
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
437
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
438
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
439
|
|
440
|
target.Predictions = pred;
|
441
|
|
442
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, new DateTime(2000, 1, 2, 6, 0, 0));
|
443
|
|
444
|
Assert.AreEqual(5, retVal.Count);
|
445
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
446
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
447
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
448
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
449
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
450
|
}
|
451
|
|
452
|
[TestMethod]
|
453
|
public void GetPredictionForTimeAllFrom()
|
454
|
{
|
455
|
string data = "";
|
456
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
457
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
458
|
|
459
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
460
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
461
|
|
462
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
463
|
|
464
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
465
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
466
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
467
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
468
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 8, 1, 2, 60_000, 3));
|
469
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
470
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
471
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
472
|
|
473
|
target.Predictions = pred;
|
474
|
|
475
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 12, 0, 0), DateTime.MaxValue);
|
476
|
|
477
|
Assert.AreEqual(3, retVal.Count);
|
478
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
479
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[1]);
|
480
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[2]);
|
481
|
}
|
482
|
|
483
|
public void GetPredictionForTimeAll()
|
484
|
{
|
485
|
|
486
|
// TODO make an input file
|
487
|
string data = "";
|
488
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
489
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
490
|
|
491
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
492
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
493
|
|
494
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
495
|
|
496
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
497
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
498
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
499
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
500
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
501
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
502
|
|
503
|
target.Predictions = pred;
|
504
|
|
505
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, DateTime.MaxValue);
|
506
|
|
507
|
Assert.AreEqual(5, retVal.Count);
|
508
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
509
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
510
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
511
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
512
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
513
|
}
|
514
|
#endregion
|
515
|
|
516
|
#endregion
|
517
|
}
|
518
|
}
|