public IEnumerator ShouldReturnResponseInSubscriberFormat()
        {
            object response;


            response    = null;
            _isFinished = false;

            _client.Request <Response>("connector.setsessiondata",
                                       _sessionData,
                                       (res) => {
                response    = res;
                _isFinished = true;
            },
                                       error => {
                response    = error;
                _isFinished = true;
            }
                                       );

            while (!_isFinished)
            {
                yield return(new WaitForSeconds(1));
            }

            Assert.NotNull(response);
            Assert.AreEqual(typeof(Response), response.GetType());
        }
Exemple #2
0
        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");
        }
Exemple #3
0
        public void Init()
        {
            _client = new PitayaClient();
            PitayaClient.SetLogLevel(PitayaLogLevel.Debug);

            _client.Connect(ServerHost, ServerPort);

            _data          = "{\"Data\":{\"name\":\"test25\"}}";
            _jsonStub      = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_data);
            _emptyData     = "{\"Data\":{}}";
            _emptyJsonStub = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_emptyData);

            _isFinished = false;

            Thread.Sleep(300);

            // clearing sessiondata
            _client.Request(
                "connector.setsessiondata",
                _emptyData,
                res => {
                _isFinished = true;
            },
                error => {
                _isFinished = true;
            }
                );
        }
Exemple #4
0
        public void TestJsonRequestCall()
        {
            var route = "route";

            var expectedRes = new TestResponse
            {
                Attr = "wololo",
                List = new List <float> {
                    14.3f, 11.0f, 65.4f
                }
            };

            var mockBinding = Substitute.For <IPitayaBinding>();

            var res = Newtonsoft.Json.JsonConvert.SerializeObject(expectedRes);

            var client = new PitayaClient(binding: mockBinding, queueDispatcher: new NullPitayaQueueDispatcher());

            mockBinding.When(x => x.Request(Arg.Any <IntPtr>(), route, Arg.Any <byte[]>(), Arg.Any <uint>(), Arg.Any <int>())).Do(x =>
            {
                client.OnRequestResponse(1, Encoding.UTF8.GetBytes(res));
            });

            var completionSource = new TaskCompletionSource <(TestResponse, PitayaError)>();

            client.Request <TestResponse>(route, new TestRequest(), (TestResponse response) =>
            {
                completionSource.TrySetResult((response, null));
            }, (PitayaError error) =>
            {
                completionSource.TrySetResult((null, error));
            });
        public void Init()
        {
            // PitayaBinding.AddPinnedPublicKeyFromCaFile("client-ssl.localhost.crt");
            _mainThread = Thread.CurrentThread;
            PitayaBinding.SkipKeyPinCheck(true);

            _client = new PitayaClient("ca.crt");
            PitayaClient.SetLogLevel(PitayaLogLevel.Debug);

            _client.Connect(ServerHost, ServerPort);

            Thread.Sleep(200);

            _data          = "{\"Data\":{\"name\":\"test25\"}}";
            _jsonStub      = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_data);
            _emptyData     = "{\"Data\":{}}";
            _emptyJsonStub = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_emptyData);

            _isFinished = false;

            // clearing sessiondata
            _client.Request(
                "connector.setsessiondata",
                _emptyData,
                res => { _isFinished = true; },
                error => { _isFinished = true; }
                );
        }
Exemple #6
0
        public IEnumerator ShouldReturnJsonObjectWhenNoSubscriberIsAdded()
        {
            while (!_isFinished)
            {
                yield return(new WaitForSeconds(0.3f));
            }
            _isFinished = false;

            object response = null;

            _client.Request(
                "connector.setsessiondata",
                _data,
                res => {
                response    = res;
                _isFinished = true;
            },
                error => {
                response    = error;
                _isFinished = true;
            }
                );

            while (!_isFinished)
            {
                yield return(new WaitForSeconds(0.3f));
            }

            var resp = (JsonObject)SimpleJson.SimpleJson.DeserializeObject((string)response);

            Assert.True(_isFinished);
            Assert.NotNull(response);
            Assert.AreEqual(resp["Code"], 200);
            Assert.AreEqual(resp["Msg"], "success");
        }
Exemple #7
0
 // Update is called once per frame
 private void Update()
 {
     if (_connected && !_requestSent)
     {
         _client.Request("connector.getsessiondata",
                         (data) =>
         {
             Debug.Log("Got request data: " + data);
             File.WriteAllText("/Users/lhahn/Downloads/OH_MY_GOD.txt", "I Got the request data: " + data);
         },
                         (err) =>
         {
             Debug.LogError("Got error: code = " + err.Code + ", msg = " + err.Msg);
         });
         _requestSent = true;
     }
 }