Ejemplo n.º 1
0
        public void Receive_InvalidPayload_PayloadNotProcessed()
        {
            //Arrange

            Client client         = new Client("10.0.0.1", 123);
            var    networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel();

            MockObjectMessage receive = null;

            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            transport.Receive <MockObjectMessage>(o =>
            {
                receive = o;
            }
                                                  )
            .Execute();

            networkChannel.SimulateClientConnect(client);
            networkChannel.SimulateClientResponse(client,
                                                  "{\"Type\":\"OTransport.tests.MockObjectMessage, ObjectTransport.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",:{\"Property1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}}"
                                                  );

            //Assert
            Assert.IsNull(receive);
        }
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 OnFailedReceived_InvalidPayloadReceived_OnFailHandleExecuted()
        {
            //Arrange

            Client          client          = new Client("10.0.0.1", 123);
            ReceivedMessage receivedMessage = null;
            Exception       failedException = null;
            var             networkChannel  = MockNetworkChannelFactory.GetMockedNetworkChannel();

            MockObjectMessage receive = new MockObjectMessage();

            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            transport.Receive <MockObjectMessage>(o =>
            {
                receive = o;
            }
                                                  )
            .Execute();

            transport.OnFailedReceive((r, e) =>
            {
                receivedMessage = r;
                failedException = e;
            });

            networkChannel.SimulateClientConnect(client);
            networkChannel.SimulateClientResponse(client, "OTransport.tests.NOTHING, ObjectTransport.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullProperty1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}");

            Assert.IsNotNull(receivedMessage);
            Assert.IsNotNull(failedException);
        }
Ejemplo n.º 4
0
        public void Receive_ObjectType_ObjectReceiveFunctionExecuted()
        {
            //Arrange

            Client client         = new Client("10.0.0.1", 123);
            var    networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel();

            MockObjectMessage receive = new MockObjectMessage();

            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            transport.Receive <MockObjectMessage>(o =>
            {
                receive = o;
            }
                                                  )
            .Execute();

            networkChannel.SimulateClientConnect(client);
            networkChannel.SimulateClientResponse(client,
                                                  "OTransport.tests.MockObjectMessage, ObjectTransport.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null::{\"Property1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}"
                                                  );
            //Assert
            Assert.AreEqual("Test String", receive.Property1_string);
            Assert.AreEqual(12, receive.Property2_int);
            Assert.AreEqual(1.33M, receive.Property3_decimal);
        }
Ejemplo n.º 5
0
        public void Receive_ReplyToReceivedObject_ObjectIsSentBack()
        {
            //Arrange
            string replayPayload  = null;
            Client client         = new Client("10.0.0.1", 123);
            var    networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                    .OnSendHandle((Client, payload) => replayPayload = payload);


            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            transport.Receive <MockObjectMessage>()
            .Reply(o =>
            {
                MockObjectMessage sendBack = new MockObjectMessage();
                sendBack.Property1_string  = "Reply message";
                sendBack.Property2_int     = 12;
                sendBack.Property3_decimal = 1.33M;

                return(sendBack);
            })
            .Execute();


            networkChannel.SimulateClientConnect(client);
            networkChannel.SimulateClientResponse(client,
                                                  "OTransport.tests.MockObjectMessage, ObjectTransport.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null::{\"Property1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}"
                                                  );

            //Assert
            Assert.AreEqual("OTransport.tests.MockObjectMessage, ObjectTransport.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null::{\"Property1_string\":\"Reply message\",\"Property2_int\":12,\"Property3_decimal\":1.33}", replayPayload);
        }
        public void SendWithResponse_ObjectWithPropertiesSet_PayloadWithObjectAndTokenSent()
        {
            //Arrange
            var sentPayload    = string.Empty;
            var client         = new Client("10.0.0.1", 123);
            var networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                 .OnSendHandle((Client, payload) => sentPayload = payload);

            MockObjectMessage sendObject = new MockObjectMessage();

            sendObject.Property1_string  = "Test String";
            sendObject.Property2_int     = 12;
            sendObject.Property3_decimal = 1.33M;

            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            networkChannel.SimulateClientConnect(client);

            //Act

            transport.Send(sendObject)
            .Response <MockObjectMessage>(o => o.GetType())
            .Execute();


            Utilities.WaitFor(ref sentPayload);

            //Assert
            Regex rgx = new Regex(typeof(MockObjectMessage).AssemblyQualifiedName + "::(.*)::{\"Property1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}");

            Assert.IsTrue(rgx.IsMatch(sentPayload));
        }
        public void SendToAll_Except2Client_AllClientsExcept2AreSendTo()
        {
            //Arrange
            var client1 = new Client("10.0.0.1", 123);
            var client2 = new Client("10.0.0.2", 123);
            var client3 = new Client("10.0.0.3", 123);

            var clientsSendTo = new List <Client>();

            var networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                 .OnSendHandle((Client, paylaod) => clientsSendTo.Add(Client));

            MockObjectMessage sendObject = new MockObjectMessage();

            sendObject.Property1_string  = "Test String";
            sendObject.Property2_int     = 12;
            sendObject.Property3_decimal = 1.33M;

            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            networkChannel.SimulateClientConnect(client1);
            networkChannel.SimulateClientConnect(client2);
            networkChannel.SimulateClientConnect(client3);

            //Act

            transport.Send(sendObject)
            .Response <MockObjectMessage>(o => o.GetType())
            .ToAllExcept(client1, client3)
            .Execute();

            //Assert
            Assert.AreEqual(1, clientsSendTo.Count);
            Assert.AreEqual(clientsSendTo[0].IPAddress, "10.0.0.2");
        }
        public void SendExecute_ObjectWithProperties_PayloadWithObjectAndTypeSent()
        {
            //Arrange
            var sentPayload    = string.Empty;
            var client         = new Client("10.0.0.1", 123);
            var networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                 .OnSendHandle((Client, payload) => sentPayload = payload);

            MockObjectMessage sendObject = new MockObjectMessage();

            sendObject.Property1_string  = "Test String";
            sendObject.Property2_int     = 12;
            sendObject.Property3_decimal = 1.33M;

            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            networkChannel.SimulateClientConnect(client);
            transport.Send(sendObject)
            .To(client)
            .Execute();

            //Assert
            Assert.AreEqual(typeof(MockObjectMessage).AssemblyQualifiedName + "::{\"Property1_string\":\"Test String\",\"Property2_int\":12,\"Property3_decimal\":1.33}", sentPayload);
        }
        public void TimeOut_MessageSentToMultipleClientsWithSomeResponding_TimeOutFunctionReturnsClientsWhoDidNotRespond()
        {
            //Arrange
            var client1 = new Client("10.0.0.1", 123);
            var client2 = new Client("10.0.0.2", 123);
            var client3 = new Client("10.0.0.3", 123);

            Client[]          clientsWhoDidNotRespond = null;
            MockObjectMessage messageThatTimedOut     = null;

            var sentPayload    = string.Empty;
            var networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                 .OnSendHandle((Client, payload) => sentPayload = payload);

            MockObjectMessage sendObject = new MockObjectMessage();

            sendObject.Property1_string  = "Test String";
            sendObject.Property2_int     = 12;
            sendObject.Property3_decimal = 1.33M;

            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            networkChannel.SimulateClientConnect(client1);
            networkChannel.SimulateClientConnect(client2);
            networkChannel.SimulateClientConnect(client3);

            //Act
            transport.Send(sendObject)
            .Response <MockObjectMessage>(o => { })
            .SetTimeOut(2)
            .OnTimeOut(
                (c, o) => {
                clientsWhoDidNotRespond = c;
                messageThatTimedOut     = o;
            })
            .ToAll()
            .Execute();

            //Echo back the message
            networkChannel.SimulateClientResponse(client2, sentPayload);

            Utilities.WaitFor(ref messageThatTimedOut);

            //Assert
            Assert.AreEqual(2, clientsWhoDidNotRespond.Length);
            Assert.IsTrue(clientsWhoDidNotRespond.Contains(client1));
            Assert.IsTrue(clientsWhoDidNotRespond.Contains(client3));
            Assert.AreEqual(sendObject, messageThatTimedOut);
        }
Ejemplo n.º 10
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.º 11
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);
        }
        public void TimeOut_TimeOutFunctionSet_TimeOutFunctionCalled()
        {
            //Arrange
            var client = new Client("10.0.0.1", 123);

            Client[]          clientsWhoDidNotRespond = null;
            MockObjectMessage messageThatTimedOut     = null;

            var sentPayload    = string.Empty;
            var networkChannel = MockNetworkChannelFactory.GetMockedNetworkChannel()
                                 .OnSendHandle((Client, payload) => sentPayload = payload);

            MockObjectMessage sendObject = new MockObjectMessage();

            sendObject.Property1_string  = "Test String";
            sendObject.Property2_int     = 12;
            sendObject.Property3_decimal = 1.33M;

            //Act
            ObjectTransport transport = TestObjectTransportFactory.CreateNewObjectTransport(networkChannel);

            networkChannel.SimulateClientConnect(client);

            transport.Send(sendObject)
            .Response <MockObjectMessage>(o => { })
            .SetTimeOut(1)
            .OnTimeOut(
                (c, o) => {
                clientsWhoDidNotRespond = c;
                messageThatTimedOut     = o;
            })
            .Execute();

            Utilities.WaitFor(ref clientsWhoDidNotRespond);

            //Assert
            Assert.AreEqual(1, clientsWhoDidNotRespond.Length);
            Assert.AreEqual(sendObject, messageThatTimedOut);
        }