public void UserApp_StartGameConversation_Test()
        {
            //--------------SET UP VARIABLES-------------------//
            RegistryData registryData = new RegistryData();

            RegistryData.GameInfo gameInfo = new RegistryData.GameInfo();

            TestAppWorker testAppWorker = new TestAppWorker(registryData);

            testAppWorker.StartTest();

            var gameManager = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            gameManager.Start();

            IPEndPoint registryEp    = new IPEndPoint(IPAddress.Loopback, testAppWorker.commFacility.udpCommunicator.Port);
            IPEndPoint gameManagerEp = new IPEndPoint(IPAddress.Loopback, gameManager.Port);

            gameInfo.RemoteEndPoint = gameManagerEp;
            gameInfo.GameActive     = false;

            Assert.IsTrue(registryData.AddGame(gameInfo));

            StartGameMessage msg1 = new StartGameMessage(1);
            Envelope         env1 = new Envelope(msg1, registryEp);

            //--------------TEST INITIAL SET UP AND SEND INITIAL MESSAGE-------------------//
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));
            Assert.IsFalse(gameInfo.GameActive);

            gameManager.Send(env1);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);

            // Make sure received message isn't null
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            // Make sure received message is AckMessage
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            AckMessage msg2 = _lastIncomingEnvelope1.message as AckMessage;

            Assert.IsNotNull(msg2);

            Assert.IsTrue(gameInfo.GameActive);
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            //--------------CLOSE EVERYTHING-------------------//
            testAppWorker.StopTest();
            gameManager.Stop();
        }
예제 #2
0
        public void UdpCommunicator_Multicast()
        {
            var commSender = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = NoOp
            };

            commSender.Start();

            var commReciever = new UdpCommunicator()
            {
                MinPort         = 5000,
                MaxPort         = 5000,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope5
            };

            commReciever.Start();

            Random rand   = new Random();
            short  gameId = (short)rand.Next(1, 1000);

            // Note, we can't test multiple receivers on the same host (localhost), because the
            // port number has to be the same for all receivers

            // Have the receivers join a Group Multicast address
            var multiCastAddress = new IPAddress(new byte[] { 224, 1, 1, 2 });

            commReciever.JoinMulticastGroup(multiCastAddress);

            // Send message to Group Multicast address
            var msg            = new StartGameMessage(gameId);
            var targetEndPoint = new IPEndPoint(IPAddress.Loopback, 5000);
            var env            = new Envelope(msg, targetEndPoint);

            commSender.Send(env);

            Thread.Sleep(100);

            Assert.AreNotSame(msg, _lastIncomingEnvelope5);
            Assert.IsNotNull(_lastIncomingEnvelope5);
            Assert.IsNotNull(_lastIncomingEnvelope5.message);
            Assert.AreEqual(msg.msgId, _lastIncomingEnvelope5.message.msgId);
            Assert.AreEqual(msg.convId, _lastIncomingEnvelope5.message.convId);
            StartGameMessage msg2 = _lastIncomingEnvelope5.message as StartGameMessage;

            Assert.IsNotNull(msg2);
            Assert.AreEqual(msg.GameId, msg2.GameId);

            commReciever.DropMulticastGroup(multiCastAddress);
            commReciever.Stop();
            commSender.Stop();
        }
        public void UserApp_JoinGameConversation_Test()
        {
            TestAppWorker testAppWorker = new TestAppWorker();

            testAppWorker.StartTest();

            var fakeRegistry = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            fakeRegistry.Start();

            IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Loopback, fakeRegistry.Port);

            Message  msg1 = new RequestGameMessage();
            Envelope env  = new Envelope(msg1, targetEndPoint);

            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            testAppWorker.commFacility.Process(env);

            Assert.IsNotNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            Thread.Sleep(100);

            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);
            Assert.AreEqual(msg1.msgId, _lastIncomingEnvelope1.message.msgId);
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            RequestGameMessage msg2 = _lastIncomingEnvelope1.message as RequestGameMessage;

            Assert.IsNotNull(msg2);

            GameInfoMessage msg3 = new GameInfoMessage(msg1.convId, 1, 1, "GMAddress", "UAAddress");

            Assert.AreNotSame((IPEndPoint)fakeRegistry._myUdpClient.Client.LocalEndPoint, _lastIncomingEnvelope1.remoteEndPoint);

            Envelope env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint);

            fakeRegistry.Send(env2);

            Thread.Sleep(100);

            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            fakeRegistry.Stop();
            testAppWorker.StopTest();
        }
