How to use GRPC mock with namespace alone #689

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

Originally created by @GomesNayagam on GitHub (May 10, 2025).

Originally assigned to: @StefH on GitHub.

Here is the proto file

syntax = "proto3";

option csharp_namespace = "Pricing.Rating";

import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

// The Classification service definition.
service Classifications {
  rpc GetRatingPeriod (Ratingperiod) returns (RatingResponse);
}

code


            server
                //.AddProtoDefinition(id, protoDefinitionText)
                .Given(
                    Request
                        .Create()
                        .UsingPost()
                        .WithHttpVersion("2")
                        .WithPath("Classifications/GetRatingPeriod")
                        .WithBodyAsProtoBuf(
                            protoDefinition,
                            "Ratingperiod",
                            protoBufJsonMatcher
                        )
                )
                .WithProtoDefinition(id)
                .RespondWith(
                    Response
                        .Create()
                        .WithHeader("Content-Type", "application/grpc")
                        .WithTrailingHeader("grpc-status", "0")
                        .WithBodyAsProtoBuf(
                            protoDefinition,
                            "RatingResponse",
                            res!
                        )
                        .WithTransformer()
                );
Originally created by @GomesNayagam on GitHub (May 10, 2025). Originally assigned to: @StefH on GitHub. Here is the proto file ``` proto syntax = "proto3"; option csharp_namespace = "Pricing.Rating"; import "google/protobuf/empty.proto"; import "google/protobuf/wrappers.proto"; // The Classification service definition. service Classifications { rpc GetRatingPeriod (Ratingperiod) returns (RatingResponse); } ``` code ``` c# server //.AddProtoDefinition(id, protoDefinitionText) .Given( Request .Create() .UsingPost() .WithHttpVersion("2") .WithPath("Classifications/GetRatingPeriod") .WithBodyAsProtoBuf( protoDefinition, "Ratingperiod", protoBufJsonMatcher ) ) .WithProtoDefinition(id) .RespondWith( Response .Create() .WithHeader("Content-Type", "application/grpc") .WithTrailingHeader("grpc-status", "0") .WithBodyAsProtoBuf( protoDefinition, "RatingResponse", res! ) .WithTransformer() ); ```
adam added the question label 2025-12-29 15:30:52 +01:00
adam closed this issue 2025-12-29 15:30:52 +01:00
Author
Owner

@StefH commented on GitHub (May 10, 2025):

@GomesNayagam

You should just add the namespace as prefix, so Pricing.Rating.Ratingperiod.

See these:

@StefH commented on GitHub (May 10, 2025): @GomesNayagam You should just add the namespace as prefix, so `Pricing.Rating.Ratingperiod`. See these: - **proto file** : https://github.com/StefH/ProtoBufJsonConverter/blob/main/test/ProtoBufJsonConverterTests/ConverterTests.cs#L48 - **unit test**: https://github.com/StefH/ProtoBufJsonConverter/blob/main/test/ProtoBufJsonConverterTests/ConverterTests.cs#L247
Author
Owner

@GomesNayagam commented on GitHub (May 13, 2025):

@StefH thanks for your response, I added below like code did not work with my version 1.6.11

Tried 1

.WithPath("Classifications/GetRatingPeriod")
.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.Ratingperiod",
                            protoBufJsonMatcher
                        )

.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.RatingResponse",
                            res!
                        )

Tried 2

.WithPath("Pricing.Rating.Classifications/GetRatingPeriod")
.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.Ratingperiod",
                            protoBufJsonMatcher
                        )

.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.RatingResponse",
                            res!
                        )

Tried 3

.WithPath("/Pricing.Rating/Classifications/GetRatingPeriod")
.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.Ratingperiod",
                            protoBufJsonMatcher
                        )

.WithBodyAsProtoBuf(
                            protoDefinition,
                            "Pricing.Rating.RatingResponse",
                            res!
                        )
@GomesNayagam commented on GitHub (May 13, 2025): @StefH thanks for your response, I added below like code did not work with my version 1.6.11 Tried 1 ``` .WithPath("Classifications/GetRatingPeriod") .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.Ratingperiod", protoBufJsonMatcher ) .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.RatingResponse", res! ) ``` Tried 2 ``` .WithPath("Pricing.Rating.Classifications/GetRatingPeriod") .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.Ratingperiod", protoBufJsonMatcher ) .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.RatingResponse", res! ) ``` Tried 3 ``` .WithPath("/Pricing.Rating/Classifications/GetRatingPeriod") .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.Ratingperiod", protoBufJsonMatcher ) .WithBodyAsProtoBuf( protoDefinition, "Pricing.Rating.RatingResponse", res! ) ```
Author
Owner

@StefH commented on GitHub (May 13, 2025):

@GomesNayagam
In that case, try the most recent version.

@StefH commented on GitHub (May 13, 2025): @GomesNayagam In that case, try the most recent version.
Author
Owner

@GomesNayagam commented on GitHub (May 13, 2025):

@StefH sure i will wait for this issue to be go in https://github.com/wiremock/WireMock.Net/issues/1280

@GomesNayagam commented on GitHub (May 13, 2025): @StefH sure i will wait for this issue to be go in https://github.com/wiremock/WireMock.Net/issues/1280
Author
Owner

@StefH commented on GitHub (May 15, 2025):

@GomesNayagam
New version should have the fix.

@StefH commented on GitHub (May 15, 2025): @GomesNayagam New version should have the fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#689