10
10
using Google . Protobuf . WellKnownTypes ;
11
11
using Greet ;
12
12
using Grpc . Net . Client ;
13
+ using NarrowIntegrationTest . Lookup ;
13
14
using WireMock . Matchers ;
14
15
using WireMock . RequestBuilders ;
15
16
using WireMock . ResponseBuilders ;
@@ -36,6 +37,12 @@ message HelloRequest {
36
37
37
38
message HelloReply {
38
39
string message = 1;
40
+ enum PhoneType {
41
+ none = 0;
42
+ mobile = 1;
43
+ home = 2;
44
+ }
45
+ PhoneType phoneType = 2;
39
46
}
40
47
" ;
41
48
@@ -600,5 +607,94 @@ public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Duration_
600
607
// Assert
601
608
reply . Du . Should ( ) . Be ( new Duration { Seconds = seconds , Nanos = nanos } ) ;
602
609
}
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
+ }
603
699
}
604
700
#endif
0 commit comments