commit cf35739b63afcc1d96e090673cf5a4616ffac19e
Author: Eliška Mourycová <eliska.mourycova@seznam.cz>
Date:   Sun Jun 6 10:34:53 2021 +0200

    Refs #9051, #9050. Added more tests + fixed some bugs revealed by the tests.

diff --git a/Server/ServerApp/DataDownload/Date.cs b/Server/ServerApp/DataDownload/Date.cs
index 3191bf9..82dde34 100644
--- a/Server/ServerApp/DataDownload/Date.cs
+++ b/Server/ServerApp/DataDownload/Date.cs
@@ -12,8 +12,8 @@ namespace ServerApp.DataDownload
 		public uint Year { get; }
 		public Date(uint month, uint year)
 		{
-			if (month == 0)
-				throw new ArgumentOutOfRangeException("month", "Month must be positive and not zero.");
+			if (month == 0 || month > 12)
+				throw new ArgumentOutOfRangeException("month", "Month must be positive and not zero and less or equal to 12.");
 			this.Month = month;
 			this.Year = year;
 		}
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index c5d629b..f81bd54 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -22,7 +22,7 @@ namespace ServerApp
 		public string DownloadedFilesNaming { get; set; }
 		public string DataRootDir { get; set; }
 		public string WeatherSite { get; set; }
-		public string Port { get; set; } // TODO port cannot be configurable?
+		public string Port { get; set; } 
 	}
 
     public class Program
diff --git a/Server/ServerApp/User/CommandsAcceptor.cs b/Server/ServerApp/User/CommandsAcceptor.cs
index 2cf180d..bf730f5 100644
--- a/Server/ServerApp/User/CommandsAcceptor.cs
+++ b/Server/ServerApp/User/CommandsAcceptor.cs
@@ -30,7 +30,7 @@ namespace ServerApp.User
 			while (true) {
 				Console.Write(">");
 				string command = Console.ReadLine();
-				if(command.Length > 0)
+				if(command != null && command.Length > 0)
 				{
 					Console.WriteLine("received admin command: " + command);
 					Command c = ParseString(command);
diff --git a/Server/ServerAppFunctionalTests/AdminCommandsTests/AdminDataCommandsTesting.cs b/Server/ServerAppFunctionalTests/AdminCommandsTests/AdminDataCommandsTesting.cs
new file mode 100644
index 0000000..abb96ee
--- /dev/null
+++ b/Server/ServerAppFunctionalTests/AdminCommandsTests/AdminDataCommandsTesting.cs
@@ -0,0 +1,36 @@
+﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
+using ServerApp.User;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ServerApp.DataDownload;
+
+namespace ServerAppFunctionalTests.AdminCommandsTests
+{
+	[TestClass]
+	public class AdminDataCommandsTesting
+	{
+		static CommandsAcceptor ca;
+
+		[ClassInitialize]
+		public static void SetUpClass(TestContext context)
+		{
+			DataDownloader dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1");
+			ca = new CommandsAcceptor(dd, null);
+			
+		}
+
+		[TestMethod]
+		public void Test()
+		{
+			StringReader stringReader = new StringReader("ahoj");
+			Console.SetIn(stringReader);
+			ca.AcceptCommand();
+
+		}
+
+	}
+}
diff --git a/Server/ServerAppFunctionalTests/DownloaderTests/DataDownloaderTesting.cs b/Server/ServerAppFunctionalTests/DownloaderTests/DataDownloaderTesting.cs
index cd3ef58..eed3160 100644
--- a/Server/ServerAppFunctionalTests/DownloaderTests/DataDownloaderTesting.cs
+++ b/Server/ServerAppFunctionalTests/DownloaderTests/DataDownloaderTesting.cs
@@ -16,7 +16,7 @@ namespace ServerAppFunctionalTests.DownloaderTests
 		[ClassInitialize]
 		public static void SetUpClass(TestContext context)
 		{
-			dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); ;
+			dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1");
 		}
 
 		[TestMethod]
@@ -32,7 +32,7 @@ namespace ServerAppFunctionalTests.DownloaderTests
 			bool jisDirExists = Directory.Exists(dd.DataSubDirectories[DataType.JIS]);
 			bool pcDirExists = Directory.Exists(dd.DataSubDirectories[DataType.STROJE]);
 			bool weatherDirExists = Directory.Exists(dd.DataSubDirectories[DataType.POCASI]);
-			// other sub dirs aren't that important
+			// other sub dirs aren't that important, because we don't use that data
 
 			bool allTrue = jisDirExists && pcDirExists && weatherDirExists;
 			Assert.IsTrue(allTrue);
@@ -71,31 +71,27 @@ namespace ServerAppFunctionalTests.DownloaderTests
 			Assert.AreEqual(2, files.Count);
 		}
 
