using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.Mvc.Testing.Handlers; using Microsoft.AspNetCore.TestHost; using Xunit; using XUnitDIStudy.Model; namespace XUnitDIStudy.Test { public class ControllerTest:IClassFixture> { private readonly WebApplicationFactory _factory; public ControllerTest(WebApplicationFactory factory) { _factory = factory; } [Fact] public async Task Test() { // Arrange var client = _factory.CreateClient(); // Act var response = await client.GetAsync("/Default/GetAll"); // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 List result = System.Text.Json.JsonSerializer.Deserialize>(response.Content.ReadAsStringAsync().Result); Assert.NotNull(result); Assert.True(result.Count>0); } } }