Ejemplo n.º 1
0
        public void Receive_ObjectWithBinaryProperty_BinaryReceived()
        {
            //Arrange
            var joinedNetworkChannels = MockNetworkChannelFactory.GetConnectedChannels();

            MockObjectMessageWithBinary sendMessage = new MockObjectMessageWithBinary();

            sendMessage.Property2_String = "Message with binary";
            sendMessage.Property1_Bytes  = Encoding.ASCII.GetBytes("hello world");

            MockObjectMessageWithBinary receivedMessage = null;
            Client receivedClient = null;

            //Act
            ObjectTransport client1 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item1);

            client1.Receive <MockObjectMessageWithBinary>((c, o) =>
            {
                receivedClient  = c;
                receivedMessage = o;
            })
            .Execute();


            ObjectTransport client2 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item2);

            client2.Send(sendMessage)
            .Execute();

            //Assert
            Assert.AreEqual("hello world", System.Text.Encoding.UTF8.GetString(receivedMessage.Property1_Bytes));
            Assert.AreEqual(receivedMessage.Property2_String, "Message with binary");
            Assert.AreEqual("10.0.0.2", receivedClient.IPAddress);
        }
Ejemplo n.º 2
0
        public void SendReceiveThroughChannel_ObjectTransportConnectedChannel_ObjectSentAndReceivedBetweenClients()
        {
            //Arrange
            var joinedNetworkChannels = MockNetworkChannelFactory.GetConnectedChannels();

            MockObjectMessage sendMessage = new MockObjectMessage();

            sendMessage.Property1_string  = "test send";
            sendMessage.Property2_int     = 123;
            sendMessage.Property3_decimal = 56M;

            MockObjectMessage receivedMessage = null;

            //Act
            ObjectTransport client1 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item1);

            client1.Receive <MockObjectMessage>(o =>
            {
                receivedMessage = o;
            })
            .Execute();


            ObjectTransport client2 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item2);

            client2.Send(sendMessage)
            .Execute();

            Utilities.WaitFor(ref receivedMessage);

            //Assert
            Assert.AreEqual(sendMessage.Property3_decimal, receivedMessage.Property3_decimal);
            Assert.AreEqual(sendMessage.Property1_string, receivedMessage.Property1_string);
            Assert.AreEqual(sendMessage.Property2_int, receivedMessage.Property2_int);
        }
Ejemplo n.º 3
0
        public void SendReceiveReplyThroughChannel_TwoObjectTransportsConnected_SameTokenUsed()
        {
            //Arrange
            var client2ReceiveFunctionCalled = false;
            var client2RespondFunctionCalled = false;
            var joinedNetworkChannels        = MockNetworkChannelFactory.GetConnectedChannels();

            MockObjectMessage sendMessage = new MockObjectMessage();

            sendMessage.Property1_string  = "test send";
            sendMessage.Property2_int     = 123;
            sendMessage.Property3_decimal = 56M;

            MockObjectMessage receivedMessage = null;

            //Act
            ObjectTransport client1 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item1);

            client1.Receive <MockObjectMessage>()
            .Reply((c, o) =>
            {
                o.Property1_string = "replied";
                return(o);
            })
            .Execute();


            ObjectTransport client2 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item2);

            client2.Send(sendMessage)
            .Response <MockObjectMessage>(o =>
            {
                client2RespondFunctionCalled = true;
                receivedMessage = o;
            })
            .Execute();

            client2.Receive <MockObjectMessage>(o =>
            {
                client2ReceiveFunctionCalled = true;
                receivedMessage = o;
            }).Execute();

            Utilities.WaitFor(ref receivedMessage);

            //Assert
            Assert.IsFalse(client2ReceiveFunctionCalled);
            Assert.IsTrue(client2RespondFunctionCalled);
        }
Ejemplo n.º 4
0
        public void ReceiveReply_WithClientAction_ObjectAndClientInjectedInToAction()
        {
            //Arrange
            var joinedNetworkChannels = MockNetworkChannelFactory.GetConnectedChannels();

            MockObjectMessage sendMessage = new MockObjectMessage();

            sendMessage.Property1_string  = "test send";
            sendMessage.Property2_int     = 123;
            sendMessage.Property3_decimal = 56M;

            MockObjectMessage receivedMessage = null;
            Client            receivedClient  = null;

            //Act
            ObjectTransport client1 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item1);

            client1.Receive <MockObjectMessage>()
            .Reply((c, o) =>
            {
                receivedMessage = o;
                receivedClient  = c;
                return(null);
            })
            .Execute();


            ObjectTransport client2 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item2);

            client2.Send(sendMessage)
            .Execute();

            Utilities.WaitFor(ref receivedMessage);

            //Assert
            Assert.AreEqual(sendMessage.Property3_decimal, receivedMessage.Property3_decimal);
            Assert.AreEqual(sendMessage.Property1_string, receivedMessage.Property1_string);
            Assert.AreEqual(sendMessage.Property2_int, receivedMessage.Property2_int);
            Assert.AreEqual("10.0.0.2", receivedClient.IPAddress);
        }
Ejemplo n.º 5
0
        public void Protobuff_UsingProtobuffSerializer_objectIsSentAndReceived()
        {
            //Arrange
            var joinedNetworkChannels = MockNetworkChannelFactory.GetConnectedChannels();

            Protobuf_MockObjectMessage sendMessage = new Protobuf_MockObjectMessage();

            sendMessage.Property1_string  = "test send";
            sendMessage.Property2_int     = 123;
            sendMessage.Property3_decimal = 56M;

            Protobuf_MockObjectMessage receivedMessage = null;
            Client receivedClient = null;

            //Act
            ObjectTransport client1 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item1, new ProtobufSerializer());

            client1.Receive <Protobuf_MockObjectMessage>((c, o) =>
            {
                receivedClient  = c;
                receivedMessage = o;
            })
            .Execute();


            ObjectTransport client2 = TestObjectTransportFactory.CreateNewObjectTransport(joinedNetworkChannels.Item2, new ProtobufSerializer());

            client2.Send(sendMessage)
            .Execute();

            //Assert
            Assert.AreEqual(sendMessage.Property3_decimal, receivedMessage.Property3_decimal);
            Assert.AreEqual(sendMessage.Property1_string, receivedMessage.Property1_string);
            Assert.AreEqual(sendMessage.Property2_int, receivedMessage.Property2_int);
            Assert.AreEqual("10.0.0.2", receivedClient.IPAddress);
        }