예제 #1
0
        public dynamic GetDynamicClient(IWampConnection <TMessage> connection)
        {
            IWampRpcClientHandler handler = mClientHandlerBuilder.Build(connection);

            DynamicWampRpcClient client = new DynamicWampRpcClient(handler, mSerializer);

            return(client);
        }
예제 #2
0
        public WampRpcClientInterceptor SelectInterceptor(MethodInfo method,
                                                          IWampRpcClientHandler handler)
        {
            if (typeof(Task).IsAssignableFrom(method.ReturnType))
            {
                return(new WampRpcClientSyncInterceptor(mSerializer, handler));
            }

            return(new WampRpcClientSyncInterceptor(mSerializer, handler));
        }
예제 #3
0
        public void HandleAsync_ClientCallError_SetsTasksException
            (WampRpcCall rpcCall, CallErrorDetails callErrorDetails)
        {
            MockWampRpcCallManager <MockRaw> callManager =
                new MockWampRpcCallManager <MockRaw>();

            IWampRpcClientHandler handler =
                GetHandler(client => callManager.GetServer(client));

            Task <object> task = handler.HandleAsync(rpcCall);

            MockWampRpcCallDetails <MockRaw> details =
                callManager.GetCallDetails(rpcCall.CallId);

            Assert.IsFalse(task.IsCompleted);

            object errorDetails = callErrorDetails.ErrorDetails;

            if (errorDetails == null)
            {
                details.Client.CallError(rpcCall.CallId,
                                         callErrorDetails.ErrorUri,
                                         callErrorDetails.ErrorDesc);
            }
            else
            {
                details.Client.CallError(rpcCall.CallId,
                                         callErrorDetails.ErrorUri,
                                         callErrorDetails.ErrorDesc,
                                         new MockRaw(errorDetails));
            }

            AggregateException aggregatedException = task.Exception;

            Assert.IsNotNull(aggregatedException);

            Exception innerException = aggregatedException.InnerException;

            Assert.That(innerException, Is.TypeOf(typeof(WampRpcCallException)));

            WampRpcCallException casted = innerException as WampRpcCallException;

            Assert.That(casted.Message, Is.EqualTo(callErrorDetails.ErrorDesc));
            Assert.That(casted.CallId, Is.EqualTo(rpcCall.CallId));
            Assert.That(casted.ErrorUri, Is.EqualTo(callErrorDetails.ErrorUri));
            Assert.That(casted.ErrorDetails,
                        Is.EqualTo(errorDetails)
                        .Using(StructuralComparisons.StructuralEqualityComparer));
        }
예제 #4
0
        public void HandleAsync_ClientCall_TaskIsAsync()
        {
            MockWampRpcCallManager <MockRaw> callManager =
                new MockWampRpcCallManager <MockRaw>();

            IWampRpcClientHandler handler =
                GetHandler(client => callManager.GetServer(client));

            // call a function that takes a long time, call another function
            // the result of the latter is received first, in other words,
            // RPC is really asynchronous
            var slowCall = new WampRpcCall()
            {
                Arguments  = new object[] { new int[] { 1, 2, 3 } },
                ProcUri    = "calc:asum",
                ReturnType = typeof(int)
            };

            var fastCall = new WampRpcCall()
            {
                Arguments  = new object[] { new int[] { 4, 5, 6 } },
                ProcUri    = "calc:sum",
                ReturnType = typeof(int)
            };

            Task <object> slowTask = handler.HandleAsync(slowCall);

            Task <object> fastTask = handler.HandleAsync(fastCall);

            MockWampRpcCallDetails <MockRaw> slowCallDetails =
                callManager.GetCallDetails(slowCall.CallId);

            MockWampRpcCallDetails <MockRaw> fastCallDetails =
                callManager.GetCallDetails(fastCall.CallId);

            Assert.IsFalse(slowTask.IsCompleted);
            Assert.IsFalse(fastTask.IsCompleted);

            fastCallDetails.Client.CallResult(fastCall.CallId, new MockRaw(15));

            Assert.That(fastTask.Result, Is.EqualTo(15));
            Assert.IsFalse(slowTask.IsCompleted);

            slowCallDetails.Client.CallResult(slowCall.CallId, new MockRaw(6));
            Assert.That(slowTask.Result, Is.EqualTo(6));
        }
예제 #5
0
        public TProxy GetClient <TProxy>(IWampConnection <TMessage> connection) where TProxy : class
        {
            IWampRpcClientHandler handler = mClientHandlerBuilder.Build(connection);

            WampRpcClientSyncInterceptor syncInterceptor =
                new WampRpcClientSyncInterceptor(mSerializer, handler);

            WampRpcClientAsyncInterceptor asyncInterceptor =
                new WampRpcClientAsyncInterceptor(mSerializer, handler);

            TProxy result = DispatchProxy.Create <TProxy, RpcDispatchProxy>();

            RpcDispatchProxy dispatchProxy = result as RpcDispatchProxy;

            dispatchProxy.SyncInterceptor  = syncInterceptor;
            dispatchProxy.AsyncInterceptor = asyncInterceptor;

            return(result);
        }
