在Visual Studio 15中对ASP.NET Core MVC Web应用程序进行单元测试,我可以在我的测试文件中放置Microsoft.AspNetCore.Mvc
的using语句,然后访问框架类,例如ViewResult
。使用Visual Studio 2017 RC,我甚至无法在测试项目中找到Microsoft.AspNetCore.Mvc
。我认为必须与依赖关系有关。
来自VS15的project.json配置:
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"moq": "4.6.38-alpha",
"System.Diagnostics.TraceSource": "4.3.0",
"SportsStore": "1.0.0",
"xunit": "2.1.0",
"Microsoft.DotNet.InternalAbstractions": "1.0.0" // Required for xUnit with NetCore 1.1
},
"frameworks": {
"netcoreapp1.1": {
"imports": [ "dotnet5.6", "portable-net45+win8" ]
}
}
}
VS17的SportsStore.Test.csproj配置:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.InternalAbstractions">
<Version>1.0.500-preview2-1-003177</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0-preview-20161123-03</Version>
</PackageReference>
<PackageReference Include="Moq">
<Version>4.6.38-alpha</Version>
</PackageReference>
<PackageReference Include="System.Diagnostics.TraceSource">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="xunit">
<Version>2.2.0-beta4-build3444</Version>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<Version>2.2.0-beta4-build1194</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SportsStore\SportsStore.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
VS17项目使用xunit.runner.visualstudio
而不是dotnet-test-xunit
,因为后者只与project.json兼容,而不是.csproj。我怀疑这种依赖性改变是我的问题的原因。如何更正此问题并获取对MVC框架的访问权限?
答案 0 :(得分:1)
嗯。我应该永远记住有用的IT支持建议......“你试过重启吗?”
似乎解决了这个问题。我已经将它报告为潜在的错误,因为我认为在向解决方案添加测试项目时IDE不需要重新启动。