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 TestProject
|
12
|
{
|
13
|
|
14
|
[TestClass]
|
15
|
public class TestingParser
|
16
|
{
|
17
|
[TestMethod]
|
18
|
public void AbstactClassTest()
|
19
|
{
|
20
|
IDataParser p = new DataParser(null);
|
21
|
List<ActivityInfo> aa = p.AttendanceList;
|
22
|
List<WeatherInfo> wa = p.WeatherList;
|
23
|
|
24
|
DataParser pp = (DataParser)p;
|
25
|
List<ActivityInfo> ap = pp.AttendanceList;
|
26
|
List<WeatherInfo> wp = pp.WeatherList;
|
27
|
|
28
|
Assert.AreEqual(aa, ap);
|
29
|
Assert.AreEqual(wa, wp);
|
30
|
}
|
31
|
|
32
|
// ------------------------------------ MERGE LISTS -------------------------------------
|
33
|
|
34
|
#region Merge lists
|
35
|
[TestMethod]
|
36
|
public void MergeListsNull()
|
37
|
{
|
38
|
DataParser target = new DataParser(null);
|
39
|
PrivateObject obj = new PrivateObject(target);
|
40
|
|
41
|
List<ActivityInfo> jis = null;
|
42
|
List<ActivityInfo> pc = null;
|
43
|
|
44
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
45
|
Assert.AreEqual(0, retVal.Count);
|
46
|
}
|
47
|
|
48
|
[TestMethod]
|
49
|
public void MergeListsJisNull()
|
50
|
{
|
51
|
DataParser target = new DataParser(null);
|
52
|
PrivateObject obj = new PrivateObject(target);
|
53
|
|
54
|
List<ActivityInfo> jis = null;
|
55
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
56
|
|
57
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
58
|
Assert.AreEqual(pc, retVal);
|
59
|
}
|
60
|
|
61
|
[TestMethod]
|
62
|
public void MergeListsPcNull()
|
63
|
{
|
64
|
DataParser target = new DataParser(null);
|
65
|
PrivateObject obj = new PrivateObject(target);
|
66
|
|
67
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
68
|
List<ActivityInfo> pc = null;
|
69
|
|
70
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
71
|
Assert.AreEqual(jis, retVal);
|
72
|
}
|
73
|
|
74
|
[TestMethod]
|
75
|
public void MergeListsOneNoOverlap()
|
76
|
{
|
77
|
DataParser target = new DataParser(null);
|
78
|
PrivateObject obj = new PrivateObject(target);
|
79
|
|
80
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
81
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
82
|
|
83
|
jis.Add(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
84
|
pc.Add(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 18, 0, 0), 3));
|
85
|
|
86
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
87
|
|
88
|
Assert.AreEqual(2, retVal.Count);
|
89
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 15, 0, 0), 3), retVal[0]);
|
90
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 18, 0, 0), 3), retVal[1]);
|
91
|
}
|
92
|
|
93
|
[TestMethod]
|
94
|
public void MergeListsOneOverlap()
|
95
|
{
|
96
|
DataParser target = new DataParser(null);
|
97
|
PrivateObject obj = new PrivateObject(target);
|
98
|
|
99
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
100
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
101
|
|
102
|
jis.Add(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
103
|
pc.Add(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
104
|
|
105
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
106
|
|
107
|
Assert.AreEqual(1, retVal.Count);
|
108
|
Assert.AreEqual(new ActivityInfo("FAV", 8, new DateTime(2001, 1, 1, 15, 0, 0), 3), retVal[0]);
|
109
|
}
|
110
|
|
111
|
[TestMethod]
|
112
|
public void MergeListsTwoNoOverlap()
|
113
|
{
|
114
|
DataParser target = new DataParser(null);
|
115
|
PrivateObject obj = new PrivateObject(target);
|
116
|
|
117
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
118
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
119
|
|
120
|
jis.Add(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 9, 0, 0), 3));
|
121
|
jis.Add(new ActivityInfo("FAV", 1, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
122
|
pc.Add(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3));
|
123
|
pc.Add(new ActivityInfo("FAV", 2, new DateTime(2001, 1, 1, 18, 0, 0), 3));
|
124
|
|
125
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
126
|
|
127
|
Assert.AreEqual(4, retVal.Count);
|
128
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 9, 0, 0), 3), retVal[0]);
|
129
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3), retVal[1]);
|
130
|
Assert.AreEqual(new ActivityInfo("FAV", 1, new DateTime(2001, 1, 1, 15, 0, 0), 3), retVal[2]);
|
131
|
Assert.AreEqual(new ActivityInfo("FAV", 2, new DateTime(2001, 1, 1, 18, 0, 0), 3), retVal[3]);
|
132
|
}
|
133
|
|
134
|
[TestMethod]
|
135
|
public void MergeListsTwoOverlap()
|
136
|
{
|
137
|
DataParser target = new DataParser(null);
|
138
|
PrivateObject obj = new PrivateObject(target);
|
139
|
|
140
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
141
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
142
|
|
143
|
jis.Add(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 9, 0, 0), 3));
|
144
|
jis.Add(new ActivityInfo("FAV", 1, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
145
|
pc.Add(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3));
|
146
|
pc.Add(new ActivityInfo("FAV", 2, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
147
|
|
148
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
149
|
|
150
|
Assert.AreEqual(3, retVal.Count);
|
151
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2001, 1, 1, 9, 0, 0), 3), retVal[0]);
|
152
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3), retVal[1]);
|
153
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 15, 0, 0), 3), retVal[2]);
|
154
|
}
|
155
|
|
156
|
[TestMethod]
|
157
|
public void MergeListsMultiple()
|
158
|
{
|
159
|
DataParser target = new DataParser(null);
|
160
|
PrivateObject obj = new PrivateObject(target);
|
161
|
|
162
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
163
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
164
|
|
165
|
jis.Add(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 10, 9, 0, 0), 3));
|
166
|
jis.Add(new ActivityInfo("FAV", 1, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
167
|
jis.Add(new ActivityInfo("FDU", 3, new DateTime(2001, 4, 1, 15, 0, 0), 3));
|
168
|
|
169
|
pc.Add(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3));
|
170
|
pc.Add(new ActivityInfo("FAV", 2, new DateTime(2001, 1, 1, 15, 0, 0), 3));
|
171
|
pc.Add(new ActivityInfo("FAV", 5, new DateTime(2001, 4, 1, 15, 0, 0), 3));
|
172
|
|
173
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
|
174
|
|
175
|
Assert.AreEqual(5, retVal.Count);
|
176
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 10, 9, 0, 0), 3), retVal[0]);
|
177
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 12, 0, 0), 3), retVal[1]);
|
178
|
Assert.AreEqual(new ActivityInfo("FAV", 3, new DateTime(2001, 1, 1, 15, 0, 0), 3), retVal[2]);
|
179
|
Assert.AreEqual(new ActivityInfo("FDU", 3, new DateTime(2001, 4, 1, 15, 0, 0), 3), retVal[3]);
|
180
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2001, 4, 1, 15, 0, 0), 3), retVal[4]);
|
181
|
}
|
182
|
#endregion
|
183
|
|
184
|
// ------------------------------ WEATHER PARSER ----------------------------------------
|
185
|
|
186
|
#region Weather parser
|
187
|
|
188
|
#region Parse days
|
189
|
[TestMethod]
|
190
|
public void ParseWeatherDayOne()
|
191
|
{
|
192
|
string path = "";
|
193
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
194
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast)/1000));
|
195
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 7, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast)/1000));
|
196
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 10, 3, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast)/1000));
|
197
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 12, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast)/1000));
|
198
|
|
199
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
200
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
201
|
|
202
|
WeatherParser target = new WeatherParser(dl.Object);
|
203
|
PrivateObject obj = new PrivateObject(target);
|
204
|
|
205
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
206
|
|
207
|
Assert.AreEqual(1, retVal.Count);
|
208
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 8, 50, 1.25, 10_000, 18-7), retVal[0]);
|
209
|
}
|
210
|
|
211
|
[TestMethod]
|
212
|
public void ParseWeatherDayOneFiltering()
|
213
|
{
|
214
|
string path = "";
|
215
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
216
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
217
|
|
218
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 7, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
219
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 10, 3, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
220
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 12, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
221
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 13, 0, 0), 12, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
222
|
|
223
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
224
|
|
225
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
226
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
227
|
|
228
|
WeatherParser target = new WeatherParser(dl.Object);
|
229
|
PrivateObject obj = new PrivateObject(target);
|
230
|
|
231
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
232
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
233
|
|
234
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1, 9, 0, 0), new DateTime(2000, 1, 1, 15, 0, 0));
|
235
|
|
236
|
Assert.AreEqual(1, retVal.Count);
|
237
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 9.75, 25, 1.75, 10_000, 18 - 7), retVal[0]);
|
238
|
}
|
239
|
|
240
|
[TestMethod]
|
241
|
public void ParseWeatherDayTwo()
|
242
|
{
|
243
|
string path = "";
|
244
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
245
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
246
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
247
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
248
|
|
249
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
250
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
251
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
252
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
253
|
|
254
|
|
255
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
256
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
257
|
|
258
|
WeatherParser target = new WeatherParser(dl.Object);
|
259
|
PrivateObject obj = new PrivateObject(target);
|
260
|
|
261
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
262
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
263
|
|
264
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
265
|
|
266
|
Assert.AreEqual(2, retVal.Count);
|
267
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 6, 100, 1, 10_000, 18-7), retVal[0]);
|
268
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 7, 0, 0), 10, 25, 2, 10_000, 18-7), retVal[1]);
|
269
|
}
|
270
|
|
271
|
[TestMethod]
|
272
|
public void ParseWeatherDayTwoFiltering()
|
273
|
{
|
274
|
string path = "";
|
275
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
276
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
277
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
278
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
279
|
|
280
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
281
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
282
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
283
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
284
|
|
285
|
|
286
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
287
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
288
|
|
289
|
WeatherParser target = new WeatherParser(dl.Object);
|
290
|
PrivateObject obj = new PrivateObject(target);
|
291
|
|
292
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
293
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
294
|
|
295
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2000, 1, 1, 11, 0, 0));
|
296
|
|
297
|
Assert.AreEqual(1, retVal.Count);
|
298
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 6, 100, 1, 10_000, 18 - 7), retVal[0]);
|
299
|
//Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 7, 0, 0), 10, 25, 2, 10_000, 18 - 7), retVal[1]);
|
300
|
}
|
301
|
#endregion
|
302
|
|
303
|
#region Parse hours
|
304
|
[TestMethod]
|
305
|
public void ParseWeatherHourOne()
|
306
|
{
|
307
|
string path = "";
|
308
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
309
|
|
310
|
// day 1
|
311
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
312
|
|
313
|
|
314
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
315
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
316
|
|
317
|
WeatherParser target = new WeatherParser(dl.Object);
|
318
|
PrivateObject obj = new PrivateObject(target);
|
319
|
|
320
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
321
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
322
|
|
323
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2001, 1, 1, 11, 0, 0));
|
324
|
|
325
|
Assert.AreEqual(1, retVal.Count);
|
326
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 5, 100, 0, (double)0, 2), retVal[0]);
|
327
|
}
|
328
|
|
329
|
[TestMethod]
|
330
|
public void ParseWeatherHourMultiple()
|
331
|
{
|
332
|
string path = "";
|
333
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
334
|
|
335
|
// day 1
|
336
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
337
|
|
338
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
339
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
340
|
|
341
|
// day 2
|
342
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Sunny) / 1000));
|
343
|
|
344
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
345
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
346
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 15, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
347
|
|
348
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
349
|
|
350
|
|
351
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
352
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
353
|
|
354
|
WeatherParser target = new WeatherParser(dl.Object);
|
355
|
PrivateObject obj = new PrivateObject(target);
|
356
|
|
357
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
358
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
359
|
|
360
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2001, 1, 1, 11, 0, 0));
|
361
|
|
362
|
Assert.AreEqual(5, retVal.Count);
|
363
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 5, 100, 0, (double)0, 2), retVal[0]);
|
364
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 6.5, 100, 1.5, 10_000, 2), retVal[1]);
|
365
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 11, 0, 0), 5, 0, 2, 60_000, 2), retVal[2]);
|
366
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 13, 0, 0), 10, 25, 2, 10_000, 2), retVal[3]);
|
367
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 15, 0, 0), 15, 40, 2, 10_000, 2), retVal[4]);
|
368
|
}
|
369
|
|
370
|
|
371
|
[TestMethod]
|
372
|
public void ParseWeatherHourFiltering()
|
373
|
{
|
374
|
string path = "";
|
375
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
376
|
|
377
|
// day 1
|
378
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
379
|
|
380
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
381
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
382
|
|
383
|
// day 2
|
384
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Sunny) / 1000));
|
385
|
|
386
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
387
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
388
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 15, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
389
|
|
390
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
391
|
|
392
|
|
393
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
394
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
395
|
|
396
|
WeatherParser target = new WeatherParser(dl.Object);
|
397
|
PrivateObject obj = new PrivateObject(target);
|
398
|
|
399
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
400
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
401
|
|
402
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 9, 0, 0), new DateTime(2000, 2, 1, 13, 0, 0));
|
403
|
|
404
|
Assert.AreEqual(3, retVal.Count);
|
405
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 6.5, 100, 1.5, 10_000, 2), retVal[0]);
|
406
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 11, 0, 0), 5, 0, 2, 60_000, 2), retVal[1]);
|
407
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 13, 0, 0), 10, 33, 2, 10_000, 2), retVal[2]);
|
408
|
}
|
409
|
|
410
|
[TestMethod]
|
411
|
public void ParseWeatherHourNone()
|
412
|
{
|
413
|
string path = "";
|
414
|
List<WeatherInstance> data = new List<WeatherInstance>();
|
415
|
|
416
|
// day 1
|
417
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
418
|
data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
|
419
|
|
420
|
// day 2
|
421
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
422
|
data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 17, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
|
423
|
|
424
|
|
425
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
426
|
dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
|
427
|
|
428
|
WeatherParser target = new WeatherParser(dl.Object);
|
429
|
PrivateObject obj = new PrivateObject(target);
|
430
|
|
431
|
List<ActivityInfo> jis = new List<ActivityInfo>();
|
432
|
List<ActivityInfo> pc = new List<ActivityInfo>();
|
433
|
|
434
|
List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 2, 1, 15, 0, 0));
|
435
|
|
436
|
Assert.AreEqual(0, retVal.Count);
|
437
|
}
|
438
|
#endregion
|
439
|
|
440
|
#endregion
|
441
|
|
442
|
// -------------------------------- JIS PARSER -----------------------------------------
|
443
|
|
444
|
#region Jis parser
|
445
|
|
446
|
#region Parse days
|
447
|
[TestMethod]
|
448
|
public void ParseJisDayOne()
|
449
|
{
|
450
|
TagInfo.CreateDictionaries();
|
451
|
|
452
|
string path = "";
|
453
|
List<JisInstance> data = new List<JisInstance>();
|
454
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
455
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
|
456
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
457
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
458
|
|
459
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
460
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
461
|
|
462
|
JisParser target = new JisParser(dl.Object);
|
463
|
PrivateObject obj = new PrivateObject(target);
|
464
|
|
465
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
466
|
|
467
|
Assert.AreEqual(2, retVal.Count);
|
468
|
Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
469
|
Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
470
|
}
|
471
|
|
472
|
[TestMethod]
|
473
|
public void ParseJisDayOneFiltering()
|
474
|
{
|
475
|
TagInfo.CreateDictionaries();
|
476
|
|
477
|
string path = "";
|
478
|
List<JisInstance> data = new List<JisInstance>();
|
479
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
|
480
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
481
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
|
482
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
483
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
484
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 17, 0, 0), 2));
|
485
|
|
486
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
487
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
488
|
|
489
|
JisParser target = new JisParser(dl.Object);
|
490
|
PrivateObject obj = new PrivateObject(target);
|
491
|
|
492
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 16, 0, 0));
|
493
|
|
494
|
Assert.AreEqual(2, retVal.Count);
|
495
|
Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
496
|
Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
497
|
}
|
498
|
|
499
|
[TestMethod]
|
500
|
public void ParseJisDayTwo()
|
501
|
{
|
502
|
TagInfo.CreateDictionaries();
|
503
|
|
504
|
string path = "";
|
505
|
List<JisInstance> data = new List<JisInstance>();
|
506
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
507
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
|
508
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
509
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
510
|
|
511
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 2, 1, 8, 0, 0), 8));
|
512
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 2, 1, 12, 0, 0), 2));
|
513
|
data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 16, 0, 0), 1));
|
514
|
|
515
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
516
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
517
|
|
518
|
JisParser target = new JisParser(dl.Object);
|
519
|
PrivateObject obj = new PrivateObject(target);
|
520
|
|
521
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 2, 1, 16, 0, 0));
|
522
|
|
523
|
Assert.AreEqual(4, retVal.Count);
|
524
|
Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
525
|
Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
526
|
|
527
|
Assert.AreEqual(new ActivityInfo("MENZA", 10, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[2]);
|
528
|
Assert.AreEqual(new ActivityInfo("KARMA", 1, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[3]);
|
529
|
}
|
530
|
|
531
|
[TestMethod]
|
532
|
public void ParseJisDayTwoFiltering()
|
533
|
{
|
534
|
TagInfo.CreateDictionaries();
|
535
|
|
536
|
string path = "";
|
537
|
List<JisInstance> data = new List<JisInstance>();
|
538
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
|
539
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
540
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
|
541
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
542
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
543
|
|
544
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 2, 1, 8, 0, 0), 8));
|
545
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 2, 1, 12, 0, 0), 2));
|
546
|
data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 16, 0, 0), 1));
|
547
|
data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 17, 0, 0), 2));
|
548
|
|
549
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
550
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
551
|
|
552
|
JisParser target = new JisParser(dl.Object);
|
553
|
PrivateObject obj = new PrivateObject(target);
|
554
|
|
555
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 2, 1, 16, 0, 0));
|
556
|
|
557
|
Assert.AreEqual(4, retVal.Count);
|
558
|
Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
559
|
Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
560
|
|
561
|
Assert.AreEqual(new ActivityInfo("MENZA", 10, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[2]);
|
562
|
Assert.AreEqual(new ActivityInfo("KARMA", 1, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[3]);
|
563
|
}
|
564
|
|
565
|
|
566
|
[TestMethod]
|
567
|
public void ParseJisDayNone()
|
568
|
{
|
569
|
TagInfo.CreateDictionaries();
|
570
|
|
571
|
string path = "";
|
572
|
List<JisInstance> data = new List<JisInstance>();
|
573
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
574
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
|
575
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
576
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
577
|
|
578
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 2, 15, 0, 0), 2));
|
579
|
|
580
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
581
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
582
|
|
583
|
JisParser target = new JisParser(dl.Object);
|
584
|
PrivateObject obj = new PrivateObject(target);
|
585
|
|
586
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 3), new DateTime(2001, 1, 1));
|
587
|
|
588
|
Assert.AreEqual(0, retVal.Count);
|
589
|
}
|
590
|
#endregion
|
591
|
|
592
|
#region Parse hours
|
593
|
[TestMethod]
|
594
|
public void ParseJisHourlyOne()
|
595
|
{
|
596
|
TagInfo.CreateDictionaries();
|
597
|
|
598
|
string path = "";
|
599
|
List<JisInstance> data = new List<JisInstance>();
|
600
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
601
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
|
602
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
|
603
|
|
604
|
/*
|
605
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 5));
|
606
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
|
607
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
|
608
|
*/
|
609
|
|
610
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
611
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
612
|
|
613
|
JisParser target = new JisParser(dl.Object);
|
614
|
PrivateObject obj = new PrivateObject(target);
|
615
|
|
616
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
617
|
|
618
|
Assert.AreEqual(2, retVal.Count);
|
619
|
Assert.AreEqual(new ActivityInfo("MENZA", 2, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
|
620
|
Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[1]);
|
621
|
}
|
622
|
|
623
|
[TestMethod]
|
624
|
public void ParseJisDayHourlyMultiple()
|
625
|
{
|
626
|
TagInfo.CreateDictionaries();
|
627
|
|
628
|
string path = "";
|
629
|
List<JisInstance> data = new List<JisInstance>();
|
630
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
|
631
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
|
632
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
|
633
|
|
634
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 0, 0), 5));
|
635
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 10, 0), 1));
|
636
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 11, 20, 0), 2));
|
637
|
|
638
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
639
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
640
|
|
641
|
JisParser target = new JisParser(dl.Object);
|
642
|
PrivateObject obj = new PrivateObject(target);
|
643
|
|
644
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
645
|
|
646
|
Assert.AreEqual(4, retVal.Count);
|
647
|
Assert.AreEqual(new ActivityInfo("MENZA", 2, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
|
648
|
Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[1]);
|
649
|
Assert.AreEqual(new ActivityInfo("MENZA", 6, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[2]);
|
650
|
Assert.AreEqual(new ActivityInfo("KARMA", 2, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[3]);
|
651
|
}
|
652
|
|
653
|
[TestMethod]
|
654
|
public void ParseJisHourlyNone()
|
655
|
{
|
656
|
TagInfo.CreateDictionaries();
|
657
|
|
658
|
string path = "";
|
659
|
List<JisInstance> data = new List<JisInstance>();
|
660
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 3, 0, 0), 2));
|
661
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 4, 0, 0), 3));
|
662
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 5, 15, 0), 3));
|
663
|
|
664
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 19, 0, 0), 5));
|
665
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 19, 10, 0), 1));
|
666
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 19, 20, 0), 2));
|
667
|
|
668
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
669
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
670
|
|
671
|
JisParser target = new JisParser(dl.Object);
|
672
|
PrivateObject obj = new PrivateObject(target);
|
673
|
|
674
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
675
|
|
676
|
Assert.AreEqual(0, retVal.Count);
|
677
|
}
|
678
|
|
679
|
[TestMethod]
|
680
|
public void ParseJisHourlyFiltering()
|
681
|
{
|
682
|
TagInfo.CreateDictionaries();
|
683
|
|
684
|
string path = "";
|
685
|
List<JisInstance> data = new List<JisInstance>();
|
686
|
data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
|
687
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
|
688
|
data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
|
689
|
|
690
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 0, 0), 5));
|
691
|
data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 18, 10, 0), 1));
|
692
|
data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 19, 20, 0), 2));
|
693
|
|
694
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
695
|
dl.Setup(m => m.LoadJisFile(path)).Returns(data);
|
696
|
|
697
|
JisParser target = new JisParser(dl.Object);
|
698
|
PrivateObject obj = new PrivateObject(target);
|
699
|
|
700
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
701
|
|
702
|
Assert.AreEqual(3, retVal.Count);
|
703
|
Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
|
704
|
Assert.AreEqual(new ActivityInfo("MENZA", 5, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[1]);
|
705
|
Assert.AreEqual(new ActivityInfo("MENZA", 1, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[2]);
|
706
|
}
|
707
|
#endregion
|
708
|
|
709
|
#endregion
|
710
|
|
711
|
// -------------------------------- LOGIN PARSER ----------------------------------------
|
712
|
|
713
|
#region Login parser
|
714
|
|
715
|
#region Parse days
|
716
|
[TestMethod]
|
717
|
public void ParseLoginDayOne()
|
718
|
{
|
719
|
TagInfo.CreateDictionaries();
|
720
|
|
721
|
string path = "";
|
722
|
List<LogInInstance> data = new List<LogInInstance>();
|
723
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
724
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
725
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
|
726
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
727
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
|
728
|
|
729
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
730
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
731
|
|
732
|
LogInParser target = new LogInParser(dl.Object);
|
733
|
PrivateObject obj = new PrivateObject(target);
|
734
|
|
735
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
736
|
|
737
|
Assert.AreEqual(2, retVal.Count);
|
738
|
Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
739
|
Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
740
|
}
|
741
|
|
742
|
[TestMethod]
|
743
|
public void ParseLoginDayOneFiltering()
|
744
|
{
|
745
|
TagInfo.CreateDictionaries();
|
746
|
|
747
|
string path = "";
|
748
|
List<LogInInstance> data = new List<LogInInstance>();
|
749
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
750
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 6, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
751
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
752
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
|
753
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
754
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
|
755
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
|
756
|
|
757
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
758
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
759
|
|
760
|
LogInParser target = new LogInParser(dl.Object);
|
761
|
PrivateObject obj = new PrivateObject(target);
|
762
|
|
763
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 16, 0, 0));
|
764
|
|
765
|
Assert.AreEqual(2, retVal.Count);
|
766
|
Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
767
|
Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
768
|
}
|
769
|
|
770
|
[TestMethod]
|
771
|
public void ParseLoginDayTwo()
|
772
|
{
|
773
|
TagInfo.CreateDictionaries();
|
774
|
|
775
|
string path = "";
|
776
|
List<LogInInstance> data = new List<LogInInstance>();
|
777
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
778
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
779
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
|
780
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
781
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
|
782
|
|
783
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
784
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
|
785
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
786
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
787
|
|
788
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
789
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
790
|
|
791
|
LogInParser target = new LogInParser(dl.Object);
|
792
|
PrivateObject obj = new PrivateObject(target);
|
793
|
|
794
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
|
795
|
|
796
|
Assert.AreEqual(4, retVal.Count);
|
797
|
Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
798
|
Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
799
|
|
800
|
Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
|
801
|
Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
|
802
|
}
|
803
|
|
804
|
[TestMethod]
|
805
|
public void ParseLoginDayTwoFiltering()
|
806
|
{
|
807
|
TagInfo.CreateDictionaries();
|
808
|
|
809
|
string path = "";
|
810
|
List<LogInInstance> data = new List<LogInInstance>();
|
811
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
812
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
813
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
814
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
|
815
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
816
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
|
817
|
|
818
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 6, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
819
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
820
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
|
821
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
822
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
823
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 19, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
824
|
|
825
|
data.Add(new LogInInstance(new DateTime(2000, 1, 3, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
826
|
data.Add(new LogInInstance(new DateTime(2000, 1, 3, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
827
|
|
828
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
829
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
830
|
|
831
|
LogInParser target = new LogInParser(dl.Object);
|
832
|
PrivateObject obj = new PrivateObject(target);
|
833
|
|
834
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
|
835
|
|
836
|
Assert.AreEqual(4, retVal.Count);
|
837
|
Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
|
838
|
Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
|
839
|
|
840
|
Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
|
841
|
Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
|
842
|
}
|
843
|
|
844
|
|
845
|
[TestMethod]
|
846
|
public void ParseLoginDayNone()
|
847
|
{
|
848
|
TagInfo.CreateDictionaries();
|
849
|
|
850
|
string path = "";
|
851
|
List<LogInInstance> data = new List<LogInInstance>();
|
852
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
853
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
854
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
|
855
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
856
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
|
857
|
|
858
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
859
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
|
860
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
861
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
|
862
|
|
863
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
864
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
865
|
|
866
|
LogInParser target = new LogInParser(dl.Object);
|
867
|
PrivateObject obj = new PrivateObject(target);
|
868
|
|
869
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 9, 0, 0));
|
870
|
|
871
|
Assert.AreEqual(0, retVal.Count);
|
872
|
}
|
873
|
#endregion
|
874
|
|
875
|
#region Parse hours
|
876
|
[TestMethod]
|
877
|
public void ParseLoginHourlyOne()
|
878
|
{
|
879
|
TagInfo.CreateDictionaries();
|
880
|
|
881
|
string path = "";
|
882
|
List<LogInInstance> data = new List<LogInInstance>();
|
883
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
884
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
885
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
|
886
|
|
887
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
888
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
|
889
|
|
890
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
891
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
892
|
|
893
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
894
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
895
|
|
896
|
LogInParser target = new LogInParser(dl.Object);
|
897
|
PrivateObject obj = new PrivateObject(target);
|
898
|
|
899
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
900
|
|
901
|
Assert.AreEqual(5, retVal.Count);
|
902
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
|
903
|
Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
|
904
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
|
905
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
|
906
|
Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[4]);
|
907
|
}
|
908
|
|
909
|
[TestMethod]
|
910
|
public void ParseLoginDayHourlyMultiple()
|
911
|
{
|
912
|
TagInfo.CreateDictionaries();
|
913
|
|
914
|
string path = "";
|
915
|
List<LogInInstance> data = new List<LogInInstance>();
|
916
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
917
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
918
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
|
919
|
|
920
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
921
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
|
922
|
|
923
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
924
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
925
|
|
926
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
927
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
928
|
|
929
|
LogInParser target = new LogInParser(dl.Object);
|
930
|
PrivateObject obj = new PrivateObject(target);
|
931
|
|
932
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
933
|
|
934
|
Assert.AreEqual(5, retVal.Count);
|
935
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
|
936
|
Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
|
937
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
|
938
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
|
939
|
Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
|
940
|
}
|
941
|
|
942
|
[TestMethod]
|
943
|
public void ParseLoginHourlyFiltering()
|
944
|
{
|
945
|
TagInfo.CreateDictionaries();
|
946
|
|
947
|
string path = "";
|
948
|
List<LogInInstance> data = new List<LogInInstance>();
|
949
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
950
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
951
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
952
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
|
953
|
|
954
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
955
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
|
956
|
|
957
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
958
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
959
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 19, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
960
|
|
961
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
962
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
963
|
|
964
|
LogInParser target = new LogInParser(dl.Object);
|
965
|
PrivateObject obj = new PrivateObject(target);
|
966
|
|
967
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
|
968
|
|
969
|
Assert.AreEqual(5, retVal.Count);
|
970
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
|
971
|
Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
|
972
|
Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
|
973
|
Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
|
974
|
Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
|
975
|
}
|
976
|
|
977
|
[TestMethod]
|
978
|
public void ParseLoginHourlyNone()
|
979
|
{
|
980
|
TagInfo.CreateDictionaries();
|
981
|
|
982
|
string path = "";
|
983
|
List<LogInInstance> data = new List<LogInInstance>();
|
984
|
// "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
|
985
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
986
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 9, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
|
987
|
|
988
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 19, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
989
|
data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 19, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
|
990
|
|
991
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
992
|
data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
|
993
|
|
994
|
Mock<IDataLoader> dl = new Mock<IDataLoader>();
|
995
|
dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
|
996
|
|
997
|
LogInParser target = new LogInParser(dl.Object);
|
998
|
PrivateObject obj = new PrivateObject(target);
|
999
|
|
1000
|
List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 1, 2, 10, 0, 0));
|
1001
|
|
1002
|
Assert.AreEqual(0, retVal.Count);
|
1003
|
}
|
1004
|
#endregion
|
1005
|
|
1006
|
#endregion
|
1007
|
|
1008
|
// -------------------------------- JSON PARSER -----------------------------------------
|
1009
|
|
1010
|
#region Json parser
|
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
|
|
1263
|
[TestMethod]
|
1264
|
public void JsonParserTestCurrent()
|
1265
|
{
|
1266
|
TagInfo.CreateDictionaries();
|
1267
|
|
1268
|
string data = SetBasicData();
|
1269
|
|
1270
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1271
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1272
|
|
1273
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1274
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1275
|
|
1276
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1277
|
|
1278
|
target.ParsePrediction();
|
1279
|
WeatherInfo current = target.Current;
|
1280
|
|
1281
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 13, 29, 0), 4, 0, 3.611, ValueToConditions.CloudCoverToConditions(100), 0), current);
|
1282
|
}
|
1283
|
|
1284
|
[TestMethod]
|
1285
|
public void JsonParserTestPrediction()
|
1286
|
{
|
1287
|
string data = SetBasicData();
|
1288
|
|
1289
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1290
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1291
|
|
1292
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1293
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1294
|
|
1295
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1296
|
|
1297
|
target.ParsePrediction();
|
1298
|
List<WeatherInfo> retVal = target.Predictions;
|
1299
|
|
1300
|
Assert.AreEqual(6, retVal.Count);
|
1301
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 0, 0, 0), 7, 87, 5.277, ValueToConditions.CloudCoverToConditions(92), 12), retVal[0]);
|
1302
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 25, 12, 0, 0), 8, 50, 2.77778, ValueToConditions.CloudCoverToConditions(60), 24), retVal[1]);
|
1303
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 12, 0, 0), 10, 0, 5.27778, ValueToConditions.CloudCoverToConditions(0), 9), retVal[2]);
|
1304
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 26, 21, 0, 0), 12, 80, 5.27778, ValueToConditions.CloudCoverToConditions(92), 21), retVal[3]);
|
1305
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 18, 0, 0), 17, 7, 2.5, ValueToConditions.CloudCoverToConditions(10), 3), retVal[4]);
|
1306
|
Assert.AreEqual(new WeatherInfo(new DateTime(2021, 5, 27, 21, 0, 0), 9, 87, 2.77778, WeatherConditions.Dark, 24), retVal[5]);
|
1307
|
}
|
1308
|
|
1309
|
[TestMethod]
|
1310
|
public void JsonParserEncompassSunRiseSetTimes()
|
1311
|
{
|
1312
|
string data = SetAstronomyData();
|
1313
|
|
1314
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1315
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1316
|
|
1317
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1318
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1319
|
|
1320
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1321
|
|
1322
|
target.ParsePrediction();
|
1323
|
List<WeatherInfo> retVal = target.Predictions;
|
1324
|
|
1325
|
Assert.AreEqual(8, retVal.Count);
|
1326
|
Assert.AreEqual(WeatherConditions.Dark, retVal[0].condition);
|
1327
|
Assert.AreEqual(WeatherConditions.Dark, retVal[1].condition);
|
1328
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[2].condition);
|
1329
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[3].condition);
|
1330
|
Assert.AreEqual(WeatherConditions.Dark, retVal[4].condition);
|
1331
|
Assert.AreEqual(WeatherConditions.Dark, retVal[5].condition);
|
1332
|
|
1333
|
Assert.AreNotEqual(WeatherConditions.Dark, retVal[6].condition);
|
1334
|
Assert.AreEqual(WeatherConditions.Dark, retVal[7].condition);
|
1335
|
}
|
1336
|
|
1337
|
#endregion
|
1338
|
|
1339
|
#region GetPredictionForTime
|
1340
|
[TestMethod]
|
1341
|
public void GetPredictionForTimeFilter()
|
1342
|
{
|
1343
|
string data = "";
|
1344
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1345
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1346
|
|
1347
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1348
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1349
|
|
1350
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1351
|
|
1352
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
1353
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1354
|
|
1355
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
1356
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
1357
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
1358
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1359
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
1360
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1361
|
|
1362
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
1363
|
|
1364
|
target.Predictions = pred;
|
1365
|
|
1366
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 3, 0, 0, 0));
|
1367
|
|
1368
|
Assert.AreEqual(6, retVal.Count);
|
1369
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
1370
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
1371
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[2]);
|
1372
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[3]);
|
1373
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15), retVal[4]);
|
1374
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[5]);
|
1375
|
}
|
1376
|
|
1377
|
[TestMethod]
|
1378
|
public void GetPredictionForTimeInvalidInput()
|
1379
|
{
|
1380
|
string data = "";
|
1381
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1382
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1383
|
|
1384
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1385
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1386
|
|
1387
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1388
|
|
1389
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
1390
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1391
|
|
1392
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
1393
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
1394
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
1395
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1396
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
1397
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1398
|
|
1399
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
1400
|
|
1401
|
target.Predictions = pred;
|
1402
|
|
1403
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 3, 0, 0, 0), new DateTime(2000, 1, 1, 6, 0, 0));
|
1404
|
Assert.AreEqual(null, retVal);
|
1405
|
}
|
1406
|
|
1407
|
[TestMethod]
|
1408
|
public void GetPredictionForTimeAllTo()
|
1409
|
{
|
1410
|
string data = "";
|
1411
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1412
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1413
|
|
1414
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1415
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1416
|
|
1417
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1418
|
|
1419
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
1420
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1421
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
1422
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
1423
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
1424
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1425
|
|
1426
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 9, 0, 0), 8, 1, 2, 60_000, 15));
|
1427
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1428
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 3, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
1429
|
|
1430
|
target.Predictions = pred;
|
1431
|
|
1432
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, new DateTime(2000, 1, 2, 6, 0, 0));
|
1433
|
|
1434
|
Assert.AreEqual(5, retVal.Count);
|
1435
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
1436
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
1437
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
1438
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
1439
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
1440
|
}
|
1441
|
|
1442
|
[TestMethod]
|
1443
|
public void GetPredictionForTimeAllFrom()
|
1444
|
{
|
1445
|
string data = "";
|
1446
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1447
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1448
|
|
1449
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1450
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1451
|
|
1452
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1453
|
|
1454
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
1455
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1456
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 3));
|
1457
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1458
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 8, 1, 2, 60_000, 3));
|
1459
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
1460
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
1461
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1462
|
|
1463
|
target.Predictions = pred;
|
1464
|
|
1465
|
List<WeatherInfo> retVal = target.GetPredictionForTime(new DateTime(2000, 1, 1, 12, 0, 0), DateTime.MaxValue);
|
1466
|
|
1467
|
Assert.AreEqual(3, retVal.Count);
|
1468
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[0]);
|
1469
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[1]);
|
1470
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[2]);
|
1471
|
}
|
1472
|
|
1473
|
public void GetPredictionForTimeAll()
|
1474
|
{
|
1475
|
|
1476
|
// TODO make an input file
|
1477
|
string data = "";
|
1478
|
Mock<DataDownloader> dl = new Mock<DataDownloader>("", "", "");
|
1479
|
dl.Setup(m => m.DownloadWeatherPrediction()).Returns("test");
|
1480
|
|
1481
|
Mock<IDataLoader> l = new Mock<IDataLoader>();
|
1482
|
l.Setup(m => m.LoadPredictionFile("test")).Returns(data);
|
1483
|
|
1484
|
JsonParser target = new JsonParser(dl.Object, l.Object);
|
1485
|
|
1486
|
List<WeatherInfo> pred = new List<WeatherInfo>();
|
1487
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3));
|
1488
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6));
|
1489
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6));
|
1490
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12));
|
1491
|
pred.Add(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3));
|
1492
|
|
1493
|
target.Predictions = pred;
|
1494
|
|
1495
|
List<WeatherInfo> retVal = target.GetPredictionForTime(DateTime.MinValue, DateTime.MaxValue);
|
1496
|
|
1497
|
Assert.AreEqual(5, retVal.Count);
|
1498
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 0, 0, 0), 8, 1, 2, 60_000, 3), retVal[0]);
|
1499
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 3, 0, 0), 8, 1, 2, 60_000, 6), retVal[1]);
|
1500
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 12, 0, 0), 8, 1, 2, 60_000, 6), retVal[2]);
|
1501
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 18, 0, 0), 8, 1, 2, 60_000, 12), retVal[3]);
|
1502
|
Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 2, 6, 0, 0), 8, 1, 2, 60_000, 3), retVal[4]);
|
1503
|
}
|
1504
|
#endregion
|
1505
|
|
1506
|
#endregion
|
1507
|
}
|
1508
|
}
|