public BasicRunTests() { server = new SimpleRpcServer(); var rpcFunctions = new SimpleDUTRemote.Functions(); server.Register(rpcFunctions); serverTask = server.Start(); }
public ClientTests() { server = new SimpleRpcServer(); var rpcFunctions = new SimpleDUTRemote.Functions(); server.Register(rpcFunctions); serverTask = server.Start(); client = new RpcClient("127.0.0.1", 8000); }
public void Job_CheckCallback_AutodetectAddress_ExpectSuccess() { var port = 14000; string receivedMessage = null; // code to listen for callback var server = new TcpListener(IPAddress.Any, port); server.Start(1); var callbackClient = server.AcceptTcpClientAsync(); // start up the server for this specific test var rpcserver = new SimpleJsonRpc.SimpleRpcServer(); var rpcFunctions = new SimpleDUTRemote.Functions(); rpcserver.Register(rpcFunctions); var rpcserverTask = rpcserver.Start(); string output; var client = new TcpClient(); client.ConnectAsync("localhost", 8000).Wait(); using (client) using (var rstream = new StreamReader(client.GetStream())) using (var wstream = new StreamWriter(client.GetStream())) { var request = new JsonRpcRequest(); request.method = "StartJobWithNotification"; request.args = new List <object>() { null, port, "systeminfo.exe" }; wstream.WriteLine(JsonConvert.SerializeObject(request) + "\r\n"); wstream.Flush(); output = rstream.ReadToEnd(); } JObject resp = JObject.Parse(output); int id = (int)resp["result"].ToObject <long>(); if (!callbackClient.Wait(10 * 1000)) { server.Stop(); Assert.Fail("Timed out waiting for callback."); } using (var reader = new StreamReader(callbackClient.Result.GetStream())) { receivedMessage = reader.ReadToEnd(); } callbackClient.Result.Dispose(); Assert.IsTrue(receivedMessage == $"JOB {id} COMPLETED", "Callback has wrong data"); }
public void RpcServer_StopServer() { var altServer = new SimpleRpcServer(); var rpcFunctions = new SimpleDUTRemote.Functions(); altServer.Register(rpcFunctions); var serverTask = altServer.Start(9000); Thread.Sleep(500); altServer.Stop(); var finished = serverTask.Wait(1000); Assert.IsTrue(finished, "Server did not stop."); }