Exemple #1
0
        public void TestClientJoinGameOnSameServer()
        {
            string DummyRoomID = "Dummy Room";

            Client ClientTest = new Client();

            ClientTest.ChangeHost(MockClientToServerConnection);
            Server ServerTest = new Server(new DummyDataManager(DummyRoomID));

            ServerTest.OnClientConnected(MockServerToClientConnection);

            DicServerOnlineScripts.Add("Create Room", new CreateRoomScriptServer(ServerTest));
            DicClientOnlineScripts.Add("Create Room", new CreateRoomScriptClient(""));
            DicServerOnlineScripts.Add("Send Room Information", new SendRoomIDScriptServer(""));
            DicClientOnlineScripts.Add("Send Room Information", new DummySendRoomInformationScriptClient(ClientTest, DummyRoomID));

            //Create Room
            ClientTest.CreateRoom("");
            ServerTest.UpdatePlayers();
            ClientTest.Update();
            Assert.AreEqual(0, ServerTest.ListPlayer.Count);
            Assert.AreEqual(DummyRoomID, ClientTest.RoomID);

            DicServerOnlineScripts.Add("Ask Start Game", new DummyAskStartGameScriptServer(ServerTest, ClientTest.RoomID));
            DicClientOnlineScripts.Add("Ask Start Game", new AskStartGameScriptClient());
            DicClientOnlineScripts.Add("Start Game", new DummyStartGameScriptClient(ClientTest));

            //Start Game
            ClientTest.StartGame();
            ServerTest.UpdatePlayers();
            Assert.IsNotNull(ServerTest.DicLocalRoom[DummyRoomID].CurrentGame);
            ClientTest.Update();
            Assert.IsNotNull(ClientTest.CurrentGame);

            //Client 2 connect to the server
            var DicClient2OnlineScripts = new Dictionary <string, OnlineScript>();
            List <OnlineScript>   ListClient2ToServerScriptSent = new List <OnlineScript>();
            List <OnlineScript>   ListServerToClient2ScriptSent = new List <OnlineScript>();
            DummyOnlineConnection MockServerToClient2Connection = new DummyOnlineConnection("MockServerToClient2Connection", DicServerOnlineScripts, ListClient2ToServerScriptSent, ListServerToClient2ScriptSent);
            DummyOnlineConnection MockClient2ToServerConnection = new DummyOnlineConnection("MockClient2ToServerConnection", DicClient2OnlineScripts, ListServerToClient2ScriptSent, ListClient2ToServerScriptSent);

            Client ClientTest2 = new Client();

            ClientTest2.ChangeHost(MockClient2ToServerConnection);
            ServerTest.OnClientConnected(MockServerToClient2Connection);
            Assert.AreEqual(1, ServerTest.ListPlayer.Count);

            //Client 2 join the room
            DicServerOnlineScripts.Add("Ask Join Room", new DummyAskJoinRoomScriptServer(ServerTest, DummyRoomID));
            DicClient2OnlineScripts.Add("Join Room Local", new DummyJoinRoomLocalScriptClient(ClientTest2, DummyRoomID, true));
            DicClient2OnlineScripts.Add("Start Game", new DummyStartGameScriptClient(ClientTest2));
            ClientTest2.JoinRoom(DummyRoomID);
            Assert.IsNull(ClientTest2.RoomID);
            ServerTest.UpdatePlayers();
            Assert.AreEqual(0, ServerTest.ListPlayer.Count);
            Assert.AreEqual(2, ServerTest.DicLocalRoom[DummyRoomID].Room.ListOnlinePlayer.Count);
            ClientTest2.Update();
            Assert.AreEqual(DummyRoomID, ClientTest2.RoomID);
            Assert.IsNotNull(ClientTest2.CurrentGame);
        }
