我使用 rc2 创建了一个空的 ASP.NET Web 应用程序项目。我的项目文件是:
{
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.Cors": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
现在我想在我的单元测试中添加 HttpConfiguration config = new HttpConfiguration();
。
但是HtppConfiguration
来自ASP.NET WEB API 2。如何更改我的project.json文件?或者 ASP.NET CORE RC2 中有替代品吗?
最佳答案
ASP.Core 提供了一种使用 TestServer
类进行集成测试的简单方法。以下内容可能有助于开始使用它:
- ASP.Net Core documentation关于集成测试。
- 一个post关于使用 TestServer 与 example在 github 上。
- 一个TestServerTests.cs文件来自Hosting存储库,其中包含 TestServer 的 xunit 测试。可能有助于回顾一下 TestServer 可以做什么。
- 关于SO的好问题:"Why the TestServer (AspNetCore) gives 404 error on static files?"
请记住,https://github.com/aspnet 中有很多项目使用 TestServer 进行测试(如 Diagnostics )。
关于asp.net-web-api - 在 ASP.NET Core RC2 中使用 HttpConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897246/