public IEnumerator ShouldClientBeAbleToListenToARouteAndReceiveData() { var receivedPushResponse = false; object response = null; const string expectedResponse = "{\"key1\":10,\"key2\":true}"; _client.Connect(ServerHost, ServerPort); _client.OnRoute("some.push.route", res => { receivedPushResponse = true; response = res; Assert.AreEqual(_mainThread, Thread.CurrentThread); } ); var requestFinished = false; object sendPushResponse = null; _client.Request( "connector.sendpush", res => { requestFinished = true; sendPushResponse = res; Assert.AreEqual(_mainThread, Thread.CurrentThread); }, error => { requestFinished = true; sendPushResponse = error; Assert.AreEqual(_mainThread, Thread.CurrentThread); } ); while (!requestFinished) { yield return(new WaitForSeconds(0.5f)); } var resp = (JsonObject)SimpleJson.SimpleJson.DeserializeObject((string)sendPushResponse); Assert.True(receivedPushResponse); Assert.NotNull(response); Assert.AreEqual(response, expectedResponse); Assert.NotNull(sendPushResponse); Assert.AreEqual(resp["Code"], 200); Assert.AreEqual(resp["Msg"], "Ok"); }
public IEnumerator ShoulReceiveAPushNotification() { object response = null; _isFinished = false; _client.OnRoute <SessionData>("some.push.route", data => { response = data; _isFinished = true; }); _client.Notify("connector.notifysessiondata", _sessionData); while (!_isFinished) { yield return(new WaitForSeconds(1)); } Assert.NotNull(response); Assert.AreEqual(typeof(SessionData), response.GetType()); Assert.AreEqual(((SessionData)response).Data, "THIS IS THE SESSION DATA"); }