Ich erstellte ein leeres asp.net-Webanwendungsprojekt mit RC2. Meine Projektdatei ist:Verwenden von HttpConfiguration in ASP.NET Core 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%" ]
}
}
Jetzt möchte ich HttpConfiguration config = new HttpConfiguration();
in meiner Unit-Test hinzuzufügen.
Aber HtppConfiguration
ist von ASP.NET WEB API 2. Wie ändere ich meine Projekt.json Datei? Oder gibt es Ersatz in ASP.NET CORE RC2?
Warum brauchen Sie es? Warum willst du es ändern? Was Sie tun, klingt nicht nach Komponententest. Der Einheitentest sollte nur kleine Codeabschnitte (Einheiten) testen. Sie sollten stattdessen Ihre Klassen neu gestalten, abhängig von einer Konfigurationsdatei im Komponententest ist definitiv falsch – Tseng
@Tseng, möchte ich im Speichereinheitstest tun. Sehen Sie das [Beispiel hier] (https://blogs.msdn.microsoft.com/kiranchalla/2012/05/05/in-memory-client-host-and-integration-testing-of-your-web-api- service /) Ist das Beispiel falsch? – Bigeyes
Wenn Sie den Titel dieses Artikels gelesen hätten, hätten Sie erkannt, dass es nicht um Komponententests geht;) – Tseng