Ejemplo n.º 1
0
        public void ResultHandler_WaitForResult_WaitHandler()
        {
            var resultHandler = new ResultHandler();
            var waitHandle = resultHandler.RegisterWaitHandler(ResultFilterFactory.CreateConnectResultFilter());

            var waitTask = resultHandler.WaitForResult(waitHandle);

            var connected = new Connected() {Session = "TestSession"};
            var returnedObject = new ReturnedObject(connected.MessageType, JObject.FromObject(connected),
                JsonConvert.SerializeObject(connected));

            resultHandler.AddResult(returnedObject);

            waitTask.Wait();

            Assert.AreEqual(returnedObject, waitTask.Result);
        }
Ejemplo n.º 2
0
        public void ResultHandler_RegisterResultCallback_CallbackCalled()
        {
            var resultHandler = new ResultHandler();

            bool callbackCalled = false;
            var connected = new Connected() { Session = "TestSession" };
            var returnedObject = new ReturnedObject(connected.MessageType, JObject.FromObject(connected),
                JsonConvert.SerializeObject(connected));

            resultHandler.RegisterResultCallback(ResultFilterFactory.CreateConnectResultFilter(), o =>
            {
                callbackCalled = true;
                Assert.AreEqual(returnedObject, o);
            });

            resultHandler.AddResult(returnedObject);

            Assert.IsTrue(callbackCalled);
        }
Ejemplo n.º 3
0
        public void ResultHandler_WaitForResult_ReactivateWaitHandle()
        {
            var resultHandler = new ResultHandler();
            var waitHandle = resultHandler.RegisterWaitHandler(ResultFilterFactory.CreateConnectResultFilter());

            var waitTask = resultHandler.WaitForResult(waitHandle);

            var connected = new Connected() { Session = "TestSession" };
            var returnedObject = new ReturnedObject(connected.MessageType, JObject.FromObject(connected),
                JsonConvert.SerializeObject(connected));

            resultHandler.AddResult(returnedObject);

            waitTask.Wait();

            Assert.AreEqual(returnedObject, waitTask.Result);

            PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => resultHandler.WaitForResult(waitHandle));
        }