public string AssertJoinGame(String userToken, int code = 200)
        {
            JoinGamePOST userJoinPost = new JoinGamePOST
            {
                userToken = userToken
            };
            JoinGamePOSTTestResponse joinResponse = POST_JoinGame(userJoinPost).Result;
            HttpStatusCode           statusCode   = joinResponse.ResponseCode;

            Assert.AreEqual(code, (int)statusCode);
            if (IsOK(joinResponse.ResponseCode))
            {
                return(joinResponse.Response.gameToken);
            }
            else
            {
                Assert.AreEqual(code, (int)joinResponse.ResponseCode);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Issues a /joingame POST call to a <see cref = "BoggleService" /> and returns the result.
        /// </summary>
        /// <param name = "joinGame">A <see cref = "JoinGamePOST" /> object representing the user to add to a game.</param>
        /// <returns>A <see cref = "JoinGamePOSTTestResponse" /> object indicating the result of the /joingame request.</returns>
        public static async Task <JoinGamePOSTTestResponse> POST_JoinGame(JoinGamePOST joinGame)
        {
            using (HttpClient client = CreateClient())
            {
                StringContent       content  = new StringContent(JsonConvert.SerializeObject(joinGame), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync("/Boggle.svc/joingame", content);

                if (!response.IsSuccessStatusCode)
                {
                    return(new JoinGamePOSTTestResponse
                    {
                        ResponseCode = response.StatusCode,
                        Response = null
                    });
                }

                return(new JoinGamePOSTTestResponse
                {
                    ResponseCode = response.StatusCode,
                    Response = JsonConvert.DeserializeObject <JoinGameResponse>(await response.Content.ReadAsStringAsync())
                });
            }
        }