Exemplo n.º 1
0
        public void TestClientToServerThroughMasterConnection()
        {
            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();

            Assert.AreEqual(MockClientToServerManagerConnection, ClientTest.Host);
            DicClientOnlineScripts["Redirect"] = new DummyRedirectScriptClient(ClientTest, MockClientToServerConnection);

            ServerManager ServerManagerTest = new ServerManager();

            ServerManagerTest.OnClientConnected(MockServerManagerToClientConnection);

            ClientTest.Update();

            Assert.AreEqual(MockClientToServerConnection, ClientTest.Host);
            Assert.AreEqual(MockClientToServerManagerConnection, ClientTest.LastTopLevel);
        }
Exemplo n.º 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);
        }