Skip to content

Commit 822206c

Browse files
committed
policy
1 parent cc827ea commit 822206c

File tree

3 files changed

+107
-13
lines changed

3 files changed

+107
-13
lines changed

test/WireMock.Net.Tests/Grpc/WireMockServerTests.Grpc.cs

+96
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Google.Protobuf.WellKnownTypes;
1111
using Greet;
1212
using Grpc.Net.Client;
13+
using NarrowIntegrationTest.Lookup;
1314
using WireMock.Matchers;
1415
using WireMock.RequestBuilders;
1516
using WireMock.ResponseBuilders;
@@ -36,6 +37,12 @@ message HelloRequest {
3637
3738
message HelloReply {
3839
string message = 1;
40+
enum PhoneType {
41+
none = 0;
42+
mobile = 1;
43+
home = 2;
44+
}
45+
PhoneType phoneType = 2;
3946
}
4047
";
4148

@@ -600,5 +607,94 @@ public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Duration_
600607
// Assert
601608
reply.Du.Should().Be(new Duration { Seconds = seconds, Nanos = nanos });
602609
}
610+
611+
[Fact]
612+
public async Task WireMockServer_WithBodyAsProtoBuf_Enum_UsingGrpcGeneratedClient()
613+
{
614+
// Arrange
615+
var definition = await System.IO.File.ReadAllTextAsync("./Grpc/greet.proto");
616+
617+
using var server = WireMockServer.Start(useHttp2: true);
618+
619+
server
620+
.Given(Request.Create()
621+
.UsingPost()
622+
.WithPath("/greet.Greeter/SayHello")
623+
.WithBody(new NotNullOrEmptyMatcher())
624+
)
625+
.RespondWith(Response.Create()
626+
.WithHeader("Content-Type", "application/grpc")
627+
.WithTrailingHeader("grpc-status", "0")
628+
.WithBodyAsProtoBuf(definition, "greet.HelloReply",
629+
new HelloReply
630+
{
631+
Message = "hello",
632+
PhoneType = HelloReply.Types.PhoneType.Home
633+
}
634+
)
635+
);
636+
637+
// Act
638+
var channel = GrpcChannel.ForAddress(server.Url!);
639+
var client = new Greeter.GreeterClient(channel);
640+
641+
var reply = await client.SayHelloAsync(new HelloRequest());
642+
643+
// Assert
644+
reply.Message.Should().Be("hello");
645+
reply.PhoneType.Should().Be(HelloReply.Types.PhoneType.Home);
646+
}
647+
648+
[Fact]
649+
public async Task WireMockServer_WithBodyAsProtoBuf_Enum_UsingPolicyGrpcGeneratedClient()
650+
{
651+
// Arrange
652+
const int seconds = 1722301323;
653+
const int nanos = 12300;
654+
const string version = "test";
655+
const string correlationId = "correlation";
656+
var definition = await System.IO.File.ReadAllTextAsync("./Grpc/policy.proto");
657+
658+
using var server = WireMockServer.Start(useHttp2: true);
659+
660+
server
661+
.Given(Request.Create()
662+
.UsingPost()
663+
.WithPath("/Policy.PolicyService/GetVersion")
664+
.WithBody(new NotNullOrEmptyMatcher())
665+
)
666+
.RespondWith(Response.Create()
667+
.WithHeader("Content-Type", "application/grpc")
668+
.WithTrailingHeader("grpc-status", "0")
669+
.WithBodyAsProtoBuf(definition, "NarrowIntegrationTest.Lookup.GetVersionResponse",
670+
new GetVersionResponse
671+
{
672+
Version = version,
673+
DateHired = new Timestamp
674+
{
675+
Seconds = seconds,
676+
Nanos = nanos
677+
},
678+
Client = new NarrowIntegrationTest.Lookup.Client
679+
{
680+
ClientName = NarrowIntegrationTest.Lookup.Client.Types.Clients.BillingCenter,
681+
CorrelationId = correlationId
682+
}
683+
}
684+
)
685+
);
686+
687+
// Act
688+
var channel = GrpcChannel.ForAddress(server.Url!);
689+
var client = new PolicyService.PolicyServiceClient(channel);
690+
691+
var reply = await client.GetVersionAsync(new GetVersionRequest());
692+
693+
// Assert
694+
reply.Version.Should().Be(version);
695+
reply.DateHired.Should().Be(new Timestamp { Seconds = seconds, Nanos = nanos });
696+
reply.Client.ClientName.Should().Be(NarrowIntegrationTest.Lookup.Client.Types.Clients.BillingCenter);
697+
reply.Client.CorrelationId.Should().Be(correlationId);
698+
}
603699
}
604700
#endif

test/WireMock.Net.Tests/Grpc/greet.proto

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ message HelloRequest {
2020

2121
message HelloReply {
2222
string message = 1;
23+
enum PhoneType {
24+
none = 0;
25+
mobile = 1;
26+
home = 2;
27+
}
28+
PhoneType phoneType = 2;
2329
}
2430

2531
message MyMessageTimestamp {

test/WireMock.Net.Tests/Grpc/policy.proto

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
syntax = "proto3";
22

3+
option csharp_namespace = "NarrowIntegrationTest.Lookup";
4+
35
import "google/protobuf/timestamp.proto";
46

5-
package Policy2;
7+
package Policy;
68

7-
service PolicyService2 {
9+
service PolicyService {
810
rpc GetVersion (GetVersionRequest) returns (GetVersionResponse);
9-
rpc GetVersion2 (GetVersion2Request) returns (GetVersion2Response);
10-
}
11-
12-
// REQUEST/RESPONSE DEFINITIONS
13-
14-
message GetVersion2Request {
15-
Client Client = 1;
16-
1711
}
18-
message GetVersion2Response {
19-
string Version = 1;
2012

21-
}
2213
message GetVersionRequest {
2314
Client Client = 1;
2415

2516
}
2617
message GetVersionResponse {
2718
string Version = 1;
2819
google.protobuf.Timestamp DateHired = 2;
20+
Client Client = 3;
2921
}
3022

3123
message Client {

0 commit comments

Comments
 (0)