コード例 #1
0
        public void RespondJoinLobbyRespondingToRetreis()
        {
            //Create a SubSystem with dummy factory.
            dummyCoversationFactory dumConvoFact  = new dummyCoversationFactory();
            LobbyAppState           lobbyAppState = new LobbyAppState();
            SubSystem commSubSys = new SubSystem(dumConvoFact, lobbyAppState);
            //Note: we dont want to start the threads of the subSystem.

            //Create Conversation
            RespondJoinLobby resJoinLobbyConvo = new RespondJoinLobby();

            resJoinLobbyConvo.SubSystem      = commSubSys;
            resJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            //Create fake incoming env.
            string   strXML      = "<RSAKeyValue><Modulus>CmZ5Hasfdldkjrjghtyremeddfjdn4738ejdjHGTFEeeeeeeeeeefjdkeldkfjguehendjeufi8ejdmGFDSqaalskebejdu==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
            Envelope IncomingEnv = new Envelope(new GMJoinLobbyMessage(strXML, new Identifier(0, 1), new Identifier(0, 1), 1111), new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111), new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222), false);

            //Set the incoming env.
            resJoinLobbyConvo.IncomingEnvelope = IncomingEnv;
            resJoinLobbyConvo.recievedMessagesDict.TryAdd(IncomingEnv.Message.MessageNumber.ToString(), IncomingEnv);

            //Start the conversation
            resJoinLobbyConvo.Launch();

            Thread.Sleep(500);

            //check the outgoing message.
            Assert.IsTrue(commSubSys.outQueue.Count >= 1);

            //Give a duplicate message.
            resJoinLobbyConvo.Process(IncomingEnv);

            Thread.Sleep(500);

            //check the outgoing message.
            Assert.IsTrue(commSubSys.outQueue.Count >= 2);

            //get count of outgoing messages for later.
            int countOfOutGoingMessages = commSubSys.outQueue.Count;

            //Wait for timeout time
            Thread.Sleep(2000);

            //Check that there are no new messages.
            Assert.IsTrue(countOfOutGoingMessages == commSubSys.outQueue.Count);

            //Cheack that thread has ended.
            resJoinLobbyConvo.Process(IncomingEnv); //If thread was running outgoing messages should go up.
            Thread.Sleep(500);
            Assert.IsTrue(countOfOutGoingMessages == commSubSys.outQueue.Count);

            //Close the communicators for next test.
            commSubSys.udpcomm.closeCommunicator();
            commSubSys.tcpcomm.closeCommunicator();
        }
コード例 #2
0
        public void PLayerJoinLobbyFullProtocolTest()
        {
            //Create a SubSystem with dummy factory.
            dummyCoversationFactory dumConvoFact1 = new dummyCoversationFactory();
            LobbyAppState           lobbyAppState = new LobbyAppState();
            SubSystem commSubSysLobby             = new SubSystem(dumConvoFact1, lobbyAppState);

            WaitingRoom    waitingRoom      = new WaitingRoom();
            PlayerAppState playerAppState   = new PlayerAppState(waitingRoom);
            SubSystem      commSubSysPlayer = new SubSystem(dumConvoFact1, playerAppState);

            //Set the name of the player in the App State.
            playerAppState.playerName = "Tester Testerson";

            //get the initial process id. This test will check that the conversation changes it.
            int startingProcessId = commSubSysPlayer.ProcessID;

            //Create Initiator conversation
            PlayerJoinLobby PlayerJoinLobby = new PlayerJoinLobby();

            PlayerJoinLobby.SubSystem      = commSubSysPlayer;
            PlayerJoinLobby.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            ////Create Responder Conversation
            RespondJoinLobby resJoinLobbyConvo = new RespondJoinLobby();

            resJoinLobbyConvo.SubSystem      = commSubSysLobby;
            resJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222);

            //Start Initiator Conversation
            PlayerJoinLobby.Launch();

            //Wait for conversation to send message.
            Thread.Sleep(500);

            //Check for outgoing message.
            Assert.IsTrue(commSubSysPlayer.outQueue.Count >= 1);

            //Get message and put into responder conversation
            Envelope initiatorEnv;

            if (!commSubSysPlayer.outQueue.TryDequeue(out initiatorEnv))
            {
                Assert.Fail();
            }
            resJoinLobbyConvo.IncomingEnvelope = initiatorEnv;
            resJoinLobbyConvo.ConversationId   = initiatorEnv.Message.ConversationId;

            //Start the responder conversation
            resJoinLobbyConvo.Launch();

            //Wait for conversation to send message
            Thread.Sleep(500);

            //Check for outgoing message from responder conversation.
            Assert.IsTrue(commSubSysLobby.outQueue.Count >= 1);

            //Get responder reply and give to initiator.
            Envelope responderEnv;

            if (!commSubSysLobby.outQueue.TryDequeue(out responderEnv))
            {
                Assert.Fail();
            }
            PlayerJoinLobby.Process(responderEnv);

            //Check that the process Id was changed. Note: This is the
            Assert.IsTrue(startingProcessId == commSubSysPlayer.ProcessID);
            Console.WriteLine(startingProcessId);
            Console.WriteLine(commSubSysLobby.ProcessID);

            //Check that the GM was added to the Lobby.
            Assert.IsTrue(lobbyAppState.Pls.Count >= 1);

            //Close the communicators for next test.
            commSubSysLobby.udpcomm.closeCommunicator();
            commSubSysLobby.tcpcomm.closeCommunicator();
        }
