public void TravelTest(TestClient target, string charID, string targetFief, string[] travelInstructions) { DisplayMessages fiefError, charError; Character character = Utility_Methods.GetCharacter(charID, out charError); Client client = Globals_Server.Clients[target.playerID]; Fief oldFief = null; if (character != null) { oldFief = character.location; } target.Move(charID, targetFief, travelInstructions); Task <ProtoMessage> responseTask = target.GetReply(); responseTask.Wait(); ProtoMessage reply = responseTask.Result; // Travelling will be done either by series of instructions or by choosing fief- ensure at least one is being used! if (string.IsNullOrWhiteSpace(targetFief)) { if (travelInstructions == null) { Assert.AreEqual(DisplayMessages.ErrorGenericFiefUnidentified, reply.ResponseType); return; } } Fief f = Utility_Methods.GetFief(targetFief, out fiefError); if (!string.IsNullOrWhiteSpace(targetFief) && f == null) { Assert.AreEqual(fiefError, reply.ResponseType); return; } // Note- if the travel instructions are invalid the server will still move the client up until the first invalid instruction, and will then send an update stating that there was a problem with the movement instructions if (character == null) { Assert.AreEqual(charError, reply.ResponseType); return; } if (character.GetPlayerCharacter() != client.myPlayerCharacter) { Assert.AreEqual(DisplayMessages.ErrorGenericUnauthorised, reply.ResponseType); return; } if (f != null && character.days < oldFief.getTravelCost(f)) { Assert.AreEqual(DisplayMessages.CharacterDaysJourney, reply.ResponseType); return; } ProtoFief fiefDetails = reply as ProtoFief; Assert.IsNotNull(fiefDetails); }
/// <summary>Test stub for LogIn(String, String, Byte[])</summary> public void LogInTest( TestClient client, string user, string pass, byte[] key ) { client.LogInAndConnect(user, pass, key); // If username not recognised, expect to be disconnected if (string.IsNullOrEmpty(user) || !Utility_Methods.CheckStringValid("combined", user) || !LogInManager.users.ContainsKey(user)) { Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString()); return; } // If password is incorrect, expect an error Tuple <byte[], byte[]> hashNsalt = LogInManager.users[user]; byte[] hash; if (pass == null) { hash = null; } else { hash = LogInManager.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass), hashNsalt.Item2); } if (hash == null || !hashNsalt.Item1.SequenceEqual(hash) || key == null || key.Length < 5) { Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString()); Assert.IsFalse(Server.ContainsConnection(user)); } else { // If the login was successful, expecting a ProtoLogin followed by a ProtoClient back Task <ProtoMessage> getReply = client.GetReply(); getReply.Wait(); ProtoMessage reply = getReply.Result; Assert.AreEqual(reply.GetType(), typeof(ProtoLogIn)); while (!client.IsConnectedAndLoggedIn()) { Thread.Sleep(0); } // If login was successful, the client should be in the list of registered observers Assert.IsTrue(Globals_Game.IsObserver(Globals_Server.Clients[user])); Assert.IsTrue(Server.ContainsConnection(user)); } }
/// <summary>Test stub for MaintainArmy(String)</summary> public DisplayMessages MaintainArmyTest(TestClient target, string armyID) { Client client; if (!ValidClientState(target, out client)) { Assert.IsTrue(target.IsConnectedAndLoggedIn() == false); } int treasury = client.myPlayerCharacter.GetHomeFief().GetAvailableTreasury(true); uint armyMaintenanceCost = 0; bool isMaintained = false; DisplayMessages armyError; Army army = Utility_Methods.GetArmy(armyID, out armyError); if (army != null) { armyMaintenanceCost = army.getMaintenanceCost(); isMaintained = army.isMaintained; } target.MaintainArmy(armyID); var replyTask = target.GetReply(); if (!replyTask.Wait(5000)) { Assert.Fail("Timed out"); } var result = replyTask.Result; // if armyID is null or empty, or a bad format, get a MessageInvalid message if (string.IsNullOrWhiteSpace(armyID) || !Utility_Methods.ValidateArmyID(armyID)) { Assert.AreEqual(DisplayMessages.ErrorGenericMessageInvalid, result.ResponseType); return(result.ResponseType); } // If armyID is not a recognised army, get an ArmyUnidentified message if (!Globals_Game.armyMasterList.ContainsKey(armyID) || army == null) { Assert.AreEqual(DisplayMessages.ErrorGenericArmyUnidentified, result.ResponseType); return(result.ResponseType); } // If the player does not own the army, get an Unauthorised message if (army.GetOwner() != client.myPlayerCharacter) { Assert.AreEqual(DisplayMessages.ErrorGenericUnauthorised, result.ResponseType); return(result.ResponseType); } // If the army has already been maintained, expect a MaintainAlready message if (isMaintained) { Assert.AreEqual(DisplayMessages.ArmyMaintainedAlready, result.ResponseType); return(result.ResponseType); } // If don't have enough funds, if (treasury < armyMaintenanceCost) { Assert.AreEqual(DisplayMessages.ArmyMaintainInsufficientFunds, result.ResponseType); return(result.ResponseType); } // If all the checks pass, expect an army back ProtoArmy armyDetails = result as ProtoArmy; if (armyDetails == null) { Assert.Fail("Could not parse result to ProtoArmy"); } return(result.ResponseType); }