Ejemplo n.º 1
0
        public void RpcClientFactoryCallCallOnProxyAndWait()
        {
            var delegateProcUriMapper     = new WampDelegateProcUriMapper(methodInfo => methodInfo.Name);
            IWampRpcSerializer serializer = new WampRpcSerializer(delegateProcUriMapper);

            MockWampServerProxyFactory <JToken> mockWampServerProxyFactory = null;

            Mock <IWampServer> serverMock = new Mock <IWampServer>();

            serverMock.Setup(x => x.Call(It.IsAny <IWampClient>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <object[]>()))
            .Callback((IWampClient client, string callId, string procUri, object[] args) =>
                      mockWampServerProxyFactory.Client.CallResult(callId, JToken.FromObject(3)));

            mockWampServerProxyFactory = new MockWampServerProxyFactory <JToken>(serverMock.Object);

            WampRpcClientHandlerBuilder <JToken> mockWampRpcClientHandlerBuilder =
                new WampRpcClientHandlerBuilder <JToken>
                    (new JsonFormatter(),
                    mockWampServerProxyFactory);

            IWampRpcClientFactory <JToken> clientFactory = new WampRpcClientFactory <JToken>(serializer, mockWampRpcClientHandlerBuilder);

            ICalculator proxy = clientFactory.GetClient <ICalculator>(DummyConnection <JToken> .Instance);
            int         three = proxy.Square(3);

            Assert.That(three, Is.EqualTo(3));
        }
        public void RpcClientFactoryCallHandlerWithSerializedCall()
        {
            var delegateProcUriMapper = new WampDelegateProcUriMapper(methodInfo => methodInfo.Name);

            IWampRpcSerializer serializer = new WampRpcSerializer(delegateProcUriMapper); // I'm not sure if we want to mock this
            var clientHandler             = new MockWampRpcClientHandler(4);

            var mockWampRpcClientHandlerBuilder           = new MockWampRpcClientHandlerBuilder <MockRaw>(clientHandler);
            IWampRpcClientFactory <MockRaw> clientFactory = new WampRpcClientFactory <MockRaw>(serializer, mockWampRpcClientHandlerBuilder);

            ICalculator proxy = clientFactory.GetClient <ICalculator>(DummyConnection <MockRaw> .Instance);
            int         nine  = proxy.Square(3);

            WampRpcCall wampRpcCall = clientHandler.LastMessage;

            Assert.That(wampRpcCall.ProcUri, Is.EqualTo("Square"));
            CollectionAssert.AreEqual(wampRpcCall.Arguments, new object[] { 3 });
        }