コード例 #3
0
        public void GMJoinLobbyFullProtocolTest()
        {
            //Create a SubSystem with dummy factory.
            dummyCoversationFactory dumConvoFact1 = new dummyCoversationFactory();
            LobbyAppState           lobbyAppState = new LobbyAppState();
            GMAppState gMAppState   = new GMAppState();
            SubSystem  commSubSys1  = new SubSystem(dumConvoFact1, lobbyAppState);
            SubSystem  commSubSysGM = new SubSystem(dumConvoFact1, gMAppState, new IPEndPoint(IPAddress.Any, 3001), new IPEndPoint(IPAddress.Any, 3002));
            //dummyCoversationFactory dumConvoFact2 = new dummyCoversationFactory();
            //SubSystem commSubSys2;
            //Note: Its a little strange that we are only using one subsystem here. Using two wont work because we have hard coded the Sockets that UDP and TCP are using and we can't bind to the same sockets.
            //Note: we dont want to start the threads of the subSystem.

            //get the initial process id. This test will check that the conversation changes it.
            int startingProcessId = commSubSysGM.ProcessID;

            //Create Initiator conversation
            GMJoinLobby GMJoinLobbyConversation = new GMJoinLobby();

            GMJoinLobbyConversation.SubSystem      = commSubSysGM;
            GMJoinLobbyConversation.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            ////Create Responder Conversation
            RespondJoinLobby resJoinLobbyConvo = new RespondJoinLobby();

            resJoinLobbyConvo.SubSystem      = commSubSys1;
            resJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222);

            //Start Initiator Conversation
            GMJoinLobbyConversation.Launch();

            //Wait for conversation to send message.
            Thread.Sleep(500);

            //Check for outgoing message.
            Assert.IsTrue(commSubSysGM.outQueue.Count >= 1);

            //Get message and put into responder conversation
            Envelope initiatorEnv;

            if (!commSubSysGM.outQueue.TryDequeue(out initiatorEnv))
            {
                Assert.Fail();
            }
            initiatorEnv.From = commSubSysGM.udpcomm.GetEndPoint(); //Added to resolve a message.
            resJoinLobbyConvo.IncomingEnvelope = initiatorEnv;
            resJoinLobbyConvo.ConversationId   = initiatorEnv.Message.ConversationId;

            //Start the responder conversation
            resJoinLobbyConvo.Launch();

            //Wait for conversation to send message
            Thread.Sleep(500);

            //Check for outgoing message from responder conversation.
            Assert.IsTrue(commSubSys1.outQueue.Count >= 1);

            //Get responder reply and give to initiator.
            Envelope responderEnv;

            if (!commSubSys1.outQueue.TryDequeue(out responderEnv))
            {
                Assert.Fail();
            }
            GMJoinLobbyConversation.Process(responderEnv);

            //Check that the process Id was changed. Note: This is the
            Assert.IsTrue(startingProcessId == commSubSysGM.ProcessID);
            Console.WriteLine(startingProcessId);
            Console.WriteLine(commSubSysGM.ProcessID);

            //Check that the GM was added to the Lobby.
            Assert.IsTrue(lobbyAppState.GMs.Count >= 1);

            //Close the communicators for next test.
            commSubSys1.udpcomm.closeCommunicator();
            commSubSys1.tcpcomm.closeCommunicator();
        }