Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (43 sloc) 1.76 KB
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);
}
}
}