Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8a243ab2

Přidáno uživatelem Alex Konig před více než 3 roky(ů)

re #8962 Fixing bugs in JsonParser.EncompassSunriseSetTimes

Zobrazit rozdíly:

Server/ServerApp/WeatherPredictionParser/JsonParser.cs
189 189
            {
190 190
                WeatherInfo w = Predictions[i];
191 191
                WeatherInfo wNext = Predictions[i + 1];
192
                DateTime sunrise = sunriseTime[index];
193
                DateTime sunset = sunsetTime[index];
194

  
192 195

  
193 196
                // if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan
194 197
                int timespan = wNext.startTime.Hour - w.startTime.Hour;
198
                bool intoTwo = false;
195 199
                if (wNext.startTime.Hour < w.startTime.Hour)
196 200
                {
201
                    intoTwo = true;
197 202
                    timespan = (wNext.startTime.Hour + 24) - w.startTime.Hour;
198 203
                }
199 204
                
200 205
                w.intervalLength = timespan;
206
                TimeSpan endTime = new TimeSpan(w.startTime.TimeOfDay.Hours + timespan, w.startTime.TimeOfDay.Minutes, 0);
201 207

  
202 208
                // if start under sunset
203 209
                if (w.startTime.TimeOfDay > sunsetTime[index].TimeOfDay)
204
                    w.condition = WeatherConditions.Dark;
210
                {
211
                    // when is end - if end after next sunrise need to compute the extent of dark
212
                    if (intoTwo && endTime > sunriseTime[index+1].TimeOfDay)
213
                    {
214
                        double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunriseTime[index + 1].Hour * 60 + sunriseTime[index + 1].Minute)) / 60.0;
215
                        howMuch = w.intervalLength - howMuch;
216

  
217
                        if (howMuch >= timespan / 2.0)
218
                            w.condition = WeatherConditions.Dark;
219
                    }
220
                    else
221
                        w.condition = WeatherConditions.Dark;
222
                }
205 223

  
206 224
                // if start under sunrise
207 225
                if (w.startTime.TimeOfDay < sunriseTime[index].TimeOfDay)
208 226
                {
209 227
                    double howMuch = ((sunriseTime[index].Hour * 60 + sunriseTime[index].Minute) - (w.startTime.Hour * 60 + w.startTime.Minute)) / 60.0;
228
                    if (endTime > sunset.TimeOfDay)
229
                        howMuch += ((w.startTime.Hour * 60 + w.startTime.Minute) - (sunset.Hour * 60 + sunset.Minute)) / 60.0;
210 230

  
211 231
                    if (howMuch >= timespan / 2.0)
212 232
                        w.condition = WeatherConditions.Dark;
213 233
                }
214 234

  
215
                // if start under sunrise
216
                TimeSpan endTime = new TimeSpan(w.startTime.TimeOfDay.Hours + timespan, w.startTime.TimeOfDay.Minutes, 0);
217
                if (endTime > sunsetTime[index].TimeOfDay)
235
                // if end over sunset
236
                else if (endTime > sunsetTime[index].TimeOfDay)
218 237
                {
219 238
                    double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunsetTime[index].Hour * 60 + sunsetTime[index].Minute)) / 60.0;
220 239

  
......
228 247

  
229 248
            // last prediction
230 249
            WeatherInfo wLast = Predictions[Predictions.Count - 1];
231
            TimeSpan endTimeW = new TimeSpan(24, 0, 0);
250
            TimeSpan endTimeW = new TimeSpan(23, 59, 59);
232 251
            int timespanLast = 24 - wLast.startTime.Hour;
233 252
            wLast.intervalLength = timespanLast;
234 253

  
......
240 259
            if (wLast.startTime.TimeOfDay < sunriseTime[sunriseTime.Count - 1].TimeOfDay)
