I have an ASP.Net Core gRPC project that I'd like to run integration tests on. As such, I set up an integration test project.
My directory structure looks something like this:
- src
- MyService.Grpc
- Protos
- my-service.proto
- Startup.cs
- tests
- MyService.Grpc.Tests
In order to set up the WebApplicationFactory
to call the Startup
class in MyService.Grpc
and to use the generated client provided by Grpc.Net.Client
, I have the test project set up like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<!-- Proto file reference -->
<Protobuf Include="../../src/MyService.Grpc/Protos/my-service.proto" GrpcServices="Client" />
<!-- ASP.NEt Core gRPC dependencies -->
<PackageReference Include="Google.Protobuf" Version="3.17.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.38.0" />
<PackageReference Include="Grpc.Tools" Version="2.38.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- Testing framework references -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/MyService.Grpc/MyService.Grpc.csproj" />
</ItemGroup>
Note that I have both the gRPC server project (MyService.Grpc.csproj
) and the proto file (my-service.proto
) referenced from the test project.
Everything compiles but I ran into some compile warnings that I would like to get rid of.
MyService.cs(44, 67): [CS0436] The type 'MyRequest' in 'tests\MyService.Grpc.Tests\obj\Debug\net5.0\MyService.cs' conflicts with the imported type 'MyRequest' in 'MyService.Grpc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'tests\MyService.Grpc.Tests\obj\Debug\net5.0\MyService.cs'.
I understand what the compiler is complaining about because the type MyRequest
is defined twice: once generated by Grpc.Net.Client
from the proto file and once by the project reference import. At the same time, I cannot get rid of either reference in the test project because I need both of them.
My question is how can I get rid of this warning without importing the same types twice in my tests?