public void ConfirmGameRegistrationGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\n" + "<ConfirmGameRegistration xmlns = \"https://se2.mini.pw.edu.pl/17-results/\" gameId = \"1\"/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(ConfirmGameRegistrationGM)); }
public void PlayerDisconnectedGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<PlayerDisconnected playerId=\"34\" xmlns=\"https://se2.mini.pw.edu.pl/17-results/\" />"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(PlayerDisconnectedGM)); }
public void TestPieceGMest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<TestPiece xmlns=\"https://se2.mini.pw.edu.pl/17-results/\"\n" + "gameId=\"1\"\n" + "playerGuid=\"c094cab7-da7b-457f-89e5-a5c51756035f\"/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(TestPieceGM)); }
public void AcceptExchangeRequestGMTest() { string xml = "<?xml version = \"1.0\" encoding = \"utf-8\" ?>\n" + "<AcceptExchangeRequest xmlns = \"https://se2.mini.pw.edu.pl/17-results/\"\n" + "playerId = \"1\"\n" + "senderPlayerId = \"2\"\n" + "/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(AcceptExchangeRequestGM)); }
public void AuthorizeKnowledgeExchangeGMGMTest() { string xml = "<?xml version = \"1.0\" encoding = \"utf-8\"?>\n" + "<AuthorizeKnowledgeExchange xmlns = \"https://se2.mini.pw.edu.pl/17-results/\"\n" + "withPlayerId = \"2\"\n" + "gameId = \"1\"\n" + "playerGuid = \"c1797885-8773-43ea-b454-d78315341a02\"\n" + "/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(AuthorizeKnowledgeExchangeGM)); }
public void RejectKnowledgeExchangeGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RejectKnowledgeExchange xmlns=\"https://se2.mini.pw.edu.pl/17-results/\"\n" + "permanent=\"false\"\n" + "playerId=\"1\"\n" + "senderPlayerId=\"2\"\n" + "playerGuid=\"c094cab7-da7b-457f-89e5-a5c51756035f\"\n" + "/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(RejectKnowledgeExchangeGM)); }
public void JoinGameGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<JoinGame\n" + "xmlns=\"https://se2.mini.pw.edu.pl/17-results/\"\n" + "gameName=\"Easy game\"\n" + "preferredRole=\"leader\"\n" + "preferredTeam=\"blue\"/>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(JoinGameGM)); }
public void ProcessHandleTestPieceRequestNoPiece() { InitGameMaster(); var player = GetPlayer("testGUID-0001", 10, TeamColour.red, ActionType.TestPiece); gameMaster.RegisterPlayer(player, "testGUID-0001"); GameArea.GameObjects.Piece p = gameMaster.GetPieceById(0); TestPieceGM data = new TestPieceGM("testGUID-0001", 0); string[] msg = data.Process(gameMaster); DataGM obj = (DataGM)GMReader.GetObjectFromXML(msg[0]); Assert.AreEqual(0, obj.Pieces.Length); }
public void ProcessDiscoverRequest() { InitGameMaster(); var player = GetPlayer("testGUID-0001", 10, TeamColour.blue, ActionType.TestPiece); gameMaster.RegisterPlayer(player, "testGUID-0001"); player.SetLocation(1, 5); gameMaster.SetAbsolutePlayerLocation(1, 5, "testGUID-0001"); DiscoverGM data = new DiscoverGM("testGUID-0001", 0); string[] msg = data.Process(gameMaster); DataGM obj = (DataGM)GMReader.GetObjectFromXML(msg[0]); Assert.AreEqual(8, obj.Tasks.Length); Assert.AreEqual(0, obj.Goals.Length); }
public void DataGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<Data xmlns = \"https://se2.mini.pw.edu.pl/17-results/\"\n" + "playerId = \"1\"\n" + "gameFinished=\"false\">\n" + "<TaskFields>\n" + "<TaskField x=\"1\" y=\"5\" timestamp=\"2017-02-23T17:20:11\"\n" + "distanceToPiece=\"5\" />\n" + "</TaskFields>\n" + "<PlayerLocation x=\"1\" y=\"5\" />\n" + "</Data>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(DataGM)); }
public void EndRead(IAsyncResult result) { var buffer = (byte[])result.AsyncState; if (clientSocket.Connected) { try { var ns = clientSocket.GetStream(); var bytesAvailable = ns.EndRead(result); var messages = Encoding.ASCII.GetString(buffer).Split((char)23); if (messages != null) { foreach (var message in messages.Select(q => q.Trim('\0'))) { logger.Log(message); ConsoleWriter.Show("GameMaster read: \n" + message + "\n"); var msgObject = GMReader.GetObjectFromXML(message); if (msgObject != null) { messageManager.ProcessMessage(msgObject); } else { ConsoleWriter.Warning("Could not obtain object from message: \n" + message); } } } BeginRead(); } catch (Exception e) { ConsoleWriter.Error("Error while handling message from communication server." + "\n Error message: \n" + e.ToString() + "\n"); GameMaster.State = GameMasterState.GameOver; } } else { ConsoleWriter.Warning("Communication server connection lost\n"); GameMaster.State = GameMasterState.GameOver; } }
public void SuggestActionGMTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<SuggestAction xmlns=\"https://se2.mini.pw.edu.pl/17-results/\"\n" + "senderPlayerId=\"1\"\n" + "playerId=\"2\"\n" + "gameId=\"1\"\n" + "playerGuid=\"c1797885-8773-43ea-b454-d78315341a02\">\n" + "<TaskFields>\n" + "<TaskField x=\"1\" y=\"2\" distanceToPiece=\"-1\" timestamp=\"2018-01-02T23:59:56\"/>\n" + "<TaskField x=\"3\" y=\"5\" distanceToPiece=\"-1\" timestamp=\"2018-01-02T23:59:56\"/>]n" + "</TaskFields>\n" + "<GoalFields>\n" + "<GoalField x=\"0\" y=\"0\" type=\"unknown\" team=\"blue\" timestamp=\"2018-01-02T23:59:56\"/>\n" + "<GoalField x=\"1\" y=\"0\" type=\"unknown\" team=\"blue\" timestamp=\"2018-01-02T23:59:56\"/>\n" + "</GoalFields>\n" + "</SuggestAction>"; var obj = GMReader.GetObjectFromXML(xml); Assert.IsNotNull(obj); Assert.IsTrue(obj.GetType() == typeof(SuggestActionGM)); }
public void ProcessHandleTestPieceRequestNormal() { InitGameMaster(); var player = GetPlayer("testGUID-0001", 10, TeamColour.red, ActionType.TestPiece); //gameMaster.RegisterPlayer(player); GameArea.GameObjects.Piece p = gameMaster.GetPieceById(0); var messagePieceKnown = new Piece(p.Type, p.ID) { timestamp = DateTime.Now, }; EquipPlayerWithPiece(messagePieceKnown, player); TestPieceGM data = new TestPieceGM("testGUID-0001", 0); string[] msg = data.Process(gameMaster); DataGM obj = (DataGM)GMReader.GetObjectFromXML(msg[0]); Assert.AreEqual(1, obj.Pieces.Length); Assert.AreEqual(p.Type, obj.Pieces[0].Type); }