public void AsyncCallbackTest()
        {
            bool          isCallbackDone = false;
            AsyncCallback callback       = ar => isCallbackDone = true;

            var pendingCall = new PendingCall(0, "", "", callback, this);

            pendingCall.ReceiveResult(
                new RpcMessage.Result {
                CallResult = new RpcMessage.Parameter {
                    IntParam = 42
                }
            });

            client.Setup(c =>
                         c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <AsyncCallback>(),
                                It.IsAny <object>())).Returns(pendingCall);

            dynamic      serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            IAsyncResult asyncResult  = serviceProxy.BeginTestMethod("param", 42.0f, callback, this);

            Assert.That(asyncResult.AsyncState, Is.EqualTo(this));
            asyncResult.AsyncWaitHandle.WaitOne(); //not necessary, just because i can
            int result = serviceProxy.EndTestMethod(asyncResult);

            Assert.That(isCallbackDone);
            Assert.That(asyncResult.IsCompleted);
            Assert.That(result, Is.EqualTo(42));
            client.Verify(c => c.Call("TestServiceName", "TestMethod", new object[] { "param", 42.0f }, callback, this));
        }
Esempio n. 2
0
        public void AsyncCallbackTest()
        {
            bool isCallbackDone = false;
            AsyncCallback callback = ar => isCallbackDone = true;

            var pendingCall = new PendingCall(0, "", "", callback, this);
            pendingCall.ReceiveResult(
                new RpcMessage.Result { CallResult = new RpcMessage.Parameter { IntParam = 42 } });

            client.Setup(c =>
                c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object[]>(), It.IsAny<AsyncCallback>(),
                    It.IsAny<object>())).Returns(pendingCall);

            dynamic serviceProxy = new DynamicProxy(client.Object, "TestServiceName");
            IAsyncResult asyncResult = serviceProxy.BeginTestMethod("param", 42.0f, callback, this);
            Assert.That(asyncResult.AsyncState, Is.EqualTo(this));
            asyncResult.AsyncWaitHandle.WaitOne(); //not necessary, just because i can
            int result = serviceProxy.EndTestMethod(asyncResult);

            Assert.That(isCallbackDone);
            Assert.That(asyncResult.IsCompleted);
            Assert.That(result, Is.EqualTo(42));
            client.Verify(c => c.Call("TestServiceName", "TestMethod", new object[] { "param", 42.0f }, callback, this));
        }