I have a dotnet core 3 console app project with a generated gRPC client (using the Protobuf element in the csproj below). I would like to unit test my code. Is there a way to generate my gRPC client to include interfaces for the generated classes so that I can properly mock out the gRPC client?
Thank you for your time!
<ItemGroup>
<Protobuf Include="..\..\Data\Protos\*" GrpcServices="Client" />
</ItemGroup>
Yes, you can definitely do that.
gRPC C-core is in maintenance mode and will be deprecated in favor of gRPC for . NET. gRPC C-core is not recommended for new apps.
The folks at Google decided not to include Interfaces going forward (They used to generate it one point).
The primary reason they've cited is that Interfaces can't maintain backward/forward compatibility that the underlying protobuf requires. If you change an interface, this will break the build and any compatibility with previous builds.
You can read more about it here.
As for testing the generated abstract classes, you can use a Mocking Framework such as Moq to test it out but sounds like you're already aware of that most likely. If not, there's an example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With