Esempio n. 1
0
        public void Send_TwoObjectsStraightAway_BothProcessedSeperatly()
        {
            //Arrange
            Client client = null;

            client = Client1ObjectTransport.GetConnectedClients().First();

            //Act
            serverObjectTransport.Receive <MockObjectMessage>()
            .Reply((o) => { return(o); })
            .Execute();

            var mockObject = new MockObjectMessage()
            {
                Property1_string = "Mock Object"
            };
            MockObjectMessage responseObject  = null;
            MockObjectMessage responseObject2 = null;

            Client1ObjectTransport.Send(mockObject)
            .Response <MockObjectMessage>((r) => { responseObject = r; })
            .Execute();

            Client1ObjectTransport.Send(mockObject)
            .Response <MockObjectMessage>((r) => { responseObject2 = r; })
            .Execute();

            Utilities.WaitFor(ref responseObject);
            Utilities.WaitFor(ref responseObject2);

            //Assert
            Assert.AreEqual(responseObject.Property1_string, "Mock Object");
            Assert.AreEqual(responseObject2.Property1_string, "Mock Object");
        }
Esempio n. 2
0
        public void Server_ReceivesObjects_CorrectObjectReceived()
        {
            //Arrange
            MockObjectMessage receivedObject = null;

            //Act
            serverObjectTransport.Receive <MockObjectMessage>(o =>
            {
                receivedObject = o;
            }).Execute();

            Client1ObjectTransport.Send(new MockObjectMessage()
            {
                Property1_string  = "hello world!",
                Property2_int     = 123,
                Property3_decimal = 12.3M
            }).Execute();

            Utilities.WaitFor(ref receivedObject);

            //Assert
            Assert.AreEqual("hello world!", receivedObject.Property1_string);
            Assert.AreEqual(123, receivedObject.Property2_int);
            Assert.AreEqual(12.3M, receivedObject.Property3_decimal);
        }
Esempio n. 3
0
        public void Server_SendObject_CorrectObjectSent()
        {
            //Arrange
            MockObjectMessage receivedObject = null;

            Client client = serverObjectTransport.GetConnectedClients().First();

            //Act
            Client1ObjectTransport.Receive <MockObjectMessage>(o =>
                                                               receivedObject = o
                                                               ).Execute();

            serverObjectTransport.Send(new MockObjectMessage()
            {
                Property1_string  = "hello world!",
                Property2_int     = 123,
                Property3_decimal = 12.3M
            })
            .To(client)
            .Execute();

            Utilities.WaitFor(ref receivedObject);

            //Assert
            Assert.AreEqual("hello world!", receivedObject.Property1_string);
            Assert.AreEqual(123, receivedObject.Property2_int);
            Assert.AreEqual(12.3M, receivedObject.Property3_decimal);
        }
Esempio n. 4
0
        public void SendAndReplyMessage_ResponseIsCalled()
        {
            //Arrange
            Client client = null;

            client = Client1ObjectTransport.GetConnectedClients().First();

            //Act
            serverObjectTransport.Receive <MockObjectMessage>()
            .Reply((o) => { return(o); })
            .Execute();

            var mockObject = new MockObjectMessage()
            {
                Property1_string = "Mock Object"
            };
            MockObjectMessage responseObject = null;

            Client1ObjectTransport.Send(mockObject)
            .Response <MockObjectMessage>((r) => { responseObject = r; })
            .Execute();

            Utilities.WaitFor(ref responseObject);

            //Assert
            Assert.AreEqual(responseObject.Property1_string, "Mock Object");
        }
Esempio n. 5
0
        public void UDPServer_ReceivesObjects_CorrectObjectReceived()
        {
            //Arrange
            MockObjectMessage receivedObject = null;
            var connectTransports            = UDPObjectTransportChannel.GetConnectObjectTransports();
            var server = connectTransports.Item1;
            var client = connectTransports.Item2;

            //Act
            server.Receive <MockObjectMessage>(o =>
            {
                receivedObject = o;
            }).Execute();

            client.Send(new MockObjectMessage()
            {
                Property1_string  = "hello world!",
                Property2_int     = 123,
                Property3_decimal = 12.3M
            }).Execute();

            Utilities.WaitFor(ref receivedObject);
            //Assert
            Assert.AreEqual("hello world!", receivedObject.Property1_string);
            Assert.AreEqual(123, receivedObject.Property2_int);
            Assert.AreEqual(12.3M, receivedObject.Property3_decimal);
        }
Esempio n. 6
0
        public void TCPClient_SendUnreliably_ExceptionThrown()
        {
            //Arrange
            Client client           = null;
            Client clientDisconnect = null;

            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(Server);

            serverObjectTransport.Start("127.0.0.1", 0);

            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(Client1);

            clientObjectTransport.OnClientDisconnect(c => clientDisconnect = c);
            clientObjectTransport.Start("127.0.0.1", Server.LocalPort);

            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 1);

            client = clientObjectTransport.GetConnectedClients().First();
            Utilities.WaitFor(ref client);

            var message = new MockObjectMessage();

            //Act

            clientObjectTransport.Send(message)
            .Unreliable()
            .Execute();
        }
Esempio n. 7
0
        public void TCPNetwork_SendAndReplyMessage_ResponseIsCalled()
        {
            //Arrange
            Client client           = null;
            Client clientDisconnect = null;

            server = new TCPServerChannel("127.0.0.1", 0);
            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(server);

            tcpclient = new TCPClientChannel("127.0.0.1", server.Port);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(tcpclient);

            clientObjectTransport.OnClientDisconnect(c => clientDisconnect = c);
            client = clientObjectTransport.GetConnectedClients().First();

            Utilities.WaitFor(ref client);
            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 1);

            //Act
            serverObjectTransport.Receive <MockObjectMessage>()
            .Reply((o) => { return(o); })
            .Execute();


            var mockObject = new MockObjectMessage()
            {
                Property1_string = "Mock Object"
            };
            MockObjectMessage responseObject = null;

            clientObjectTransport.Send(mockObject)
            .Response <MockObjectMessage>((r) => { responseObject = r; })
            .Execute();

            Utilities.WaitFor(ref responseObject);

            //Assert
            Assert.AreEqual(responseObject.Property1_string, "Mock Object");
        }
Esempio n. 8
0
        public void UDPServer_SendObject_CorrectObjectSent()
        {
            //Arrange
            MockObjectMessage receivedObject = null;

            udpServer = new UDPServerChannel("127.0.0.1", 0, 32);

            Client client = null;

            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpServer);

            serverObjectTransport.OnClientConnect(c => client = c);

            udpClient = new UDPClientChannel("127.0.0.1", udpServer.Port);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpClient);

            Utilities.WaitFor(ref client);

            //Act

            clientObjectTransport.Receive <MockObjectMessage>(o =>
                                                              receivedObject = o
                                                              ).Execute();

            serverObjectTransport.Send(new MockObjectMessage()
            {
                Property1_string  = "hello world!",
                Property2_int     = 123,
                Property3_decimal = 12.3M
            })
            .To(client)
            .Execute();

            Utilities.WaitFor(ref receivedObject);
            //Assert
            Assert.AreEqual("hello world!", receivedObject.Property1_string);
            Assert.AreEqual(123, receivedObject.Property2_int);
            Assert.AreEqual(12.3M, receivedObject.Property3_decimal);
        }