public void TearDown() { var client = ElasticSearchCommands.create_lowlevelclient(); var Spaceships = new object[] { new { index = new { _index = "spaceships", _type = "spaceship", _id = "0", } }, new { Name = "test0", Health = 100, Capacity = 100, Energy = 100, XCoordinate = 0, YCoordinate = 0, UserId = "0", Code = "1234567891234567" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "1", } }, new { Name = "test1", Health = 20, Capacity = 100, Energy = 100, XCoordinate = 20, YCoordinate = 20, UserId = "1", Code = "8273781009352487" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "2" } }, new { Name = "test2", Health = 100, Capacity = 100, Energy = 100, XCoordinate = 80, YCoordinate = 49, UserId = "2", Code = "1234566356352487" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "3" } }, new { Name = "test3", Health = 100, Capacity = 100, Energy = 100, XCoordinate = -10, YCoordinate = 10, UserId = "3", Code = "3454356200177235" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "4" } }, new { Name = "test4", Health = 100, Capacity = 100, Energy = 100, XCoordinate = 0, YCoordinate = 0, UserId = "4", Code = "3454356200177235" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "5" } }, new { Name = "test5", Health = 100, Capacity = 100, Energy = 100, XCoordinate = 10, YCoordinate = 20, UserId = "5", Code = "3454356200177235" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "6" } }, new { Name = "test6", Health = 100, Capacity = 1000, Energy = 100, XCoordinate = 20, YCoordinate = 5, UserId = "6", Code = "3454356200177235" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "7" } }, new { Name = "test7", Health = 100, Capacity = 100, Energy = 98, XCoordinate = 20, YCoordinate = 5, UserId = "7", Code = "3454356200177235" }, new { index = new { _index = "spaceships", _type = "spaceship", _id = "100" } }, new { Name = "test100", Health = 100, Capacity = 100, Energy = 100, XCoordinate = 20, YCoordinate = 5, UserId = "7", Code = "3454356200177235" } }; var ndexResponse = client.Bulk <StringResponse>(PostData.MultiJson(Spaceships)); Console.WriteLine("Populated"); }
public void Shoot_SimpleValues_ReturnsShotShips() { Spaceship spaceship = new Spaceship("100", "spaceship", 0, 0); Spaceship spaceship1 = new Spaceship("101", "spaceship", 20, 20); Spaceship spaceship2 = new Spaceship("102", "spaceship", 40, 40); spaceship2.Capacity = 1000; String all_codes = spaceship1.Code + spaceship2.Code; String presentInShoot = ""; List <Spaceship> lst_sp = new List <Spaceship>(); presentInShoot = spaceship.Shoot(45, 45, 50, "12345678"); string[] lines = Regex.Split(presentInShoot, "\r\n"); foreach (string line in lines) { string[] words = line.Split(" "); lst_sp.AddRange(ElasticSearchCommands.searchUsername(words[5])); } if (lst_sp.Contains(spaceship1) && lst_sp.Contains(spaceship2)) { Assert.Pass(); } }
public void Search_All_Finds_All_Users() { var client = ElasticSearchCommands.create_lowlevelclient(); ElasticSearchCommands.Populate(); List <Spaceship> search_all = ElasticSearchCommands.searchAll(); Assert.Greater(search_all.Count, 3); }
public void Update_Energy_Increases_Energy() { Thread energy_update = new Thread(() => ElasticSearchCommands.UpdateEnergy()); energy_update.Start(); Thread.Sleep(4000); Spaceship test_ship = ElasticSearchCommands.searchUsername("test7")[0]; Assert.AreEqual(100, test_ship.Energy); }
public void Shoot_SimpleValues_SpaceshipShotShouldHaveLessHealth() { Spaceship spaceship = ElasticSearchCommands.searchUsername("test0")[0]; spaceship.Shoot(0, 90, 40, "123456778987654321"); //Thread.Sleep(5000); Spaceship spaceship1 = ElasticSearchCommands.searchUsername("test3")[0]; Assert.Less(spaceship1.Health, 100); }
public void Update_User_Correctly_Updates_Information() { Spaceship test_ship = ElasticSearchCommands.searchUsername("test4")[0]; test_ship.XCoordinate = 100; ElasticSearchCommands.updateUser(test_ship); Thread.Sleep(1000); Spaceship search_username = ElasticSearchCommands.searchUsername("test4")[0]; Console.WriteLine(search_username.XCoordinate); Assert.AreEqual(search_username.XCoordinate, 100); }
public static String Login(String username) { Console.WriteLine("Client attempting Login"); List <Spaceship> search = ElasticSearchCommands.searchUsername(username); if (search.Count == 0) { return("false"); } else { return("true"); } }
public static string AddCommand(String data, String username) { List <Spaceship> search = ElasticSearchCommands.searchUsername(username); Spaceship user = search[0]; Console.WriteLine("User {0} connected", username); String command = data; command = command.Replace(" ", ""); var command_list = command.Split(new Char[] { '(', ',', ')' }); double angle, polarAngle; int energy; if (command_list[0].Equals("move")) { angle = float.Parse(command_list[1]); energy = int.Parse(command_list[2]); user.Move(angle, energy); } else if (command_list[0].Equals("shoot")) { polarAngle = float.Parse(command_list[1]); angle = float.Parse(command_list[2]); energy = int.Parse(command_list[3]); String code = command_list[4]; user.Shoot(polarAngle, angle, energy, code); } else if (command_list[0].Equals("scan")) { polarAngle = float.Parse(command_list[1]); angle = float.Parse(command_list[2]); energy = int.Parse(command_list[3]); return(user.Scan(polarAngle, angle, energy)); } else if (command_list[0].Equals("GetHealth")) { string originalmessage = ("Current health: " + user.Health); return(originalmessage); } else if (command_list[0].Equals("GetEnergy")) { string originalmessage = ("Current energy: " + user.Energy); return(originalmessage); } else if (command_list[0].Equals("exit")) { disconnected_users += 1; return("Quitting game!"); } else { return("Unknown command: (" + command + ") \n Please try again."); } return(""); }
public void Search_Username_Finds_User() { Spaceship search_username = ElasticSearchCommands.searchUsername("test0")[0]; Assert.AreEqual(search_username.Name, "test0"); }