コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public Player GetNewPlayer()
 {
     return(DatabaseSeed.GenerateRandomPlayer());
 }