无法在.NET Core 2.2中运行集成测试; System.Reflection.ReflectionTypeLoadException

时间:2019-07-07 21:14:30

标签: c# asp.net-core .net-core integration-testing

我正在尝试对Web API进行简单的集成测试。我有一个错误:

  

System.Reflection.ReflectionTypeLoadException:无法加载一个或多个请求的类型。   无法从程序集'mscorlib,Version = 4.0

加载类型'System.Runtime.Remoting.Proxies.RealProxy'

我遵循了本教程: https://dotnetcorecentral.com/blog/asp-net-core-web-api-integration-testing-with-xunit/

测试类:

public class UnitTest1
{
    [Fact]
    public async Task Test1()
    {
      var client = new TestClientProvider().Client;
      var response = await client.GetAsync("/api/Emitter");
      response.EnsureSuccessStatusCode();
      Assert.Equal(HttpStatusCode.OK, response.StatusCode);
    }
  }

TestClientProvider:

public class TestClientProvider
  {
    public HttpClient Client { get; set; }

    public TestClientProvider()
    {
      var server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
      Client = server.CreateClient();
    }
  }

csproj:

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

    <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="AspNetCore.Proxy" Version="2.1.2" />
        <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
        <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
        <PackageReference Include="xunit" Version="2.4.0" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Odo.Web\Odo.Web.csproj" />
    </ItemGroup>

</Project>

0 个答案:

没有答案