public void TestGetAllServers() { var server1 = new GameServer { Endpoint = "test1.com-8080", Name = "1", GameModes = new [] { new GameMode { Name = "DM" } } }; var server2 = new GameServer { Endpoint = "test2.com-8080", Name = "2", GameModes = new GameMode[0] }; var urlArgs = new Dictionary <string, string>(); var request = new HttpRequest(HttpMethod.Get, Stream.Null); using (var db = new ServerDatabase()) { db.GameServers.Add(server1); db.GameServers.Add(server2); db.SaveChanges(); } var response = ServerInfoRoutes.GetAllServersInfo(urlArgs, request); var actual = JToken.Parse(response.Content); var expected = "[{\"endpoint\":\"test1.com-8080\",\"info\":{\"name\":\"1\",\"gameModes\":[\"DM\"]}},{\"endpoint\":\"test2.com-8080\",\"info\":{\"name\":\"2\",\"gameModes\":[]}}]"; var expectedJson = JToken.Parse(expected); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(JToken.DeepEquals(expectedJson, actual)); }
public void TestGetAllServersEmpty() { var urlArgs = new Dictionary <string, string>(); var request = new HttpRequest(HttpMethod.Get, Stream.Null); var response = ServerInfoRoutes.GetAllServersInfo(urlArgs, request); var actual = JToken.Parse(response.Content); var expected = "[]"; var expectedJson = JToken.Parse(expected); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(JToken.DeepEquals(expectedJson, actual)); }