You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
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<WebApplicationFactory<WebApp.Startup>>
|
|
{
|
|
private readonly WebApplicationFactory<WebApp.Startup> _factory;
|
|
|
|
public ControllerTest(WebApplicationFactory<WebApp.Startup> 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<Student> result = System.Text.Json.JsonSerializer.Deserialize<List<Student>>(response.Content.ReadAsStringAsync().Result);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.True(result.Count>0);
|
|
}
|
|
}
|
|
}
|