asp.net-web-api - 在 ASP.NET Core RC2 中使用 HttpConfiguration

标签 asp.net-web-api asp.net-core

我使用 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 类进行集成测试的简单方法。以下内容可能有助于开始使用它:

请记住,https://github.com/aspnet 中有很多项目使用 TestServer 进行测试(如 Diagnostics )。

关于asp.net-web-api - 在 ASP.NET Core RC2 中使用 HttpConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897246/

相关文章:

asp.net-web-api - 在 F# 中实现 IExceptionHandler 或 IExceptionLogger 等消息处理程序时,返回 "empty task"的正确方法是什么?

c# - Entity Framework 核心存储库模式 - 重复检查

c# - 热衷于从同一解决方案中的另一个项目访问 appsettings.json?

.net - az webapp 在指定 .net core 时创建错误

azure - 将 Serilog 中的 outputTemplate 参数与 Azure Application Insights 结合使用

asp.net-web-api - 网络API : how to access multipart form values when using MultipartMemoryStreamProvider?

c# - WebApi 2 使用属性路由构建嵌套路由。结果同时映射到两个 Controller

asp.net - Route 属性上的 RouteOrder 属性在哪里?

c# - 如何从 ASP.Net Core 中的 SqlServerDBContextOptionsExtensions 获取连接字符串

javascript - Controller 收到每个页面请求 2 个请求