예제 #6
0
        public void HandleAsync_Calls_ServerProxyCall(WampRpcCall rpcCall)
        {
            MockWampRpcCallManager <MockRaw> callManager =
                new MockWampRpcCallManager <MockRaw>();

            IWampRpcClientHandler handler =
                GetHandler(client => callManager.GetServer(client));

            Assert.That(callManager.AllCalls, Is.Empty);

            Task <object> task = handler.HandleAsync(rpcCall);

            MockWampRpcCallDetails <MockRaw> details =
                callManager.GetCallDetails(rpcCall.CallId);

            Assert.IsNotNull(details);

            Assert.That(details.CallId, Is.EqualTo(rpcCall.CallId));
            Assert.That(details.ProcUri, Is.EqualTo(rpcCall.ProcUri));
            CollectionAssert.AreEqual(rpcCall.Arguments, details.Arguments);
        }
예제 #7
0
        public TProxy GetClient <TProxy>(IWampConnection <TMessage> connection) where TProxy : class
        {
            IWampRpcClientHandler handler = mClientHandlerBuilder.Build(connection);

            WampRpcClientSyncInterceptor syncInterceptor =
                new WampRpcClientSyncInterceptor(mSerializer, handler);

            WampRpcClientAsyncInterceptor asyncInterceptor =
                new WampRpcClientAsyncInterceptor(mSerializer, handler);

            ProxyGenerationOptions generationOptions =
                new ProxyGenerationOptions {
                Selector = new WampRpcClientInterceptorSelector()
            };

            TProxy result =
                mProxyGenerator.CreateInterfaceProxyWithoutTarget <TProxy>
                    (generationOptions,
                    syncInterceptor,
                    asyncInterceptor);

            return(result);
        }
예제 #8
0
        public void HandleAsync_ClientCallResult_SetsTasksResult(WampRpcCall rpcCall, object result)
        {
            MockWampRpcCallManager <MockRaw> callManager =
                new MockWampRpcCallManager <MockRaw>();

            IWampRpcClientHandler handler =
                GetHandler(client => callManager.GetServer(client));

            if (result != null)
            {
                rpcCall.ReturnType = result.GetType();
            }

            Task <object> task = handler.HandleAsync(rpcCall);

            MockWampRpcCallDetails <MockRaw> details =
                callManager.GetCallDetails(rpcCall.CallId);

            Assert.IsFalse(task.IsCompleted);

            details.Client.CallResult(rpcCall.CallId, new MockRaw(result));

            Assert.That(task.Result, Is.EqualTo(result));
        }
 public WampRpcClientAsyncInterceptor(IWampRpcSerializer serializer, IWampRpcClientHandler clientHandler)
     : base(serializer, clientHandler)
 {
 }
예제 #10
0
 /// <summary>
 /// Creates a new instance of <see cref="WampRpcClientHandlerBuilder{TMessage}"/>.
 /// </summary>
 /// <param name="serializer"></param>
 /// <param name="clientHandler"></param>
 public WampRpcClientInterceptor(IWampRpcSerializer serializer, IWampRpcClientHandler clientHandler)
 {
     mSerializer    = serializer;
     mClientHandler = clientHandler;
 }
 public WampRpcClientSyncInterceptor(IWampRpcSerializer serializer, IWampRpcClientHandler clientHandler) : base(serializer, clientHandler)
 {
 }
 /// <summary>
 /// Creates a new instance of <see cref="WampRpcClientHandlerBuilder{TMessage}"/>.
 /// </summary>
 /// <param name="serializer"></param>
 /// <param name="clientHandler"></param>
 public WampRpcClientInterceptor(IWampRpcSerializer serializer, IWampRpcClientHandler clientHandler)
 {
     mSerializer = serializer;
     mClientHandler = clientHandler;
 }
예제 #13
0
 /// <summary>
 /// Creates a new instance of <see cref="DynamicWampRpcClient"/>.
 /// </summary>
 /// <param name="clientHandler">The <see cref="IWampRpcClientHandler"/>
 /// that will deal rpc calls.</param>
 /// <param name="serializer">The <see cref="IWampRpcSerializer"/> that will serialize
 /// RPC calls.</param>
 public DynamicWampRpcClient(IWampRpcClientHandler clientHandler,
                             IWampRpcSerializer serializer)
 {
     ClientHandler = clientHandler;
     mSerializer   = serializer;
 }
예제 #14
0
 /// <summary>
 /// Creates a new instance of <see cref="DynamicWampRpcClient"/>.
 /// </summary>
 /// <param name="clientHandler">The <see cref="IWampRpcClientHandler"/>
 /// that will deal rpc calls.</param>
 /// <param name="serializer">The <see cref="IWampRpcSerializer"/> that will serialize
 /// RPC calls.</param>
 public DynamicWampRpcClient(IWampRpcClientHandler clientHandler,
                             IWampRpcSerializer serializer)
 {
     mClientHandler = clientHandler;
     mSerializer = serializer;
 }