public void AssertGameOver(String gameToken) { BriefStatusTestResponse briefResponse = GET_BriefStatus(gameToken).Result; Assert.AreEqual(HttpStatusCode.OK, briefResponse.ResponseCode); int reportedTimeleft = briefResponse.Response.timeleft; Assert.IsTrue(reportedTimeleft > 0); if (briefResponse.Response.gameStatus != "playing") { Console.WriteLine("Game is unexpectedly not playing. Consider making games longer."); } Assert.AreEqual("playing", briefResponse.Response.gameStatus); int timeleft = reportedTimeleft; while (true) { Thread.Sleep(1000); briefResponse = GET_BriefStatus(gameToken).Result; //Assert.AreEqual(HttpStatusCode.OK, briefResponse.ResponseCode); reportedTimeleft = briefResponse.Response.timeleft; //Assert.IsTrue(timeleft < 0 || Math.Abs(timeleft - reportedTimeleft) <= 2); if (reportedTimeleft <= 0 || briefResponse.Response.gameStatus == "finished") { Assert.AreEqual(HttpStatusCode.OK, briefResponse.ResponseCode); Assert.AreEqual("finished", briefResponse.Response.gameStatus); Assert.AreEqual(0, reportedTimeleft); Console.Write("\r \r"); return; } else { //Assert.AreEqual("playing", briefResponse.Response.gameStatus); Console.Write("\r" + reportedTimeleft + " seconds left "); timeleft = reportedTimeleft - 1; } } }
public int AssertBriefStatus(String gameToken, String status, int score1, int score2, int timeleft = -1, int code = 200) { BriefStatusTestResponse briefResponse = GET_BriefStatus(gameToken).Result; HttpStatusCode resultCode = briefResponse.ResponseCode; Assert.AreEqual(code, (int)resultCode); if (IsOK(resultCode)) { Assert.AreEqual(HttpStatusCode.OK, briefResponse.ResponseCode); Assert.AreEqual(status, briefResponse.Response.gameStatus); Assert.AreEqual(0, briefResponse.Response.score1); Assert.AreEqual(0, briefResponse.Response.score2); int reportedTimeleft = briefResponse.Response.timeleft; if (timeleft >= 0) { Assert.IsTrue(Math.Abs(timeleft - reportedTimeleft) <= 2); } return(reportedTimeleft); } else { return(0); } }