public void TestAddServer() { var urlArgs = new Dictionary <string, string> { { "endpoint", "test.com-8080" } }; var expected = new GameServer { Endpoint = "test.com-8080", Name = "] My P3rfect Server [", GameModes = new[] { new GameMode { Name = "DM" }, new GameMode { Name = "TDM" } } }; using (var stream = new MemoryStream()) { var writer = new StreamWriter(stream); writer.Write("{\"name\": \"] My P3rfect Server [\",\"gameModes\": [ \"DM\", \"TDM\" ]}"); writer.Flush(); stream.Position = 0; var request = new HttpRequest(HttpMethod.Put, stream); var response = ServerInfoRoutes.ServerInfo(urlArgs, request); Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); using (var db = new ServerDatabase()) { var a = db.GameServers.ToList(); CollectionAssert.AreEqual(new[] { expected }, a); } } }
public void TestGetServer() { var server = new GameServer { Endpoint = "test.com-8080", Name = "] My P3rfect Server [", GameModes = new[] { new GameMode { Name = "DM" } } }; var urlArgs = new Dictionary <string, string> { { "endpoint", "test.com-8080" } }; var request = new HttpRequest(HttpMethod.Get, Stream.Null); var response = ServerInfoRoutes.ServerInfo(urlArgs, request); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); using (var db = new ServerDatabase()) { db.GameServers.Add(server); db.SaveChanges(); } var expected = "{\"name\":\"] My P3rfect Server [\",\"gameModes\":[\"DM\"]}"; var expectedJson = JToken.Parse(expected); response = ServerInfoRoutes.ServerInfo(urlArgs, request); var actual = JToken.Parse(response.Content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(JToken.DeepEquals(actual, expectedJson)); }
public void TestInvalidHostname() { var request = new HttpRequest(HttpMethod.Get, Stream.Null); var urlArgs = new Dictionary <string, string> { { "endpoint", "test.com" } }; var response = ServerInfoRoutes.ServerInfo(urlArgs, request); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }