Exemplo n.º 1
0
        public void CallServer_And_Receive_Call_Result_ViaRpcServer()
        {
            MockListener <JToken> mockListener = new MockListener <JToken>();

            var wampRpcServiceHost = new WampRpcMetadataCatalog();

            wampRpcServiceHost.Register(new MethodInfoWampRpcMetadata(new AddCalculator()));

            WampRpcServer <JToken> rpcServer =
                new WampRpcServer <JToken>(mFormatter,
                                           wampRpcServiceHost);

            WampListener <JToken> listener = GetListener(mockListener, rpcServer);

            MockConnection <JToken> connection = new MockConnection <JToken>(mFormatter);

            WampRpcClientFactory <JToken> factory =
                new WampRpcClientFactory <JToken>(new WampRpcSerializer(new WampDelegateProcUriMapper(x => "http://www.yogev.com/pr/" + x.Name)),
                                                  new WampRpcClientHandlerBuilder <JToken>(mFormatter,
                                                                                           new WampServerProxyFactory <JToken>(new WampServerProxyBuilder <JToken, IWampRpcClient <JToken>, IWampServer>(new WampOutgoingRequestSerializer <JToken>(mFormatter),
                                                                                                                                                                                                         new WampServerProxyOutgoingMessageHandlerBuilder <JToken, IWampRpcClient <JToken> >(new WampServerProxyIncomingMessageHandlerBuilder <JToken, IWampRpcClient <JToken> >(mFormatter))))));

            listener.Start();

            IAddCalculator calculator = factory.GetClient <IAddCalculator>(connection.SideAToSideB);

            mockListener.OnNext(connection.SideBToSideA);

            int sixteen = calculator.Add(10, 6);

            Assert.That(sixteen, Is.EqualTo(16));
        }
Exemplo n.º 2
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 });
        }
Exemplo n.º 4
0
        public void CallServer_And_Receive_Call_Result_ViaRpcClient()
        {
            MockListener <JToken> mockListener = new MockListener <JToken>();

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

            serverMock.Setup(x => x.Call(It.IsAny <IWampClient>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <JToken[]>()))
            .Callback((IWampClient clientParameter, string callId, string procUrl, JToken[] arguments) =>
            {
                clientParameter.CallResult(callId, 12);
            });

            WampListener <JToken> listener = GetListener(mockListener, serverMock.Object);

            MockConnection <JToken> connection = new MockConnection <JToken>(mFormatter);

            WampRpcClientFactory <JToken> factory =
                new WampRpcClientFactory <JToken>(new WampRpcSerializer(new WampDelegateProcUriMapper(x => x.Name)),
                                                  new WampRpcClientHandlerBuilder <JToken>(mFormatter,
                                                                                           new WampServerProxyFactory <JToken>(new WampServerProxyBuilder <JToken, IWampRpcClient <JToken>, IWampServer>(new WampOutgoingRequestSerializer <JToken>(mFormatter),
                                                                                                                                                                                                         new WampServerProxyOutgoingMessageHandlerBuilder <JToken, IWampRpcClient <JToken> >(new WampServerProxyIncomingMessageHandlerBuilder <JToken, IWampRpcClient <JToken> >(mFormatter))))));

            listener.Start();

            ICalculator calculator = factory.GetClient <ICalculator>(connection.SideAToSideB);

            mockListener.OnNext(connection.SideBToSideA);

            int four = 4;

            int sixteen = calculator.Square(four);

            Assert.That(sixteen, Is.EqualTo(12));

            serverMock.Verify(x => x.Call(It.IsAny <IWampClient>(),
                                          It.IsAny <string>(),
                                          "Square",
                                          It.Is((JToken[] parameters) => parameters[0].Value <int>() == four)));
        }
