Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Web.Api.Core.Domain.Entities;
using Xunit;
namespace Web.Api.IntegrationTests.Controllers
{
public class PlayersControllerIntegrationTests : IClassFixture<CustomWebApplicationFactory<Startup>>
{
private readonly HttpClient _client;
public PlayersControllerIntegrationTests(CustomWebApplicationFactory<Startup> factory)
{
_client = factory.CreateClient();
}
[Fact]
public async Task CanGetPlayers()
{
// The endpoint or route of the controller action.
var httpResponse = await _client.GetAsync("/api/players");
// Must be successful.
httpResponse.EnsureSuccessStatusCode();
// Deserialize and examine results.
var stringResponse = await httpResponse.Content.ReadAsStringAsync();
var players = JsonConvert.DeserializeObject<IEnumerable<Player>>(stringResponse);
Assert.Contains(players, p => p.FirstName=="Wayne");
Assert.Contains(players, p => p.FirstName == "Mario");
}
[Fact]
public async Task CanGetPlayerById()
{
// The endpoint or route of the controller action.
var httpResponse = await _client.GetAsync("/api/players/1");
// Must be successful.
httpResponse.EnsureSuccessStatusCode();
// Deserialize and examine results.
var stringResponse = await httpResponse.Content.ReadAsStringAsync();
var player = JsonConvert.DeserializeObject<Player>(stringResponse);
Assert.Equal(1,player.Id);
Assert.Equal("Wayne", player.FirstName);
}
}
}