Revize cf35739b
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
Server/ServerApp/DataDownload/Date.cs | ||
---|---|---|
12 | 12 |
public uint Year { get; } |
13 | 13 |
public Date(uint month, uint year) |
14 | 14 |
{ |
15 |
if (month == 0) |
|
16 |
throw new ArgumentOutOfRangeException("month", "Month must be positive and not zero."); |
|
15 |
if (month == 0 || month > 12)
|
|
16 |
throw new ArgumentOutOfRangeException("month", "Month must be positive and not zero and less or equal to 12.");
|
|
17 | 17 |
this.Month = month; |
18 | 18 |
this.Year = year; |
19 | 19 |
} |
Server/ServerApp/Program.cs | ||
---|---|---|
22 | 22 |
public string DownloadedFilesNaming { get; set; } |
23 | 23 |
public string DataRootDir { get; set; } |
24 | 24 |
public string WeatherSite { get; set; } |
25 |
public string Port { get; set; } // TODO port cannot be configurable?
|
|
25 |
public string Port { get; set; } |
|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
public class Program |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
30 | 30 |
while (true) { |
31 | 31 |
Console.Write(">"); |
32 | 32 |
string command = Console.ReadLine(); |
33 |
if(command.Length > 0) |
|
33 |
if(command != null && command.Length > 0)
|
|
34 | 34 |
{ |
35 | 35 |
Console.WriteLine("received admin command: " + command); |
36 | 36 |
Command c = ParseString(command); |
Server/ServerAppFunctionalTests/AdminCommandsTests/AdminDataCommandsTesting.cs | ||
---|---|---|
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
2 |
using ServerApp.User; |
|
3 |
using System; |
|
4 |
using System.Collections.Generic; |
|
5 |
using System.IO; |
|
6 |
using System.Linq; |
|
7 |
using System.Text; |
|
8 |
using System.Threading.Tasks; |
|
9 |
using ServerApp.DataDownload; |
|
10 |
|
|
11 |
namespace ServerAppFunctionalTests.AdminCommandsTests |
|
12 |
{ |
|
13 |
[TestClass] |
|
14 |
public class AdminDataCommandsTesting |
|
15 |
{ |
|
16 |
static CommandsAcceptor ca; |
|
17 |
|
|
18 |
[ClassInitialize] |
|
19 |
public static void SetUpClass(TestContext context) |
|
20 |
{ |
|
21 |
DataDownloader dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); |
|
22 |
ca = new CommandsAcceptor(dd, null); |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
[TestMethod] |
|
27 |
public void Test() |
|
28 |
{ |
|
29 |
StringReader stringReader = new StringReader("ahoj"); |
|
30 |
Console.SetIn(stringReader); |
|
31 |
ca.AcceptCommand(); |
|
32 |
|
|
33 |
} |
|
34 |
|
|
35 |
} |
|
36 |
} |
Server/ServerAppFunctionalTests/DownloaderTests/DataDownloaderTesting.cs | ||
---|---|---|
16 | 16 |
[ClassInitialize] |
17 | 17 |
public static void SetUpClass(TestContext context) |
18 | 18 |
{ |
19 |
dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); ;
|
|
19 |
dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); |
|
20 | 20 |
} |
21 | 21 |
|
22 | 22 |
[TestMethod] |
... | ... | |
32 | 32 |
bool jisDirExists = Directory.Exists(dd.DataSubDirectories[DataType.JIS]); |
33 | 33 |
bool pcDirExists = Directory.Exists(dd.DataSubDirectories[DataType.STROJE]); |
34 | 34 |
bool weatherDirExists = Directory.Exists(dd.DataSubDirectories[DataType.POCASI]); |
35 |
// other sub dirs aren't that important |
|
35 |
// other sub dirs aren't that important, because we don't use that data
|
|
36 | 36 |
|
37 | 37 |
bool allTrue = jisDirExists && pcDirExists && weatherDirExists; |
38 | 38 |
Assert.IsTrue(allTrue); |
... | ... | |
71 | 71 |
Assert.AreEqual(2, files.Count); |
72 | 72 |
} |
73 | 73 |
|
74 |
[TestMethod] |
|
75 |
public void DateCompare() |
|
76 |
{ |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 | 74 |
[TestMethod] |
81 | 75 |
public void WeatherPredictionDownload() |
82 | 76 |
{ |
83 | 77 |
string weatherJson = dd.DownloadWeatherPrediction(); |
78 |
bool weatherRelatedContent = weatherJson.Contains("FeelsLikeC"); |
|
84 | 79 |
Assert.IsNotNull(weatherJson); |
80 |
Assert.IsTrue(weatherRelatedContent); |
|
85 | 81 |
} |
86 | 82 |
|
87 | 83 |
|
88 |
//[AssemblyCleanup]
|
|
89 |
//public static void AssemblyCleanup()
|
|
90 |
//{
|
|
91 |
// try
|
|
92 |
// {
|
|
93 |
// Directory.Delete(dd.RootDataDirectory, true);
|
|
94 |
// }
|
|
95 |
// catch (DirectoryNotFoundException dnfe)
|
|
96 |
// {
|
|
97 |
|
|
98 |
// }
|
|
99 |
//}
|
|
84 |
[ClassCleanup]
|
|
85 |
public static void ClassCleanup()
|
|
86 |
{ |
|
87 |
try |
|
88 |
{ |
|
89 |
Directory.Delete(dd.RootDataDirectory, true); |
|
90 |
} |
|
91 |
catch (DirectoryNotFoundException dnfe) |
|
92 |
{ |
|
93 |
|
|
94 |
} |
|
95 |
} |
|
100 | 96 |
} |
101 | 97 |
} |
Server/ServerAppFunctionalTests/DownloaderTests/DateTesting.cs | ||
---|---|---|
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
2 |
using ServerApp.DataDownload; |
|
3 |
using System; |
|
4 |
using System.Collections.Generic; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
using System.Threading.Tasks; |
|
8 |
|
|
9 |
namespace ServerAppFunctionalTests.DownloaderTests |
|
10 |
{ |
|
11 |
[TestClass] |
|
12 |
public class DateTesting |
|
13 |
{ |
|
14 |
[TestMethod] |
|
15 |
[ExpectedException(typeof(ArgumentOutOfRangeException))] |
|
16 |
public void DateInvalidMonthZero() |
|
17 |
{ |
|
18 |
Date d = new Date(0, 2019); |
|
19 |
} |
|
20 |
|
|
21 |
[TestMethod] |
|
22 |
[ExpectedException(typeof(ArgumentOutOfRangeException))] |
|
23 |
public void DateInvalidMonthOver12() |
|
24 |
{ |
|
25 |
Date d = new Date(13, 2019); |
|
26 |
} |
|
27 |
|
|
28 |
[TestMethod] |
|
29 |
public void DatesEqual() |
|
30 |
{ |
|
31 |
Date d1 = new Date(2, 2019); |
|
32 |
Date d2 = new Date(2, 2019); |
|
33 |
|
|
34 |
bool datesEqual = d1.Equals(d2) && d2.Equals(d1); |
|
35 |
Assert.IsTrue(datesEqual); |
|
36 |
} |
|
37 |
|
|
38 |
[TestMethod] |
|
39 |
public void DatesNotEqual() |
|
40 |
{ |
|
41 |
Date d1 = new Date(2, 2019); |
|
42 |
Date d2 = new Date(3, 2019); |
|
43 |
|
|
44 |
bool datesEqual = d1.Equals(d2) || d2.Equals(d1); |
|
45 |
Assert.IsFalse(datesEqual); |
|
46 |
} |
|
47 |
|
|
48 |
[TestMethod] |
|
49 |
public void DateSmaller() |
|
50 |
{ |
|
51 |
Date d2_19 = new Date(2, 2019); |
|
52 |
Date d3_19 = new Date(3, 2019); |
|
53 |
Date d10_18 = new Date(10, 2018); |
|
54 |
Date d1_20 = new Date(1, 2020); |
|
55 |
|
|
56 |
bool smaller = |
|
57 |
d2_19 < d3_19 && |
|
58 |
d3_19 < d1_20 && |
|
59 |
d10_18 < d2_19; |
|
60 |
|
|
61 |
Assert.IsTrue(smaller); |
|
62 |
} |
|
63 |
|
|
64 |
[TestMethod] |
|
65 |
public void DateSmallerOrEqual() |
|
66 |
{ |
|
67 |
Date d1 = new Date(8, 2017); |
|
68 |
Date d2 = new Date(8, 2017); |
|
69 |
Date d3 = new Date(12, 2017); |
|
70 |
|
|
71 |
bool lessOrEqual = d1 <= d2 && d2 <= d3; |
|
72 |
|
|
73 |
Assert.IsTrue(lessOrEqual); |
|
74 |
} |
|
75 |
|
|
76 |
[TestMethod] |
|
77 |
public void DateGreater() |
|
78 |
{ |
|
79 |
Date d2_19 = new Date(2, 2019); |
|
80 |
Date d3_19 = new Date(3, 2019); |
|
81 |
Date d10_18 = new Date(10, 2018); |
|
82 |
Date d1_20 = new Date(1, 2020); |
|
83 |
|
|
84 |
bool greater = |
|
85 |
d3_19 > d2_19 && |
|
86 |
d1_20 > d3_19 && |
|
87 |
d2_19 > d10_18; |
|
88 |
|
|
89 |
Assert.IsTrue(greater); |
|
90 |
} |
|
91 |
|
|
92 |
[TestMethod] |
|
93 |
public void DateGreaterOrEqual() |
|
94 |
{ |
|
95 |
Date d1 = new Date(8, 2017); |
|
96 |
Date d2 = new Date(8, 2017); |
|
97 |
Date d3 = new Date(12, 2017); |
|
98 |
|
|
99 |
bool greaterOrEqual = d1 >= d2 && d3 >= d2; |
|
100 |
|
|
101 |
Assert.IsTrue(greaterOrEqual); |
|
102 |
} |
|
103 |
|
|
104 |
[TestMethod] |
|
105 |
public void MonthIncreased() |
|
106 |
{ |
|
107 |
Date d = new Date(3, 2010); |
|
108 |
Date dIncreased = d.IncreaseMonthByOne(); |
|
109 |
|
|
110 |
Assert.AreEqual((uint)4, dIncreased.Month); |
|
111 |
Assert.AreEqual((uint)2010, dIncreased.Year); |
|
112 |
} |
|
113 |
|
|
114 |
[TestMethod] |
|
115 |
public void MonthIncreasedYrBreak() |
|
116 |
{ |
|
117 |
Date d = new Date(12, 2010); |
|
118 |
Date dIncreased = d.IncreaseMonthByOne(); |
|
119 |
|
|
120 |
Assert.AreEqual((uint)1, dIncreased.Month); |
|
121 |
Assert.AreEqual((uint)2011, dIncreased.Year); |
|
122 |
} |
|
123 |
|
|
124 |
} |
|
125 |
} |
Server/ServerAppFunctionalTests/XMLComTests/XMLComProtocolTesting.cs | ||
---|---|---|
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
2 |
using ServerApp.Connection.XMLProtocolHandler; |
|
3 |
using System; |
|
4 |
using System.Collections.Generic; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
using System.Threading.Tasks; |
|
8 |
|
|
9 |
namespace ServerAppFunctionalTests.XMLComTests |
|
10 |
{ |
|
11 |
[TestClass] |
|
12 |
public class XMLComProtocolTesting |
|
13 |
{ |
|
14 |
|
|
15 |
[TestMethod] |
|
16 |
public void XMLSerializeRequest() |
|
17 |
{ |
|
18 |
Request request = Request.Randomize(); |
|
19 |
var xml = XmlCommunication.Serialize(request); |
|
20 |
Assert.IsNotNull(xml); |
|
21 |
} |
|
22 |
|
|
23 |
[TestMethod] |
|
24 |
public void XMLSerializeResponse() |
|
25 |
{ |
|
26 |
Response response = Response.Randomize(); |
|
27 |
var xml = XmlCommunication.Serialize(response); |
|
28 |
Assert.IsNotNull(xml); |
|
29 |
} |
|
30 |
|
|
31 |
[TestMethod] |
|
32 |
public void XMLDeserializeRequest() |
|
33 |
{ |
|
34 |
Request request = Request.Randomize(); |
|
35 |
var xml = XmlCommunication.Serialize(request); |
|
36 |
|
|
37 |
Request requestDeserialized = XmlCommunication.Deserialize<Request>(xml); |
|
38 |
Assert.IsNotNull(requestDeserialized); |
|
39 |
Assert.AreEqual(request.rain, requestDeserialized.rain); |
|
40 |
Assert.AreEqual(request.temperature, requestDeserialized.temperature); |
|
41 |
} |
|
42 |
|
|
43 |
[TestMethod] |
|
44 |
public void XMLDeserializeResponse() |
|
45 |
{ |
|
46 |
Response response = Response.Randomize(); |
|
47 |
var xml = XmlCommunication.Serialize(response); |
|
48 |
|
|
49 |
Response responseDeserialized = XmlCommunication.Deserialize<Response>(xml); |
|
50 |
Assert.IsNotNull(responseDeserialized); |
|
51 |
Assert.AreEqual(response.hoursPerSegment, responseDeserialized.hoursPerSegment); |
|
52 |
Assert.AreEqual(response.predicitons[0].dateTime.day, responseDeserialized.predicitons[0].dateTime.day); |
|
53 |
Assert.AreEqual(response.predicitons[0].dateTime.month, responseDeserialized.predicitons[0].dateTime.month); |
|
54 |
Assert.AreEqual(response.predicitons[0].dateTime.year, responseDeserialized.predicitons[0].dateTime.year); |
|
55 |
Assert.AreEqual(response.predicitons[0].dateTime.hour, responseDeserialized.predicitons[0].dateTime.hour); |
|
56 |
} |
|
57 |
|
|
58 |
[TestMethod] |
|
59 |
[ExpectedException(typeof(InvalidOperationException))] |
|
60 |
public void XMLDeserializeRequestWrongFormat() |
|
61 |
{ |
|
62 |
string xmlRequest = "not a request xml"; |
|
63 |
Request requestDeserialized = XmlCommunication.Deserialize<Request>(xmlRequest); |
|
64 |
} |
|
65 |
|
|
66 |
[TestMethod] |
|
67 |
[ExpectedException(typeof(InvalidOperationException))] |
|
68 |
public void XMLDeserializeResponseWrongFormat() |
|
69 |
{ |
|
70 |
string xmlResponse = "not a response xml"; |
|
71 |
Response responseDeserialized = XmlCommunication.Deserialize<Response>(xmlResponse); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
Také k dispozici: Unified diff
Refs #9051, #9050. Added more tests + fixed some bugs revealed by the tests.