-		[TestMethod]
-		public void DateCompare()
-		{
-
-		}
-
 		[TestMethod]
 		public void WeatherPredictionDownload()
 		{
 			string weatherJson = dd.DownloadWeatherPrediction();
+			bool weatherRelatedContent = weatherJson.Contains("FeelsLikeC");
 			Assert.IsNotNull(weatherJson);
+			Assert.IsTrue(weatherRelatedContent);
 		}
 
 
-		//[AssemblyCleanup]
-		//public static void AssemblyCleanup()
-		//{
-		//	try
-		//	{
-		//		Directory.Delete(dd.RootDataDirectory, true);
-		//	}
-		//	catch (DirectoryNotFoundException dnfe)
-		//	{
-
-		//	}
-		//}
+		[ClassCleanup]
+		public static void ClassCleanup()
+		{
+			try
+			{
+				Directory.Delete(dd.RootDataDirectory, true);
+			}
+			catch (DirectoryNotFoundException dnfe)
+			{
+
+			}
+		}
 	}
 }
diff --git a/Server/ServerAppFunctionalTests/DownloaderTests/DateTesting.cs b/Server/ServerAppFunctionalTests/DownloaderTests/DateTesting.cs
new file mode 100644
index 0000000..b572fa2
--- /dev/null
+++ b/Server/ServerAppFunctionalTests/DownloaderTests/DateTesting.cs
@@ -0,0 +1,125 @@
+﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
+using ServerApp.DataDownload;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ServerAppFunctionalTests.DownloaderTests
+{
+	[TestClass]
+	public class DateTesting
+	{
+		[TestMethod]
+		[ExpectedException(typeof(ArgumentOutOfRangeException))]
+		public void DateInvalidMonthZero()
+		{
+			Date d = new Date(0, 2019);
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(ArgumentOutOfRangeException))]
+		public void DateInvalidMonthOver12()
+		{
+			Date d = new Date(13, 2019);
+		}
+
+		[TestMethod]
+		public void DatesEqual()
+		{
+			Date d1 = new Date(2, 2019);
+			Date d2 = new Date(2, 2019);
+
+			bool datesEqual = d1.Equals(d2) && d2.Equals(d1);
+			Assert.IsTrue(datesEqual);
+		}
+
+		[TestMethod]
+		public void DatesNotEqual()
+		{
+			Date d1 = new Date(2, 2019);
+			Date d2 = new Date(3, 2019);
+
+			bool datesEqual = d1.Equals(d2) || d2.Equals(d1);
+			Assert.IsFalse(datesEqual);
+		}
+
+		[TestMethod]
+		public void DateSmaller()
+		{
+			Date d2_19 = new Date(2, 2019);
+			Date d3_19 = new Date(3, 2019);
+			Date d10_18 = new Date(10, 2018);
+			Date d1_20 = new Date(1, 2020);
+
+			bool smaller = 
+				d2_19 < d3_19 && 
+				d3_19 < d1_20 && 
+				d10_18 < d2_19;
+
+			Assert.IsTrue(smaller);
+		}
+
+		[TestMethod]
+		public void DateSmallerOrEqual()
+		{
+			Date d1 = new Date(8, 2017);
+			Date d2 = new Date(8, 2017);
+			Date d3 = new Date(12, 2017);
+
+			bool lessOrEqual = d1 <= d2 && d2 <= d3;
+
+			Assert.IsTrue(lessOrEqual);
+		}
+
+		[TestMethod]
+		public void DateGreater()
+		{
+			Date d2_19 = new Date(2, 2019);
+			Date d3_19 = new Date(3, 2019);
+			Date d10_18 = new Date(10, 2018);
+			Date d1_20 = new Date(1, 2020);
+
+			bool greater =
+				 d3_19 > d2_19 &&
+				d1_20 > d3_19 &&
+				d2_19 > d10_18;
+
+			Assert.IsTrue(greater);
+		}
+
+		[TestMethod]
+		public void DateGreaterOrEqual()
+		{
+			Date d1 = new Date(8, 2017);
+			Date d2 = new Date(8, 2017);
+			Date d3 = new Date(12, 2017);
+
+			bool greaterOrEqual = d1 >= d2 && d3 >= d2;
+
+			Assert.IsTrue(greaterOrEqual);
+		}
+
+		[TestMethod]
+		public void MonthIncreased()
+		{
+			Date d = new Date(3, 2010);
+			Date dIncreased = d.IncreaseMonthByOne();
+
+			Assert.AreEqual((uint)4, dIncreased.Month);
+			Assert.AreEqual((uint)2010, dIncreased.Year);
+		}
+
+		[TestMethod]
+		public void MonthIncreasedYrBreak()
+		{
+			Date d = new Date(12, 2010);
+			Date dIncreased = d.IncreaseMonthByOne();
+
+			Assert.AreEqual((uint)1, dIncreased.Month);
+			Assert.AreEqual((uint)2011, dIncreased.Year);
+		}
+
+	}
+}
diff --git a/Server/ServerAppFunctionalTests/XMLComTests/XMLComProtocolTesting.cs b/Server/ServerAppFunctionalTests/XMLComTests/XMLComProtocolTesting.cs
new file mode 100644
index 0000000..981645c
--- /dev/null
+++ b/Server/ServerAppFunctionalTests/XMLComTests/XMLComProtocolTesting.cs
@@ -0,0 +1,74 @@
+﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
+using ServerApp.Connection.XMLProtocolHandler;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ServerAppFunctionalTests.XMLComTests
+{
+	[TestClass]
+	public class XMLComProtocolTesting
+	{
+
+		[TestMethod]
+		public void XMLSerializeRequest()
+		{
+			Request request = Request.Randomize();
+			var xml = XmlCommunication.Serialize(request);
+			Assert.IsNotNull(xml);
+		}
+
+		[TestMethod]
+		public void XMLSerializeResponse()
+		{
+			Response response = Response.Randomize();
+			var xml = XmlCommunication.Serialize(response);
+			Assert.IsNotNull(xml);
+		}
+
+		[TestMethod]
+		public void XMLDeserializeRequest()
+		{
+			Request request = Request.Randomize();
+			var xml = XmlCommunication.Serialize(request);
+
+			Request requestDeserialized = XmlCommunication.Deserialize<Request>(xml);
+			Assert.IsNotNull(requestDeserialized);
+			Assert.AreEqual(request.rain, requestDeserialized.rain);
+			Assert.AreEqual(request.temperature, requestDeserialized.temperature);
+		}
+
+		[TestMethod]
+		public void XMLDeserializeResponse()
+		{
+			Response response = Response.Randomize();
+			var xml = XmlCommunication.Serialize(response);
+
+			Response responseDeserialized = XmlCommunication.Deserialize<Response>(xml);
+			Assert.IsNotNull(responseDeserialized);
+			Assert.AreEqual(response.hoursPerSegment, responseDeserialized.hoursPerSegment);
+			Assert.AreEqual(response.predicitons[0].dateTime.day, responseDeserialized.predicitons[0].dateTime.day);
+			Assert.AreEqual(response.predicitons[0].dateTime.month, responseDeserialized.predicitons[0].dateTime.month);
+			Assert.AreEqual(response.predicitons[0].dateTime.year, responseDeserialized.predicitons[0].dateTime.year);
+			Assert.AreEqual(response.predicitons[0].dateTime.hour, responseDeserialized.predicitons[0].dateTime.hour);
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(InvalidOperationException))]
+		public void XMLDeserializeRequestWrongFormat()
+		{
+			string xmlRequest = "not a request xml";
+			Request requestDeserialized = XmlCommunication.Deserialize<Request>(xmlRequest);
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(InvalidOperationException))]
+		public void XMLDeserializeResponseWrongFormat()
+		{
+			string xmlResponse = "not a response xml";
+			Response responseDeserialized = XmlCommunication.Deserialize<Response>(xmlResponse);
+		}
+	}
+}
