2017-09-06 63 views
0

我剛剛創建了一個空的Web API項目與.net核心2.0。 我有一個默認的控制器,我現在想創建一個集成測試。IntegrationTest控制器與網絡api上的.net核心2.0

[Route("api/[controller]")] 
public class ValuesController : Controller 
{ 
    // GET api/values 
    [HttpGet] 
    public IEnumerable<string> Get() 
    { 
     return new string[] { "value1", "value2" }; 
    } 
} 

目標是在集成中的自我主機,然後輸入url api/values並檢查返回值。

注意:我只使用wep api 2和owin,這很容易做到。但以下鏈接:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/owin表示.net核心應用程序不應該使用owin,那麼我們應該使用什麼以及如何使用它?

+0

爲什麼不從您的控制器調用方法? – hugoterelle

+0

因爲如果我instanciate控制器並直接調用Get()它不會測試路由和調用Http GET的事實。這將是更多的單元測試。 –

+0

此鏈接可以幫助你https://docs.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/unit-testing-controllers-in-web-api – hugoterelle

回答