-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestClientManager.cs
113 lines (85 loc) · 3.49 KB
/
TestClientManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.IO.Compression;
using System.Diagnostics;
using System.Threading;
using System.Security.AccessControl;
namespace TestNetwork
{
[TestClass]
public class TestClientManager
{
[TestMethod]
public void ClientManagerCoverage()
{
Exception err = null;
Process server = null;
String serverDirectory = Directory.GetCurrentDirectory() + "\\..\\..\\..\\Server";
String serverZip = serverDirectory + ".zip";
try
{
CoreNetwork.ClientManager coreSide = new CoreNetwork.ClientManager(new CoreCommand.BinaryManager());
EventClient.Communication.TcpManager guiSide = new EventClient.Communication.TcpManager();
Assert.IsTrue(File.Exists(serverZip));
if (Directory.Exists(serverDirectory))
Directory.Delete(serverDirectory, true);
ZipFile.ExtractToDirectory(serverZip, serverDirectory);
String serverExe = serverDirectory + "\\Server.exe";
Assert.IsTrue(File.Exists(serverExe));
server = Process.Start(serverExe, "-p 4242");
Thread.Sleep(500);
coreSide.Connect("127.0.0.1", 4242);
guiSide.Connect("127.0.0.1", 4242);
Assert.IsTrue(coreSide.isConnected() && guiSide.isConnected());
coreSide.RegisterEvents();
CoreCommand.Command.Declarator.Declare tosend = new CoreCommand.Command.Declarator.Declare
{
ContainerID = 0,
EntityType = CoreControl.EntityFactory.ENTITY.CONTEXT,
Name = "testCoverage",
Visibility = CoreControl.EntityFactory.VISIBILITY.PUBLIC
};
bool run = true;
guiSide.RegisterEvent("DECLARATOR.DECLARED", (byte[] data) =>
{
MemoryStream stream = new MemoryStream(data);
CoreCommand.Command.Declarator.Declare.Reply reply = BinarySerializer.Serializer.Deserialize<CoreCommand.Command.Declarator.Declare.Reply>(data);
Debug.WriteLine("Reply: { {" + tosend.ContainerID + ", " + tosend.EntityType + ", \"" + tosend.Name + "\", " + tosend.Visibility + "}, " + reply.EntityID + "}");
run = false;
}, 0);
MemoryStream sendstream = new MemoryStream();
BinarySerializer.Serializer.Serialize(tosend, sendstream);
guiSide.SendEvent("DECLARATOR.DECLARE", sendstream.GetBuffer());
uint timeout = 100;
while (run && timeout > 0)
{
coreSide.Update();
guiSide.Update();
Thread.Sleep(50);
--timeout;
}
Assert.IsFalse(run);
}
catch (Exception error)
{
err = error;
Console.Error.WriteLine(error.Message);
}
if (server != null)
{
server.Kill();
server.WaitForExit();
}
try
{
Directory.Delete(serverDirectory, true);
}
catch (Exception)
{
}
if (err != null)
throw err;
}
}
}