Exemplo n.º 5
0
        private WampRpcClientFactory <TMessage> GetRpcClientFactory()
        {
            WampRpcSerializer rpcSerializer =
                new WampRpcSerializer(new WampRpcMethodAttributeProcUriMapper());

            ManualWampServerProxyBuilder <TMessage, IWampRpcClient <TMessage> > serverProxyBuilder =
                GetServerProxyBuilder <IWampRpcClient <TMessage> >();

            Rpc.Client.WampServerProxyFactory <TMessage> serverProxyFactory =
                new Rpc.Client.WampServerProxyFactory <TMessage>(serverProxyBuilder);

            WampRpcClientHandlerBuilder <TMessage> clientHandlerBuilder =
                new WampRpcClientHandlerBuilder <TMessage>(Formatter, serverProxyFactory);

            WampRpcClientFactory <TMessage> result =
                new WampRpcClientFactory <TMessage>
                    (rpcSerializer,
                    clientHandlerBuilder);

            return(result);
        }
        public void CallServer_And_Receive_Call_Result_ViaRpcClient()
        {
            MockListener<JToken> mockListener = new MockListener<JToken>();

            Mock<IWampServer<JToken>> serverMock = new Mock<IWampServer<JToken>>();
            serverMock.Setup(x => x.Call(It.IsAny<IWampClient>(),
                                         It.IsAny<string>(),
                                         It.IsAny<string>(),
                                         It.IsAny<JToken[]>()))
                      .Callback((IWampClient clientParameter, string callId, string procUrl, JToken[] arguments) =>
                                    {
                                        clientParameter.CallResult(callId, 12);
                                    });

            WampListener<JToken> listener = GetListener(mockListener, serverMock.Object);

            MockConnection<JToken> connection = new MockConnection<JToken>();

            WampRpcClientFactory<JToken> factory =
                new WampRpcClientFactory<JToken>(new WampRpcSerializer(new WampDelegateProcUriMapper(x => x.Name)),
                    new WampRpcClientHandlerBuilder<JToken>(mFormatter,
                        new WampServerProxyFactory<JToken>(new WampServerProxyBuilder<JToken, IWampRpcClient<JToken>, IWampServer>(new WampOutgoingRequestSerializer<JToken>(mFormatter),
                                new WampServerProxyOutgoingMessageHandlerBuilder<JToken, IWampRpcClient<JToken>>(new WampServerProxyIncomingMessageHandlerBuilder<JToken, IWampRpcClient<JToken>>(mFormatter))))));

            listener.Start();

            ICalculator calculator = factory.GetClient<ICalculator>(connection.SideAToSideB);

            mockListener.OnNext(connection.SideBToSideA);

            int four = 4;

            int sixteen = calculator.Square(four);

            Assert.That(sixteen, Is.EqualTo(12));

            serverMock.Verify(x => x.Call(It.IsAny<IWampClient>(),
                                          It.IsAny<string>(),
                                          "Square",
                                          It.Is((JToken[] parameters) => parameters[0].Value<int>() == four)));
        }
        public void CallServer_And_Receive_Call_Result_ViaRpcServer()
        {
            MockListener<JToken> mockListener = new MockListener<JToken>();

            var wampRpcServiceHost = new WampRpcMetadataCatalog();
            wampRpcServiceHost.Register(new MethodInfoWampRpcMetadata(new AddCalculator()));

            WampRpcServer<JToken> rpcServer =
                new WampRpcServer<JToken>(mFormatter,
                                          wampRpcServiceHost);

            WampListener<JToken> listener = GetListener(mockListener, rpcServer);

            MockConnection<JToken> connection = new MockConnection<JToken>();

            WampRpcClientFactory<JToken> factory =
                new WampRpcClientFactory<JToken>(new WampRpcSerializer(new WampDelegateProcUriMapper(x => "http://www.yogev.com/pr/" + x.Name)),
                    new WampRpcClientHandlerBuilder<JToken>(mFormatter,
                        new WampServerProxyFactory<JToken>(new WampServerProxyBuilder<JToken, IWampRpcClient<JToken>, IWampServer>(new WampOutgoingRequestSerializer<JToken>(mFormatter),
                                new WampServerProxyOutgoingMessageHandlerBuilder<JToken, IWampRpcClient<JToken>>(new WampServerProxyIncomingMessageHandlerBuilder<JToken, IWampRpcClient<JToken>>(mFormatter))))));

            listener.Start();

            IAddCalculator calculator = factory.GetClient<IAddCalculator>(connection.SideAToSideB);

            mockListener.OnNext(connection.SideBToSideA);

            int sixteen = calculator.Add(10, 6);

            Assert.That(sixteen, Is.EqualTo(16));
        }