Exemple #2
0
        public void TestClientServerTransferWhileInRoom()
        {
            string DummyRoomID = "Dummy Room";

            Client ClientTest = new Client();

            DicServerOnlineScripts.Add("Redirect", new RedirectScriptServer());
            DicClientOnlineScripts.Add("Redirect", new DummyRedirectScriptClient(ClientTest, MockClientToServerManagerConnection));

            Master MasterTest = new Master();

            ClientTest.ChangeHost(MockClientToMasterConnection);

            MasterTest.OnClientConnected(MockMasterToClientConnection);

            ClientTest.Update();

            DicClientOnlineScripts["Redirect"] = new DummyRedirectScriptClient(ClientTest, MockClientToServerConnection);

            ServerManager ServerManagerTest = new ServerManager();

            ServerManagerTest.OnClientConnected(MockServerManagerToClientConnection);
            ClientTest.Update();
            Assert.AreEqual(MockClientToServerConnection, ClientTest.Host);

            Server ServerTest = new Server(new DummyDataManager(DummyRoomID));

            ServerTest.OnClientConnected(MockServerToClientConnection);

            DicServerOnlineScripts.Add("Create Room", new CreateRoomScriptServer(ServerTest));
            DicClientOnlineScripts.Add("Create Room", new CreateRoomScriptClient(""));
            DicServerOnlineScripts.Add("Send Room Information", new SendRoomIDScriptServer(""));
            DicClientOnlineScripts.Add("Send Room Information", new DummySendRoomInformationScriptClient(ClientTest, DummyRoomID));

            //Create Room
            ClientTest.CreateRoom("");
            ServerTest.UpdatePlayers();
            ClientTest.Update();
            Assert.AreEqual(0, ServerTest.ListPlayer.Count);
            Assert.AreEqual(DummyRoomID, ClientTest.RoomID);

            DicServerOnlineScripts.Add("Ask Start Game", new DummyAskStartGameScriptServer(ServerTest, ClientTest.RoomID));
            DicClientOnlineScripts.Add("Ask Start Game", new AskStartGameScriptClient());
            DicClientOnlineScripts.Add("Start Game", new DummyStartGameScriptClient(ClientTest));

            //Start Game
            ClientTest.StartGame();
            ServerTest.UpdatePlayers();
            Assert.IsNotNull(ServerTest.DicLocalRoom[ClientTest.RoomID].CurrentGame);
            ClientTest.Update();
            Assert.IsNotNull(ClientTest.CurrentGame);

            //Lose connection to Server, connect back to Server Manager
            MockClientToServerConnection.Connected = false;
            ClientTest.Update();
            Assert.AreEqual(MockClientToServerManagerConnection, ClientTest.Host);
            Assert.IsNull(ClientTest.LastTopLevel);

            //Get new Server
            MockServerToClientConnection.Clear();
            MockClientToServerConnection.Clear();
            ServerTest = new Server(new DummyDataManager(DummyRoomID));
            ServerTest.DicAllRoom.Add(DummyRoomID, new RoomInformations(DummyRoomID, "", "", 0));

            MockClientToServerConnection.Connected = true;
            ServerManagerTest.OnClientConnected(MockServerManagerToClientConnection);
            ClientTest.Update();
            Assert.AreEqual(MockClientToServerConnection, ClientTest.Host);

            ServerTest.OnClientConnected(MockServerToClientConnection);
            Assert.IsFalse(ServerTest.DicLocalRoom.ContainsKey(ClientTest.RoomID));

            //Send Server the game data
            DicServerOnlineScripts.Add("Transfer Room", new TransferRoomScriptServer(ServerTest, DummyRoomID));
            ServerTest.UpdatePlayers();
            Assert.AreEqual(1, ServerTest.DicTransferingRoom.Count);

            DicClientOnlineScripts.Add("Ask Game Data", new AskGameDataScriptClient(ClientTest));
            ClientTest.Update();

            DicServerOnlineScripts.Add("Send Game Data", new DummySendGameDataScriptServer(ServerTest, DummyRoomID));
            ServerTest.UpdatePlayers();

            //Wait for sync
            Assert.AreEqual(0, ServerTest.DicTransferingRoom.Count);
            Assert.AreEqual(1, ServerTest.DicLocalRoom.Count);
            Assert.IsNotNull(ServerTest.DicLocalRoom[ClientTest.RoomID].CurrentGame);
        }