????2????д????Owin Host??Web API?????????????
public class CommentsWebApiTest : IDisposable
{
private const string HOST_ADDRESS = "http://localhost:8001";
private IDisposable _webApp;
private HttpClient _httClient;
public CommentsWebApiTest()
{
_webApp = WebApp.Start<Startup>(HOST_ADDRESS);
Console.WriteLine("Web API started!");
_httClient = new HttpClient();
_httClient.BaseAddress = new Uri(HOST_ADDRESS);
Console.WriteLine("HttpClient started!");
}
public void Dispose()
{
_httClient.Dispose();
_webApp.Dispose();
}
[Fact]
public async Task GetComments()
{
var postId = 1;
var response = await _httClient.GetAsync($"/blogposts/{postId}/comments");
if(response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
Assert.Equal(HttpStatusCode.OK?? response.StatusCode);
var comments = await response.Content.ReadAsAsync<Comment[]>();
Assert.NotEmpty(comments);
Assert.Equal(postId?? comments[0].PostId);
Assert.Equal("Coding changes the world"?? comments[0].Body);
}
}
???????????nuget???Microsoft.Owin.Hosting??Microsoft.Owin.Host.HttpListener????????????Microsoft.AspNet.WebApi.Client??????ReadAsAsync<Comment[]>?????У???
????3?????е???????????????????е?????????????Run Test(s)???????TestDriven.Net???????????????????б???

????4??????????????????????Web API??????????????
????Output from WebApiTests.CommentsWebApiTest.GetComments:
????Web API started!
????HttpClient started!
????1 passed?? 0 failed?? 0 skipped?? took 4.91 seconds (xUnit.net 1.9.2 build 1705).
??????????????????????
??????ξ????????????????????????????д????????????????????????????????????????????????????????????????????n?????????????????????????????????????μ?????ж??
???????????
??????????????????????????????owin host????web api?????????????????????????????????????????????????app.config?ж???????????web api?????web.config?ж???????????web.config?е????????????app.config?С?