2016-06-18 15 views
1

rc2で空のasp.net Webアプリケーションプロジェクトを作成しました。私のプロジェクトファイルは:ASP.NETコアでHttpConfigurationを使用するRC2

{ 
    "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にそれを置き換えることはありますか?

+0

なぜそれが必要ですか?なぜそれを変更したいのですか?あなたがしていることは単体テストのようには聞こえません。単体テストはコードの小さなまとまり(単位)のみをテストすべきです。ユニットテストの設定ファイルに応じて、クラスを再設計する必要があります。確かに間違っています – Tseng

+0

@ Tseng、私はメモリユニットテストで行いたいです。ここの例を参照してください。(https://blogs.msdn.microsoft.com/kiranchalla/2012/05/05/in-memory-client-host-and-integration-testing-of-your-web-api-サービス/)その例は間違っていますか? – Bigeyes

+0

この記事のタイトルを読んでいれば、単体テストではないことに気づいたでしょう; – Tseng

答えて

1

ASP.Coreは、TestServerクラスを使用した簡単な統合テストを提供します。それを使用し始めるのに役立つかもしれない:

と(Diagnosticsのような)テストのためのhttps://github.com/aspnet使用TESTSERVERでのプロジェクトの多くのことを覚えておいてください。

+0

フォローするのは難しいです。私は[リンク](https://github.com/aspnet/Docs/tree/1.0.0-rc1/aspnet/mvc/controllers/testing/sample/TestingControllersSample/src/TestingControllersSample)を見つける。しかし、サンプルを引き出すためのzipファイルやgitはありません。 – Bigeyes

+0

私は答えを更新しました。 – Set

+0

答えをマークしました。ありがとうございます。単体テストや統合テストプロジェクトを追加したい場合は、次の質問があります。プロジェクトテンプレートとは何ですか?単体テストプロジェクトか、Webアプリケーションプロジェクトの下のフォルダですか? asp.net team [document](https://docs.asp.net/en/latest/testing/unit-testing.html)から、テストプロジェクトにはproject.jsonファイルがあります。私の質問は、ユニットテストプロジェクトのテンプレートであれば、project.jsonはありません。 – Bigeyes

関連する問題