Closed vgoranski closed 3 months ago
Imports should work, see default example proto definition here: https://protobuf.heyenrath.nl/
I think that the JsonMatcher will not match, I think in that case you need a https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-JsonPartialMatcher
Yes, imports actually work. In my example above the problem was eventually the JsonMatcher.
I also noticed that in case when none of the types are used from the import, then there will be an error. But usually, if you use an import you should use the types from it, so I guess it's not that big of a deal.
[Fact]
public async Task WireMockServer_WithBodyAsProtoBuf_InlineProtoDefinition_UsingGrpcGeneratedClient_UsingProtoImport()
{
const string protoDefinition = """
syntax = "proto3";
import "google/protobuf/wrappers.proto";
package greet;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
""";
// Arrange
using var server = WireMockServer.Start(useHttp2: true);
server
.Given(Request.Create()
.UsingPost()
.WithPath("/greet.Greeter/SayHello")
.WithBodyAsProtoBuf(protoDefinition, "greet.HelloRequest")
)
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/grpc")
.WithTrailingHeader("grpc-status", "0")
.WithBodyAsProtoBuf(protoDefinition, "greet.HelloReply",
new
{
message = "hello John {{request.method}}"
}
)
.WithTransformer()
);
// Act
var channel = GrpcChannel.ForAddress(server.Url!);
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "John" });
// Assert
reply.Message.Should().Be("hello John POST");
server.Stop();
}
If you remove the import form this example, everything will work fine.
also noticed that in case when none of the types are used from the import, then there will be an error.
This is very strange, I need to check that. can you maybe create a issue here : https://github.com/StefH/ProtoBufJsonConverter ?
Closing this one...
Describe the bug
I'm not sure if it's a bug or more of a feature request, but it seems that the current implmentation of ProtoBufMatcher is not supporting imports in proto.
Expected behavior:
Imports in proto work.
Test to reproduce