241 260
            {
242 261
                double howMuch = ((sunriseTime[sunriseTime.Count - 1].Hour * 60 + sunriseTime[sunriseTime.Count - 1].Minute) - (wLast.startTime.Hour * 60 + wLast.startTime.Minute)) / 60.0;
262
                if (endTimeW > sunsetTime[sunriseTime.Count - 1].TimeOfDay)
263
                    howMuch += ((wLast.startTime.Hour * 60 + wLast.startTime.Minute) - (sunsetTime[sunriseTime.Count - 1].Hour * 60 + sunsetTime[sunriseTime.Count - 1].Minute)) / 60.0;
243 264

  
244 265
                if (howMuch >= timespanLast / 2.0)
245 266
                    wLast.condition = WeatherConditions.Dark;
Server/TestProject/ParserTests/JisParserTesting.cs
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

  
9
namespace TestProject.ParserTests
10
{
11
    /// <summary>
12
    /// Summary description for WeatherParserTesting
13
    /// </summary>
14
    [TestClass]
15
    public class JisParserTesting
16
    {
17

  
18

  
19
        #region Jis parser
20

  
21
        #region Parse days
22
        [TestMethod]
23
        public void ParseJisDayOne()
24
        {
25
            TagInfo.CreateDictionaries();
26

  
27
            string path = "";
28
            List<JisInstance> data = new List<JisInstance>();
29
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
30
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
31
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
32
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
33

  
34
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
35
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
36

  
37
            JisParser target = new JisParser(dl.Object);
38
            PrivateObject obj = new PrivateObject(target);
39

  
40
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
41

  
42
            Assert.AreEqual(2, retVal.Count);
43
            Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
44
            Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
45
        }
46

  
47
        [TestMethod]
48
        public void ParseJisDayOneFiltering()
49
        {
50
            TagInfo.CreateDictionaries();
51

  
52
            string path = "";
53
            List<JisInstance> data = new List<JisInstance>();
54
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
55
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
56
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
57
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
58
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
59
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 17, 0, 0), 2));
60

  
61
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
62
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
63

  
64
            JisParser target = new JisParser(dl.Object);
65
            PrivateObject obj = new PrivateObject(target);
66

  
67
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 16, 0, 0));
68

  
69
            Assert.AreEqual(2, retVal.Count);
70
            Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
71
            Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
72
        }
73

  
74
        [TestMethod]
75
        public void ParseJisDayTwo()
76
        {
77
            TagInfo.CreateDictionaries();
78

  
79
            string path = "";
80
            List<JisInstance> data = new List<JisInstance>();
81
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
82
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
83
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
84
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
85

  
86
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 2, 1, 8, 0, 0), 8));
87
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 2, 1, 12, 0, 0), 2));
88
            data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 16, 0, 0), 1));
89

  
90
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
91
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
92

  
93
            JisParser target = new JisParser(dl.Object);
94
            PrivateObject obj = new PrivateObject(target);
95

  
96
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 2, 1, 16, 0, 0));
97

  
98
            Assert.AreEqual(4, retVal.Count);
99
            Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
100
            Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
101

  
102
            Assert.AreEqual(new ActivityInfo("MENZA", 10, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[2]);
103
            Assert.AreEqual(new ActivityInfo("KARMA", 1, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[3]);
104
        }
105

  
106
        [TestMethod]
107
        public void ParseJisDayTwoFiltering()
108
        {
109
            TagInfo.CreateDictionaries();
110

  
111
            string path = "";
112
            List<JisInstance> data = new List<JisInstance>();
113
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
114
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
115
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
116
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
117
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
118

  
119
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 2, 1, 8, 0, 0), 8));
120
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 2, 1, 12, 0, 0), 2));
121
            data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 16, 0, 0), 1));
122
            data.Add(new JisInstance("A2", new DateTime(2000, 2, 1, 17, 0, 0), 2));
123

  
124
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
125
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
126

  
127
            JisParser target = new JisParser(dl.Object);
128
            PrivateObject obj = new PrivateObject(target);
129

  
130
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 2, 1, 16, 0, 0));
131

  
132
            Assert.AreEqual(4, retVal.Count);
