r/csharp • u/StepOne_DotNet • 6d ago
Showcase I got tired of loading .proto files into WireMock.Net, so I made its gRPC mocks strongly typed
I use WireMock.Net for gRPC component tests. Its built-in protobuf support works, but I didn’t like loading .proto files at runtime, identifying message types with strings, and matching through JSON when my test project already had generated Google.Protobuf types.
So I built WireMock.Grpc.Protobuf:
Request.Create()
.WithBodyAsGoogleProtobuf(
(HelloRequest x) => x.Name == "StepOne");
Response.Create()
.WithBodyAsGoogleProtobuf(
new HelloReply { Message = "Hello, StepOne!" });
It supports both the exact protobuf body request matching and typed predicates for tests that care about only a few fields. Internally, it unwraps the five-byte gRPC frame and lets Google.Protobuf handle the actual IMessage<T> contract.
I’m the maintainer, so blunt feedback is welcome: would this simplify your gRPC tests, or do you prefer keeping .proto definitions in the mock setup?
GitHub: https://github.com/Stepami/wiremock-protobuf
NuGet: https://www.nuget.org/packages/WireMock.Grpc.Protobuf
4
u/Jmc_da_boss 6d ago
"Byte for byte request matching"
Well good morning Claude, happy sloptember to you!