using System; using Xunit; using poi.Controllers; using poi.Models; using poi; using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; namespace IntegrationTests { public class POIIntegrationTests: IClassFixture> { private readonly CustomWebApplicationFactory _factory; public POIIntegrationTests(CustomWebApplicationFactory factory) { _factory = factory; } [Theory] [InlineData("/api/poi/")] public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url) { // Arrange var client = _factory.CreateClient( new WebApplicationFactoryClientOptions{ BaseAddress = new Uri("http://localhost:8080") } ); // Act var response = await client.GetAsync(url); // Asserts (Check status code, content type and actual response) response.EnsureSuccessStatusCode(); // Status Code 200-299 Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString()); //deserialize response to poi list List pois = JsonConvert.DeserializeObject>( await response.Content.ReadAsStringAsync()); //Check that 3 pois are returned Assert.Equal(3, pois.Count); } } }