133
            Assert.AreEqual(new ActivityInfo("MENZA", 3, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
134
            Assert.AreEqual(new ActivityInfo("KARMA", 5, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
135

  
136
            Assert.AreEqual(new ActivityInfo("MENZA", 10, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[2]);
137
            Assert.AreEqual(new ActivityInfo("KARMA", 1, new DateTime(2000, 2, 1, 7, 0, 0), 18 - 7), retVal[3]);
138
        }
139

  
140

  
141
        [TestMethod]
142
        public void ParseJisDayNone()
143
        {
144
            TagInfo.CreateDictionaries();
145

  
146
            string path = "";
147
            List<JisInstance> data = new List<JisInstance>();
148
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
149
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 10, 0, 0), 3));
150
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
151
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
152

  
153
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 2, 15, 0, 0), 2));
154

  
155
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
156
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
157

  
158
            JisParser target = new JisParser(dl.Object);
159
            PrivateObject obj = new PrivateObject(target);
160

  
161
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsDays", path, new DateTime(2000, 1, 3), new DateTime(2001, 1, 1));
162

  
163
            Assert.AreEqual(0, retVal.Count);
164
        }
165
        #endregion
166

  
167
        #region Parse hours
168
        [TestMethod]
169
        public void ParseJisHourlyOne()
170
        {
171
            TagInfo.CreateDictionaries();
172

  
173
            string path = "";
174
            List<JisInstance> data = new List<JisInstance>();
175
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
176
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
177
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
178

  
179
            /*
180
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 5));
181
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 12, 0, 0), 1));
182
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 15, 0, 0), 2));
183
            */
184

  
185
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
186
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
187

  
188
            JisParser target = new JisParser(dl.Object);
189
            PrivateObject obj = new PrivateObject(target);
190

  
191
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
192

  
193
            Assert.AreEqual(2, retVal.Count);
194
            Assert.AreEqual(new ActivityInfo("MENZA", 2, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
195
            Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[1]);
196
        }
197

  
198
        [TestMethod]
199
        public void ParseJisDayHourlyMultiple()
200
        {
201
            TagInfo.CreateDictionaries();
202

  
203
            string path = "";
204
            List<JisInstance> data = new List<JisInstance>();
205
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 7, 0, 0), 2));
206
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
207
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
208

  
209
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 0, 0), 5));
210
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 10, 0), 1));
211
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 11, 20, 0), 2));
212

  
213
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
214
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
215

  
216
            JisParser target = new JisParser(dl.Object);
217
            PrivateObject obj = new PrivateObject(target);
218

  
219
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
220

  
221
            Assert.AreEqual(4, retVal.Count);
222
            Assert.AreEqual(new ActivityInfo("MENZA", 2, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
223
            Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[1]);
224
            Assert.AreEqual(new ActivityInfo("MENZA", 6, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[2]);
225
            Assert.AreEqual(new ActivityInfo("KARMA", 2, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[3]);
226
        }
227

  
228
        [TestMethod]
229
        public void ParseJisHourlyNone()
230
        {
231
            TagInfo.CreateDictionaries();
232

  
233
            string path = "";
234
            List<JisInstance> data = new List<JisInstance>();
235
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 3, 0, 0), 2));
236
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 4, 0, 0), 3));
237
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 5, 15, 0), 3));
238

  
239
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 19, 0, 0), 5));
240
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 19, 10, 0), 1));
241
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 19, 20, 0), 2));
242

  
243
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
244
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
245

  
246
            JisParser target = new JisParser(dl.Object);
247
            PrivateObject obj = new PrivateObject(target);
248

  
249
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
250

  
251
            Assert.AreEqual(0, retVal.Count);
252
        }
253

  
254
        [TestMethod]
255
        public void ParseJisHourlyFiltering()
256
        {
257
            TagInfo.CreateDictionaries();
258

  
259
            string path = "";
260
            List<JisInstance> data = new List<JisInstance>();
261
            data.Add(new JisInstance("MenzaKL-vydej", new DateTime(2000, 1, 1, 6, 0, 0), 2));
262
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 0, 0), 3));
263
            data.Add(new JisInstance("A2-Hlavni vchod", new DateTime(2000, 1, 1, 8, 15, 0), 3));
264

  
265
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 11, 0, 0), 5));
266
            data.Add(new JisInstance("Menza4-kasa5", new DateTime(2000, 1, 1, 18, 10, 0), 1));
