Add protodefinition and refer it from mapping #668

Closed
opened 2025-12-29 15:30:23 +01:00 by adam · 7 comments
Owner

Originally created by @GomesNayagam on GitHub (Jan 30, 2025).

Originally assigned to: @StefH on GitHub.

Feature Request

I am planning to use grpc mock using docker container via WireMockContainerBuilder() like standalone WIreMock.Start() server. While doing that i noticed i am missing .AddProtoDefinition(id, protoDefinitionText) signatue for Container way.

Describe the solution you'd like
Prefer to as close as possible like

var server = WireMockServer.Start() 
server.AddProtoDefinition(id, protoDefinitionText)

var wireMockContainer = new WireMockContainerBuilder()
    .WithAutoRemove(true)
    .WithCleanUp(true)
   // .WithBindMount(TestHelper.GetAbsolutePath(@"mocks\greet"), "/home/wiremock")
   // .AddProtoDefinition(id, protoDefinitionText)
    .WithCommand("--UseHttp2")
    .AddUrl("grpc://*:9090")
    .AddUrl("http://*:8080")
    .Build();

Describe alternatives you've considered

  var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json"));
  result.EnsureSuccessStatusCode();

Is your feature request supported by WireMock (java version)? Please provide details.
Verified with WireMock.Net author and it is possible to include this feature.

Additional context
More discussion here
https://github.com/WireMock-Net/WireMock.Net/issues/1239

Originally created by @GomesNayagam on GitHub (Jan 30, 2025). Originally assigned to: @StefH on GitHub. **Feature Request** I am planning to use grpc mock using docker container via WireMockContainerBuilder() like standalone WIreMock.Start() server. While doing that i noticed i am missing .AddProtoDefinition(id, protoDefinitionText) signatue for Container way. **Describe the solution you'd like** Prefer to as close as possible like ```c# var server = WireMockServer.Start() server.AddProtoDefinition(id, protoDefinitionText) var wireMockContainer = new WireMockContainerBuilder() .WithAutoRemove(true) .WithCleanUp(true) // .WithBindMount(TestHelper.GetAbsolutePath(@"mocks\greet"), "/home/wiremock") // .AddProtoDefinition(id, protoDefinitionText) .WithCommand("--UseHttp2") .AddUrl("grpc://*:9090") .AddUrl("http://*:8080") .Build(); ``` **Describe alternatives you've considered** ```c# var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json")); result.EnsureSuccessStatusCode(); ``` **Is your feature request supported by [WireMock (java version)](https://www.wiremock.org)? Please provide details.** Verified with WireMock.Net author and it is possible to include this feature. **Additional context** More discussion here https://github.com/WireMock-Net/WireMock.Net/issues/1239
adam added the feature label 2025-12-29 15:30:23 +01:00
adam closed this issue 2025-12-29 15:30:23 +01:00
Author
Owner

@StefH commented on GitHub (Feb 7, 2025):

https://github.com/WireMock-Net/WireMock.Net/pull/1250

@StefH commented on GitHub (Feb 7, 2025): https://github.com/WireMock-Net/WireMock.Net/pull/1250
Author
Owner

@StefH commented on GitHub (Feb 8, 2025):

@GomesNayagam

A new preview version from WireMock.Net + Docker container is created: 1.7.2-preview-01

This example should work now:

var wireMockContainer = new WireMockContainerBuilder()
    .WithAutoRemove(true)
    .WithCleanUp(true)
    .AddUrl("grpc://*:9090")
    .AddProtoDefinition("my-greeter", ReadFile("greet.proto"))
    .Build();
@StefH commented on GitHub (Feb 8, 2025): @GomesNayagam A new preview version from WireMock.Net + Docker container is created: 1.7.2-preview-01 This example should work now: ``` c# var wireMockContainer = new WireMockContainerBuilder() .WithAutoRemove(true) .WithCleanUp(true) .AddUrl("grpc://*:9090") .AddProtoDefinition("my-greeter", ReadFile("greet.proto")) .Build(); ```
Author
Owner

@GomesNayagam commented on GitHub (Feb 11, 2025):

@StefH it throws method not allowed error:

Code used using these files
a) https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/protobuf-mapping-3.json
b)https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/Grpc/greet.proto


            var protoDefinition = File.ReadAllText(
             TestHelper.GetAbsolutePath("Grpc") + @"\greet.proto"
             );

            var wireMockContainer = new WireMockContainerBuilder()
                .WithAutoRemove(true)
                .WithCleanUp(true)
                .WithCommand("--UseHttp2")
                .AddUrl("grpc://*:9090")
                .AddUrl("http://*:8080")
                .AddProtoDefinition("my-greeter", protoDefinition)
                .Build();

            await wireMockContainer.StartAsync();

            var mappingsJson = File.ReadAllText(
                TestHelper.GetAbsolutePath(@"mocks\greet") + @"\hellorequest.json"
            );

            var address = wireMockContainer.GetPublicUrls()[9090];
            var address2 = wireMockContainer.GetPublicUrls()[8080];

            using var httpClient = wireMockContainer.CreateClient();

            var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json"));
            result.EnsureSuccessStatusCode();

            var channel = GrpcChannel.ForAddress(address);

            var client = new Greeter.GreeterClient(channel);

            var res = await client.SayHelloAsync(new HelloRequest { Name = "stef" });
