1 |
cf35739b
|
Eliška Mourycová
|
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 |
|
|
}
|