267
            data.Add(new JisInstance("A1", new DateTime(2000, 1, 1, 19, 20, 0), 2));
268

  
269
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
270
            dl.Setup(m => m.LoadJisFile(path)).Returns(data);
271

  
272
            JisParser target = new JisParser(dl.Object);
273
            PrivateObject obj = new PrivateObject(target);
274

  
275
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneJisFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
276

  
277
            Assert.AreEqual(3, retVal.Count);
278
            Assert.AreEqual(new ActivityInfo("KARMA", 6, new DateTime(2000, 1, 1, 7, 0, 0), 2), retVal[0]);
279
            Assert.AreEqual(new ActivityInfo("MENZA", 5, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[1]);
280
            Assert.AreEqual(new ActivityInfo("MENZA", 1, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[2]);
281
        }
282
        #endregion
283

  
284
        #endregion
285

  
286
    }
287
}
Server/TestProject/ParserTests/JsonParserTesting.cs
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.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
}
Server/TestProject/ParserTests/LoginParserTesting.cs
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

  
9
namespace TestProject.ParserTests
10
{
11
    /// <summary>
12
    /// Summary description for WeatherParserTesting
13
    /// </summary>
14
    [TestClass]
15
    public class LoginParserTesting
16
    {
17

  
18
        #region Login parser
19

  
20
        #region Parse days
21
        [TestMethod]
22
        public void ParseLoginDayOne()
23
        {
24
            TagInfo.CreateDictionaries();
25

  
26
            string path = "";
27
            List<LogInInstance> data = new List<LogInInstance>();
28
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
29
            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"));
30
            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"));
31
            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"));
32
            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"));
33

  
34
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
35
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
36

  
37
            LogInParser target = new LogInParser(dl.Object);
38
            PrivateObject obj = new PrivateObject(target);
39

  
40
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
41

  
42
            Assert.AreEqual(2, retVal.Count);
43
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
44
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
45
        }
46

  
47
        [TestMethod]
48
        public void ParseLoginDayOneFiltering()
49
        {
50
            TagInfo.CreateDictionaries();
51

  
52
            string path = "";
53
            List<LogInInstance> data = new List<LogInInstance>();
54
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
55
            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"));
56
            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"));
57
            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"));
58
            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"));
59
            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"));
60
            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"));
61

  
62
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
63
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
64

  
65
            LogInParser target = new LogInParser(dl.Object);
66
            PrivateObject obj = new PrivateObject(target);
67

  
68
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 16, 0, 0));
69

  
70
            Assert.AreEqual(2, retVal.Count);
71
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
72
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
73
        }
74

  
75
        [TestMethod]
76
        public void ParseLoginDayTwo()
77
        {
78
            TagInfo.CreateDictionaries();
79

  
80
            string path = "";
81
            List<LogInInstance> data = new List<LogInInstance>();
82
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
83
            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"));
84
            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"));
85
            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"));
86
            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"));
87

  
88
            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"));
89
            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"));
90
            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"));
91
            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"));
92

  
93
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
94
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
95

  
96
            LogInParser target = new LogInParser(dl.Object);
97
            PrivateObject obj = new PrivateObject(target);
98

  
99
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
100

  
101
            Assert.AreEqual(4, retVal.Count);
102
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
103
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
104

  
105
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
106
            Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
107
        }
108

  
109
        [TestMethod]
110
        public void ParseLoginDayTwoFiltering()
111
        {
112
            TagInfo.CreateDictionaries();
113

  
114
            string path = "";
115
            List<LogInInstance> data = new List<LogInInstance>();
116
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
117
            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"));
118
            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"));
119
            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"));
120
            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"));
121
            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"));
122

  
123
            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"));
124
            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"));
125
            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"));
126
            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"));
127
            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"));
128
            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"));
129

  
130
            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"));
131
            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"));
132

  
133
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
134
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
135

  
136
            LogInParser target = new LogInParser(dl.Object);
137
            PrivateObject obj = new PrivateObject(target);
138

  
139
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
140

  
141
            Assert.AreEqual(4, retVal.Count);
142
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
143
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
144

  
145
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
146
            Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
147
        }
148

  
149

  
150
        [TestMethod]
