0

我的域对象在一个 SDK 风格的项目中,并以 net472 和 net5.0 为目标,我的实体层和单元测试项目也是如此。一切都编译得很好。

对于我声明的每个 TFM,测试资源管理器正确地显示了重复的测试。但是 net5.0 测试失败,声称没有连接字符串。我有一个文件App.config和一个appsettings.json文件..但不确定此时我缺少什么。

单元测试项目源

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net472;net5.0</TargetFrameworks>
    <Platforms>AnyCPU;x64</Platforms>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.4.4" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
    <PackageReference Include="coverlet.collector" Version="1.3.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyCorp.BizObjects\MyCorp.BizObjects.csproj" />
    <ProjectReference Include="..\MyCorp.EntityAccess\MyCorp.EntityAccess.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Compile Update="appsettings.Designer.cs">
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <AutoGen>True</AutoGen>
      <DependentUpon>appsettings.json</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <None Update="appsettings.json">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>appsettings.Designer.cs</LastGenOutput>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

应用设置.json

{
  "ConnectionStrings": {
    "ThingStatusLocation": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyCorpEntity_TEST_DotNet50;Integrated Security=True;Pooling=False"
  }
}
4

0 回答 0