public async Task put_valid_player_returns_no_content(string url) { var generated = DatabaseSeed.GenerateRandomPlayer(); var postContent = new StringContent(JsonConvert.SerializeObject(generated), System.Text.Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync(url, postContent); postResponse.EnsureSuccessStatusCode(); var playerContent = await postResponse.Content.ReadAsStringAsync(); var player = JsonConvert.DeserializeObject <Player>(playerContent); player.Age = DatabaseSeed.GetRandomAge(); var putContent = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PutAsync($"{url}/{player.PlayerId}", putContent); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); }
public async Task put_invalid_player_returns_validation_problem_data(string url) { var generated = DatabaseSeed.GenerateRandomPlayer(); var postContent = new StringContent(JsonConvert.SerializeObject(generated), System.Text.Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync(url, postContent); postResponse.EnsureSuccessStatusCode(); var playerContent = await postResponse.Content.ReadAsStringAsync(); var player = JsonConvert.DeserializeObject <Player>(playerContent); player.LastName = null; var putContent = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PutAsync($"{url}/{player.PlayerId}", putContent); var responseConent = await response.Content.ReadAsStringAsync(); var modelState = JsonConvert.DeserializeObject <ValidationProblemDetails>(responseConent); Assert.IsType <ValidationProblemDetails>(modelState); }
public async Task post_returns_created_status(string url) { var player = DatabaseSeed.GenerateRandomPlayer(); var content = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); Assert.Equal(HttpStatusCode.Created, response.StatusCode); }
public async Task post_returns_application_data_in_response(string url) { var player = DatabaseSeed.GenerateRandomPlayer(); var content = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString()); }
public async Task post_returns_route_for_created_player(string url) { var player = DatabaseSeed.GenerateRandomPlayer(); var content = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode(); Assert.NotNull(response.Headers.Location); }
public async Task post_created_route_matches_get_by_id_for_player(string url) { var player = DatabaseSeed.GenerateRandomPlayer(); var content = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode(); var playerResponse = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <Player>(playerResponse); Assert.Equal($"{url}/{data.PlayerId}", response.Headers.Location.AbsolutePath); }
public async Task post_returns_player(string url) { var player = DatabaseSeed.GenerateRandomPlayer(); var content = new StringContent(JsonConvert.SerializeObject(player), System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode(); var playerResponse = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <Player>(playerResponse); Assert.IsType <Player>(data); }
public Player GetNewPlayer() { return(DatabaseSeed.GenerateRandomPlayer()); }