151
        public void ParseLoginDayNone()
152
        {
153
            TagInfo.CreateDictionaries();
154

  
155
            string path = "";
156
            List<LogInInstance> data = new List<LogInInstance>();
157
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
158
            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"));
159
            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"));
160
            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"));
161
            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"));
162

  
163
            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"));
164
            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"));
165
            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"));
166
            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"));
167

  
168
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
169
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
170

  
171
            LogInParser target = new LogInParser(dl.Object);
172
            PrivateObject obj = new PrivateObject(target);
173

  
174
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 9, 0, 0));
175

  
176
            Assert.AreEqual(0, retVal.Count);
177
        }
178
        #endregion
179

  
180
        #region Parse hours
181
        [TestMethod]
182
        public void ParseLoginHourlyOne()
183
        {
184
            TagInfo.CreateDictionaries();
185

  
186
            string path = "";
187
            List<LogInInstance> data = new List<LogInInstance>();
188
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
189
            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"));
190
            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"));
191

  
192
            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"));
193
            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"));
194

  
195
            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"));
196
            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"));
197

  
198
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
199
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
200

  
201
            LogInParser target = new LogInParser(dl.Object);
202
            PrivateObject obj = new PrivateObject(target);
203

  
204
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
205

  
206
            Assert.AreEqual(5, retVal.Count);
207
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
208
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
209
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
210
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
211
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[4]);
212
        }
213

  
214
        [TestMethod]
215
        public void ParseLoginDayHourlyMultiple()
216
        {
217
            TagInfo.CreateDictionaries();
218

  
219
            string path = "";
220
            List<LogInInstance> data = new List<LogInInstance>();
221
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
222
            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"));
223
            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"));
224

  
225
            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"));
226
            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"));
227

  
228
            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"));
229
            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"));
230

  
231
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
232
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
233

  
234
            LogInParser target = new LogInParser(dl.Object);
235
            PrivateObject obj = new PrivateObject(target);
236

  
237
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
238

  
239
            Assert.AreEqual(5, retVal.Count);
240
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
241
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
242
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
243
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
244
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
245
        }
246

  
247
        [TestMethod]
248
        public void ParseLoginHourlyFiltering()
249
        {
250
            TagInfo.CreateDictionaries();
251

  
252
            string path = "";
253
            List<LogInInstance> data = new List<LogInInstance>();
254
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
255
            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"));
256
            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"));
257
            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"));
258

  
259
            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"));
260
            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"));
261

  
262
            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"));
263
            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"));
264
            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"));
265

  
266
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
267
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
268

  
269
            LogInParser target = new LogInParser(dl.Object);
270
            PrivateObject obj = new PrivateObject(target);
271

  
272
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
273

  
274
            Assert.AreEqual(5, retVal.Count);
275
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
276
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
277
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
278
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
279
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
280
        }
281

  
282
        [TestMethod]
283
        public void ParseLoginHourlyNone()
284
        {
285
            TagInfo.CreateDictionaries();
286

  
287
            string path = "";
288
            List<LogInInstance> data = new List<LogInInstance>();
289
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
290
            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"));
291
            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"));
292

  
293
            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"));
294
            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"));
295

  
296
            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"));
297
            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"));
298

  
299
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
300
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
301

  
302
            LogInParser target = new LogInParser(dl.Object);
303
            PrivateObject obj = new PrivateObject(target);
304

  
305
            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));
306

  
307
            Assert.AreEqual(0, retVal.Count);
308
        }
309
        #endregion
310

  
311
        #endregion
312

  
313
    }
314
}
Server/TestProject/ParserTests/TestingParser.cs
3 3
using ServerApp.Parser.Parsers;
4 4
using System.Collections.Generic;
5 5
using ServerApp.Parser.OutputInfo;
6
using Moq;
7
using ServerApp.Parser.InputData;
8
using ServerApp.WeatherPredictionParser;
9
using ServerApp.DataDownload;
10 6

  
11
namespace TestProject
7
namespace TestProject.ParserTests
12 8
{
13 9

  
14 10
    [TestClass]
......
181 177
        }
182 178
        #endregion
183 179

  
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

  
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff