??Owin Host???????IIS??Web API???????
???????????? ???????[ 2015/8/21 15:22:28 ] ??????????????? ???????
????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?С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11