예제 #4
0
        public void Registry_JoinGameConversation_Test()
        {
            IPEndPoint registryEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000);

            RegistryData  registryData  = new RegistryData();
            TestAppWorker testAppWorker = new TestAppWorker(registryData, registryEndPoint);

            testAppWorker.StartTest();

            var comm1 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            comm1.Start();

            Message  msg1 = new RequestGameMessage();
            Envelope env  = new Envelope(msg1, registryEndPoint);

            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));
            Assert.IsNull(registryData.GetAvailableGameManager());

            comm1.Send(env);

            Thread.Sleep(1000);

            /*
             * //The conversation happens to fast. After the sleep, the conv is already gone
             * Assert.IsNotNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));
             */

            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            GameInfoMessage msg2 = _lastIncomingEnvelope1.message as GameInfoMessage;

            Assert.IsNotNull(msg2);

            Assert.IsNotNull(registryData.GetAvailableGameManager());
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            //-------------STOPPING------------//
            testAppWorker.StopTest();
            comm1.Stop();
        }
예제 #5
0
        public void UdpSendReceiveTest()
        {
            var        testGuid = Guid.NewGuid();
            IPEndPoint ep       = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12000);
            Message    message  = new CanvasMessage()
            {
                ConversationId = new Tuple <Guid, short>(testGuid, 1),
                MessageNumber  = new Tuple <Guid, short>(testGuid, 1),
                CanvasId       = 1
            };
            Envelope envelope = new Envelope()
            {
                RemoteEP = ep, Message = message
            };
            UdpCommunicator communicator1 = new UdpCommunicator()
            {
                EnvelopeHandler = FirstEnvelope
            };

            communicator1.SetPort(12001);
            communicator1.Start();

            UdpCommunicator communicator2 = new UdpCommunicator()
            {
                EnvelopeHandler = SecondEnvelope
            };

            communicator2.SetPort(12000);
            communicator2.Start();

            Thread.Sleep(2000);
            communicator1.Send(envelope);
            Thread.Sleep(1000);

            Assert.IsNotNull(envelope2);
            Assert.IsNotNull(envelope2.Message);
            Assert.AreEqual(envelope.Message.ConversationId, envelope2.Message.ConversationId);
            Assert.AreEqual(envelope.Message.MessageNumber, envelope2.Message.MessageNumber);
            Assert.AreEqual((envelope.Message as CanvasMessage).CanvasId, (envelope2.Message as CanvasMessage).CanvasId);
        }
