Ashley Bye
Ashley Bye

Reputation: 1750

xUnit configuration for ASP.NET Core 1.1 MVC in Visual Studio 2017 RC

Unit testing ASP.NET Core MVC web apps in Visual Studio 15, I could put a using statement for Microsoft.AspNetCore.Mvc in my test file and then access framework classes, such as ViewResult. Using Visual Studio 2017 RC, I cannot even locate Microsoft.AspNetCore.Mvc in the test project. I believe it must be to do with dependencies.

The project.json configuration from VS15:

{
  "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" ]
    }
  }
}

The SportsStore.Test.csproj configuration from VS17:

<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>

The VS17 project uses xunit.runner.visualstudio rather than dotnet-test-xunit due to latter only being compatible with project.json, not .csproj. I suspect this dependency change is the cause of my problem. How do I correct this and get access to the MVC framework?

Upvotes: 2

Views: 594

Answers (1)

Ashley Bye
Ashley Bye

Reputation: 1750

Hmm. I should always remember the helpful IT support advice... "Have you tried restarting it?"

Seems to have fixed the problem. I've reported it as a potential bug since I don't think the IDE should need restarting when adding a test project to the solution.

Upvotes: 1

Related Questions