コード例 #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));
        }
コード例 #2
0
        public void CallServer_And_Receive_Call_Result()
        {
            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, new { stuff = "cool" });
            });

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

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

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

            IWampServer client = GetClient(connection.SideAToSideB, clientMock.Object);

            listener.Start();
            mockListener.OnNext(connection.SideBToSideA);

            clientMock.Verify(x => x.Welcome(It.IsAny <string>(),
                                             It.IsAny <int>(),
                                             It.IsAny <string>()));

            Mock <IWampClient> userClientMock = new Mock <IWampClient>();

            client.Call(userClientMock.Object, "a123123", "Test",
                        new
            {
                name = "Jack"
            });

            serverMock.Verify(x => x.Call(It.IsAny <IWampClient>(),
                                          "a123123",
                                          "Test",
                                          It.IsAny <JToken[]>()));

            clientMock.Verify(x => x.CallResult("a123123",
                                                It.Is((JToken result) => result.Value <string>("stuff") == "cool")));
        }
コード例 #3
0
ファイル: ListenerTests.cs プロジェクト: uzbekdev1/WampSharp
        public void Welcome_OnClient_Connect()
        {
            var    clientMock = new Mock <IWampClient>();
            string sessionId  = "dfgewj324908";

            clientMock.SetupGet(x => x.SessionId).Returns(sessionId);
            MockListener <JToken> mockListener = new MockListener <JToken>();
            WampListener <JToken> listener     = GetListener(mockListener, clientMock.Object);

            listener.Start();
            Mock <IWampConnection <JToken> > connectionMock = new Mock <IWampConnection <JToken> >();

            mockListener.OnNext(connectionMock.Object);

            connectionMock.Raise(x => x.ConnectionOpen += (sender, args) => {},
                                 EventArgs.Empty);

            clientMock.Verify(x => x.Welcome(sessionId, 1, "WampSharp"));
        }
コード例 #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)));
        }