在ASP.NET Core RC2中使用HttpConfiguration

时间:2016-06-18 13:00:49

标签: 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中有没有替代它?

1 个答案:

答案 0 :(得分:1)

ASP.Core提供了一种使用TestServer类进行集成测试的简便方法。以下内容可能有助于开始使用它:

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