예제 #6
0
        public void UserApp_StartGameConversation_Test()
        {
            //--------------SET UP VARIABLES-------------------//
            UserInfo userInfo = new UserInfo()
            {
                PlayerId        = 0,
                CurrentPlayerId = -1,
                AcceptUserInput = false
            };

            TestAppWorker testAppWorker = new TestAppWorker(userInfo);

            testAppWorker.StartTest();

            var gameManager = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            gameManager.Start();

            IPEndPoint userAppEp = new IPEndPoint(IPAddress.Loopback, testAppWorker.commFacility.udpCommunicator.Port);

            testAppWorker.UserInfo.GameManagerEP = new IPEndPoint(IPAddress.Loopback, gameManager.Port);

            StartGameMessage msg1 = new StartGameMessage(1);
            Envelope         env1 = new Envelope(msg1, userAppEp);

            //--------------TEST INITIAL SET UP AND SEND INITIAL MESSAGE-------------------//
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            gameManager.Send(env1);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.IsTrue(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId) is StartGameConversation);

            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);

            // Make sure received message isn't null
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            // Make sure received message is AckMessage
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            AckMessage msg2 = _lastIncomingEnvelope1.message as AckMessage;

            Assert.IsNotNull(msg2);

            //--------------SEND START GAME STATE UPDATE MESSAGE-------------------//
            GameStateUpdateMessage msg3 = new GameStateUpdateMessage(msg1.convId, 1, 0, new short[4], new short[4], new short[84], 0, "TEST APP MOVE");
            Envelope env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint);

            _lastIncomingEnvelope1 = null;

            // User should not know it is their turn
            Assert.IsFalse(userInfo.IsTurn);

            gameManager.Send(env2);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            // User should know it is their turn
            Assert.IsTrue(userInfo.IsTurn);

            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);

            // Make sure received message isn't null
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            // Make sure received message is AckMessage
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);

            AckMessage msg4 = _lastIncomingEnvelope1.message as AckMessage;

            Assert.IsNotNull(msg4);

            //--------------SEND FIRST PLAYER GO ACK MESSAGE-------------------//
            AckMessage msg5 = new AckMessage(msg1.convId, msg1.GameId);
            Envelope   env3 = new Envelope(msg5, _lastIncomingEnvelope1.remoteEndPoint);

            _lastIncomingEnvelope1 = null;

            // Check user isn't able to input
            Assert.IsFalse(userInfo.AcceptUserInput);

            gameManager.Send(env3);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            // Check user is able to input
            Assert.IsTrue(userInfo.AcceptUserInput);

            // Check conversation ended
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            //--------------CLOSE EVERYTHING-------------------//
            testAppWorker.StopTest();
            gameManager.Stop();
        }
예제 #7
0
        public void UdpCommunicator_SimpleSendReceives()
        {
            var comm1 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            comm1.Start();

            var comm2 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope2
            };

            comm2.Start();

            Random rand   = new Random();
            short  gameId = (short)rand.Next(1, 1000);

            StartGameMessage msg            = new StartGameMessage(gameId);
            IPEndPoint       targetEndPoint = new IPEndPoint(IPAddress.Loopback, comm2.Port);
            Envelope         env            = new Envelope(msg, targetEndPoint);

            comm1.Send(env);

            Thread.Sleep(100);

            Assert.AreNotSame(msg, _lastIncomingEnvelope2);
            Assert.IsNotNull(_lastIncomingEnvelope2);
            Assert.IsNotNull(_lastIncomingEnvelope2.message);
            Assert.AreEqual(msg.msgId, _lastIncomingEnvelope2.message.msgId);
            Assert.AreEqual(msg.convId, _lastIncomingEnvelope2.message.convId);
            StartGameMessage msg2 = _lastIncomingEnvelope2.message as StartGameMessage;

            Assert.IsNotNull(msg2);
            Assert.AreEqual(msg.GameId, msg2.GameId);

            AckMessage msg3 = new AckMessage(msg2.convId, msg2.GameId);

            Assert.AreNotEqual(msg2.msgId, msg3.msgId);
            Assert.AreEqual(msg2.convId, msg3.convId);
            targetEndPoint = new IPEndPoint(IPAddress.Loopback, comm1.Port);
            Envelope env3 = new Envelope(msg3, targetEndPoint);

            comm2.Send(env3);

            Thread.Sleep(100);

            Assert.AreNotSame(msg3, _lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);
            Assert.AreEqual(msg3.msgId, _lastIncomingEnvelope1.message.msgId);
            Assert.AreEqual(msg3.convId, _lastIncomingEnvelope1.message.convId);
            AckMessage msg4 = _lastIncomingEnvelope1.message as AckMessage;

            Assert.IsNotNull(msg4);
            Assert.AreEqual(msg3.GameId, msg4.GameId);

            comm1.Stop();
            comm2.Stop();
        }