@GomesNayagam commented on GitHub (Feb 11, 2025): @StefH it throws method not allowed error: Code used using these files a) https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/protobuf-mapping-3.json b)https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/Grpc/greet.proto ```c# var protoDefinition = File.ReadAllText( TestHelper.GetAbsolutePath("Grpc") + @"\greet.proto" ); var wireMockContainer = new WireMockContainerBuilder() .WithAutoRemove(true) .WithCleanUp(true) .WithCommand("--UseHttp2") .AddUrl("grpc://*:9090") .AddUrl("http://*:8080") .AddProtoDefinition("my-greeter", protoDefinition) .Build(); await wireMockContainer.StartAsync(); var mappingsJson = File.ReadAllText( TestHelper.GetAbsolutePath(@"mocks\greet") + @"\hellorequest.json" ); var address = wireMockContainer.GetPublicUrls()[9090]; var address2 = wireMockContainer.GetPublicUrls()[8080]; using var httpClient = wireMockContainer.CreateClient(); var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json")); result.EnsureSuccessStatusCode(); var channel = GrpcChannel.ForAddress(address); var client = new Greeter.GreeterClient(channel); var res = await client.SayHelloAsync(new HelloRequest { Name = "stef" }); ```
Author
Owner

@StefH commented on GitHub (Feb 11, 2025):

Are you sure you have the correct docker container version?
Best is to delete all local docker containers for WireMock.Net Linux / Alpine Linux and then try again.

BTW I used protobug-mapping-4 as test.
See
https://github.com/WireMock-Net/WireMock.Net/pull/1250/files

@StefH commented on GitHub (Feb 11, 2025): Are you sure you have the correct docker container version? Best is to delete all local docker containers for WireMock.Net Linux / Alpine Linux and then try again. BTW I used protobug-mapping-4 as test. See https://github.com/WireMock-Net/WireMock.Net/pull/1250/files
Author
Owner

@GomesNayagam commented on GitHub (Feb 11, 2025):

thats the good point let me delete the image and retry and let u know

@GomesNayagam commented on GitHub (Feb 11, 2025): thats the good point let me delete the image and retry and let u know
Author
Owner

@GomesNayagam commented on GitHub (Feb 11, 2025):

apologies for my silly mistake, it works. great work once again. @StefH pls tag me when it is publicly available.

hope u tag new version for those docker image as well besides client version.

@GomesNayagam commented on GitHub (Feb 11, 2025): apologies for my silly mistake, it works. great work once again. @StefH pls tag me when it is publicly available. hope u tag new version for those docker image as well besides client version.
Author
Owner

@StefH commented on GitHub (Feb 12, 2025):

  • new NuGet 1.7.2 will be released within the hour
  • docker images later today
  • all docker images are tagged 1.7.2 and latest, however I still think you need delete your local latest to get the real latest version, I need to think on that how the dependency between the NuGet and Docker version can be defined / enforced.....
@StefH commented on GitHub (Feb 12, 2025): - new NuGet 1.7.2 will be released within the hour - docker images later today - all docker images are tagged _1.7.2_ and _latest_, however I still think you need delete your local _latest_ to get the real latest version, I need to think on that how the dependency between the NuGet and Docker version can be defined / enforced.....
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#668