11using System ;
2- using System . Collections . Generic ;
32using System . Text . Json ;
43using System . Threading . Tasks ;
54using FluentAssertions ;
87using System . Text . Json . Serialization ;
98using PactNet ;
109using PactNet . Exceptions ;
10+ using PactNet . Extensions . Grpc ;
1111using PactNet . Output . Xunit ;
1212using Xunit . Abstractions ;
1313
1414namespace GrpcGreeterClient . Tests
1515{
1616 public class GrpcGreeterClientTests : IDisposable
1717 {
18- private readonly ISynchronousPluginPactBuilderV4 pact ;
18+ private readonly IGrpcPactBuilderV4 pact ;
1919
2020 public GrpcGreeterClientTests ( ITestOutputHelper output )
2121 {
2222 var config = new PactConfig
2323 {
2424 PactDir = "../../../../pacts/" ,
25- Outputters = new [ ] { new XunitOutput ( output ) } ,
25+ Outputters = new [ ]
26+ {
27+ new XunitOutput ( output )
28+ } ,
2629 DefaultJsonSettings = new JsonSerializerOptions
2730 {
2831 PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
@@ -32,26 +35,19 @@ public GrpcGreeterClientTests(ITestOutputHelper output)
3235 LogLevel = PactLogLevel . Information
3336 } ;
3437
35- this . pact = Pact . V4 ( "grpc-greeter-client" , "grpc-greeter" , config )
36- . WithSynchronousPluginInteractions ( "protobuf" , "0.4.0" , transport : "grpc" ) ;
38+ this . pact = Pact . V4 ( "grpc-greeter-client" , "grpc-greeter" , config ) . WithGrpcInteractions ( ) ;
3739 }
3840
3941 [ Fact ]
4042 public void ThrowsExceptionWhenNoGrpcClientRequestMade ( )
4143 {
4244 string protoFilePath = Path . Join ( Directory . GetCurrentDirectory ( ) , ".." , ".." , ".." , ".." , "GrpcGreeterClient" , "Protos" , "greet.proto" ) ;
43- var content = new Dictionary < string , object >
44- {
45- {
46- "pact:proto" , protoFilePath
47- } ,
48- { "pact:proto-service" , "Greeter/SayHello" } ,
49- { "pact:content-type" , "application/protobuf" } ,
50- { "request" , new { name = "matching(equalTo, 'foo')" } } ,
51- { "response" , new { message = "matching(equalTo, 'Hello foo')" } }
52- } ;
53-
54- this . pact . UponReceiving ( "A greeting request to say hello." ) . WithContent ( "application/grpc" , content ) ;
45+ this . pact
46+ . UponReceiving ( "A greeting request to say hello." )
47+ . WithRequest ( protoFilePath , nameof ( Greeter ) , "SayHello" ,
48+ new { name = "matching(equalTo, 'foo')" } )
49+ . WillRespond ( )
50+ . WithBody ( new { message = "matching(equalTo, 'Hello foo')" } ) ;
5551
5652 Assert . Throws < PactFailureException > ( ( ) =>
5753 this . pact . Verify ( _ =>
@@ -63,20 +59,14 @@ public void ThrowsExceptionWhenNoGrpcClientRequestMade()
6359 [ Fact ]
6460 public async Task WritesPactForGreeterSayHelloRequest ( )
6561 {
62+ // Arrange
6663 string protoFilePath = Path . Join ( Directory . GetCurrentDirectory ( ) , ".." , ".." , ".." , ".." , "GrpcGreeterClient" , "Protos" , "greet.proto" ) ;
67- var content = new Dictionary < string , object >
68- {
69- {
70- "pact:proto" , protoFilePath
71- } ,
72- { "pact:proto-service" , "Greeter/SayHello" } ,
73- { "pact:content-type" , "application/protobuf" } ,
74- { "request" , new { name = "matching(equalTo, 'foo')" } } ,
75- { "response" , new { message = "matching(equalTo, 'Hello foo')" } }
76- } ;
77-
78-
79- this . pact . UponReceiving ( "A greeting request to say hello." ) . WithContent ( "application/grpc" , content ) ;
64+ this . pact
65+ . UponReceiving ( "A greeting request to say hello." )
66+ . WithRequest ( protoFilePath , nameof ( Greeter ) , "SayHello" ,
67+ new { name = "matching(equalTo, 'foo')" } )
68+ . WillRespond ( )
69+ . WithBody ( new { message = "matching(equalTo, 'Hello foo')" } ) ;
8070
8171 await this . pact . VerifyAsync ( async ctx =>
8272 {
0 commit comments