예제 #8
0
        public void UdpCommunicator_SendingOfBadEnvelopes()
        {
            var commSender = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = NoOp
            };

            commSender.Start();

            var commReciever = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope3
            };

            commReciever.Start();

            Random rand   = new Random();
            short  gameId = (short)rand.Next(1, 1000);

            // Send a message to a non-existant remote end point
            //     Expected behavior - no error, but no delivery
            var msg            = new StartGameMessage(gameId);
            var targetEndPoint = new IPEndPoint(IPAddress.Loopback, 1012);
            var env            = new Envelope(msg, targetEndPoint);
            var error          = commSender.Send(env);

            Assert.IsNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            // Send a message to a remote end point with a 0 for the port
            //     Expected behavior - error
            env.remoteEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
            error = commSender.Send(env);
            Assert.IsNotNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            // Send a message to a remote end point with a 0.0.0.0 for the address
            //     Expected behavior - error
            env.remoteEndPoint = new IPEndPoint(IPAddress.Any, 1245);
            error = commSender.Send(env);
            Assert.IsNotNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            // Send to a null remote end point
            //      Expected behavior -- error
            env.remoteEndPoint = null;
            error = commSender.Send(env);
            Assert.IsNotNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            // Send a null message
            //      Expected behavior -- error
            env.message        = null;
            env.remoteEndPoint = new IPEndPoint(IPAddress.Loopback, 1012);
            error = commSender.Send(env);
            Assert.IsNotNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            // Send a null envelope
            //      Expected behavior -- error
            error = commSender.Send(null);
            Assert.IsNotNull(error);
            Assert.IsNull(_lastIncomingEnvelope3);

            commSender.Stop();
            commReciever.Stop();
        }
        public void GameManager_StartGameConversation_Test()
        {
            //--------------SET UP VARIABLES-------------------//
            string[]      args          = { "Test Arguments" };
            GameInfo      gameInfo      = new GameInfo();
            TestAppWorker testAppWorker = new TestAppWorker(args, gameInfo);

            testAppWorker.StartTest();

            var ua1 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope1
            };

            var ua2 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope2
            };

            var ua3 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope3
            };

            var ua4 = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope4
            };

            var registry = new UdpCommunicator()
            {
                MinPort         = 10000,
                MaxPort         = 10999,
                Timeout         = 1000,
                EnvelopeHandler = ProcessEnvelope5
            };

            ua1.Start();
            ua2.Start();
            ua3.Start();
            ua4.Start();
            registry.Start();

            IPEndPoint ua1Ep      = new IPEndPoint(IPAddress.Loopback, ua1.Port);
            IPEndPoint ua2Ep      = new IPEndPoint(IPAddress.Loopback, ua2.Port);
            IPEndPoint ua3Ep      = new IPEndPoint(IPAddress.Loopback, ua3.Port);
            IPEndPoint ua4Ep      = new IPEndPoint(IPAddress.Loopback, ua4.Port);
            IPEndPoint registryEp = new IPEndPoint(IPAddress.Loopback, registry.Port);

            Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(0, ua1Ep));
            Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(1, ua2Ep));
            Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(2, ua3Ep));
            Assert.IsTrue(gameInfo.UserEndPoints.TryAdd(3, ua4Ep));

            StartGameMessage msg1 = new StartGameMessage(1);
            Envelope         env1 = new Envelope(msg1, registryEp);

            //--------------TEST INITIAL SET UP AND START CONVERSATION-------------------//
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            testAppWorker.commFacility.Process(env1);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.IsTrue(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId) is StartGameConversation);

            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope2);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope3);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope4);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope5);

            // Make sure received messages aren't null
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            Assert.IsNotNull(_lastIncomingEnvelope2);
            Assert.IsNotNull(_lastIncomingEnvelope2.message);

            Assert.IsNotNull(_lastIncomingEnvelope3);
            Assert.IsNotNull(_lastIncomingEnvelope3.message);

            Assert.IsNotNull(_lastIncomingEnvelope4);
            Assert.IsNotNull(_lastIncomingEnvelope4.message);

            Assert.IsNotNull(_lastIncomingEnvelope5);
            Assert.IsNotNull(_lastIncomingEnvelope5.message);

            // Make sure received messages are StartGameMessages
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);
            StartGameMessage msg2 = _lastIncomingEnvelope1.message as StartGameMessage;

            Assert.IsNotNull(msg2);

            msg2 = _lastIncomingEnvelope2.message as StartGameMessage;
            Assert.IsNotNull(msg2);

            msg2 = _lastIncomingEnvelope3.message as StartGameMessage;
            Assert.IsNotNull(msg2);

            msg2 = _lastIncomingEnvelope4.message as StartGameMessage;
            Assert.IsNotNull(msg2);

            msg2 = _lastIncomingEnvelope5.message as StartGameMessage;
            Assert.IsNotNull(msg2);

            //--------------SEND START ACK MESSAGE-------------------//
            AckMessage msg3 = new AckMessage(msg1.convId, msg1.GameId);
            Envelope   env2 = new Envelope(msg3, _lastIncomingEnvelope1.remoteEndPoint);

            _lastIncomingEnvelope1 = null;
            _lastIncomingEnvelope2 = null;
            _lastIncomingEnvelope3 = null;
            _lastIncomingEnvelope4 = null;
            _lastIncomingEnvelope5 = null;

            ua1.Send(env2);
            ua2.Send(env2);
            ua3.Send(env2);
            ua4.Send(env2);
            registry.Send(env2);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope2);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope3);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope4);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope5);

            // Make sure received messages aren't null, except registry's
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            Assert.IsNotNull(_lastIncomingEnvelope2);
            Assert.IsNotNull(_lastIncomingEnvelope2.message);

            Assert.IsNotNull(_lastIncomingEnvelope3);
            Assert.IsNotNull(_lastIncomingEnvelope3.message);

            Assert.IsNotNull(_lastIncomingEnvelope4);
            Assert.IsNotNull(_lastIncomingEnvelope4.message);

            Assert.IsNull(_lastIncomingEnvelope5);

            // Make sure received messages are StartGameMessages
            Assert.AreEqual(msg1.convId, _lastIncomingEnvelope1.message.convId);

            GameStateUpdateMessage msg4;

            msg4 = _lastIncomingEnvelope1.message as GameStateUpdateMessage;
            Assert.IsNotNull(msg4);

            msg4 = _lastIncomingEnvelope2.message as GameStateUpdateMessage;
            Assert.IsNotNull(msg4);

            msg4 = _lastIncomingEnvelope3.message as GameStateUpdateMessage;
            Assert.IsNotNull(msg4);

            msg4 = _lastIncomingEnvelope4.message as GameStateUpdateMessage;
            Assert.IsNotNull(msg4);

            //--------------SEND UPDATE ACK MESSAGE-------------------//
            AckMessage msg5 = new AckMessage(msg1.convId, msg1.GameId);
            Envelope   env3 = new Envelope(msg5, _lastIncomingEnvelope1.remoteEndPoint);

            _lastIncomingEnvelope1 = null;
            _lastIncomingEnvelope2 = null;
            _lastIncomingEnvelope3 = null;
            _lastIncomingEnvelope4 = null;
            _lastIncomingEnvelope5 = null;

            ua1.Send(env3);
            ua2.Send(env3);
            ua3.Send(env3);
            ua4.Send(env3);

            Thread.Sleep(1000);

            //--------------TEST OUTCOME-------------------//
            Assert.AreNotSame(msg1, _lastIncomingEnvelope1);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope2);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope3);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope4);
            Assert.AreNotSame(msg1, _lastIncomingEnvelope5);

            // Make sure all received messages are null except ua1's
            Assert.IsNotNull(_lastIncomingEnvelope1);
            Assert.IsNotNull(_lastIncomingEnvelope1.message);

            Assert.IsNull(_lastIncomingEnvelope2);

            Assert.IsNull(_lastIncomingEnvelope3);

            Assert.IsNull(_lastIncomingEnvelope4);

            Assert.IsNull(_lastIncomingEnvelope5);

            // Check conversation ended
            Assert.IsNull(testAppWorker.commFacility.convDictionary.GetConv(msg1.convId));

            //--------------CLOSE EVERYTHING-------------------//
            testAppWorker.StopTest();
            ua1.Stop();
            ua2.Stop();
            ua3.Stop();
            ua4.Stop();
            registry.Stop();
        }