1818using System . Linq ;
1919using System . Threading . Tasks ;
2020using Xunit ;
21+ using System ;
22+ using Google . Api . Gax . Grpc ;
2123
2224namespace Google . Api . Generator . IntegrationTests
2325{
@@ -36,29 +38,55 @@ public void SimpleEcho()
3638 public void EchoError ( )
3739 {
3840 var client = CreateClient ( ) ;
39- var request = new EchoRequest { Error = new Rpc . Status { Code = ( int ) Code . Cancelled } } ;
41+ var request = new EchoRequest { Error = new Rpc . Status { Code = ( int ) Code . Cancelled } } ;
4042 var exception = Assert . Throws < RpcException > ( ( ) => client . Echo ( request ) ) ;
41- Assert . Equal ( request . Error . Code , ( int ) exception . Status . StatusCode ) ;
43+ Assert . Equal ( request . Error . Code , ( int ) exception . Status . StatusCode ) ;
4244 }
4345
44- // Note: header testing is currently at least tricky. (It may be feasible for a gRPC interceptor.)
45- // We'll defer that for now; perhaps in a future version of the server it could check the expected
46- // header values.
46+ [ SkippableFact ]
47+ protected void EchoCustomError ( )
48+ {
49+ var client = CreateClient ( ) ;
50+ var request = new FailEchoWithDetailsRequest ( ) ;
51+ RpcException e = Assert . Throws < RpcException > ( ( ) => client . FailEchoWithDetails ( request ) ) ;
52+ Console . WriteLine ( e ) ;
53+
54+ // Assertions for meaningful data inside the exception
55+ var rpcStatusDetails = e . GetRpcStatus ( ) ;
56+ Console . WriteLine ( $ "Rpc Details: { rpcStatusDetails } ") ;
57+ Assert . NotNull ( rpcStatusDetails ) ;
58+ Assert . Equal ( ( int ) Grpc . Core . StatusCode . Aborted , rpcStatusDetails . Code ) ;
59+ Assert . Equal ( "This is an error generated by the server" , rpcStatusDetails . Message ) ;
4760
48- public class EchoRestTest : EchoTestBase { }
4961
50- public class EchoGrpcTest : EchoTestBase
62+ // Assertions for localized message
63+ var localizedMessage = e . GetLocalizedMessage ( ) ;
64+ Assert . Equal ( "fr-CH" , localizedMessage . Locale ) ;
65+ Assert . Equal ( "This LocalizedMessage should be treated specially" , localizedMessage . Message ) ;
66+
67+ // Asserts for the custom error (PoetryError)
68+ // This currently fails for Rest
69+ Assert . NotNull ( e . GetStatusDetail < PoetryError > ( ) ) ;
70+ }
71+ }
72+
73+ // Note: header testing is currently at least tricky. (It may be feasible for a gRPC interceptor.)
74+ // We'll defer that for now; perhaps in a future version of the server it could check the expected
75+ // header values.
76+ public class EchoRestTest : EchoTestBase { }
77+
78+ public class EchoGrpcTest : EchoTestBase
79+ {
80+ // Note: currently only for gRPC as we don't support streaming methods in REST yet.
81+ [ SkippableFact ]
82+ public async Task Expand ( )
5183 {
52- // Note: currently only for gRPC as we don't support streaming methods in REST yet.
53- [ SkippableFact ]
54- public async Task Expand ( )
55- {
56- string content = "The rain in Spain stays mainly on the plain!" ;
57- var client = CreateClient ( ) ;
58- var stream = client . Expand ( new ExpandRequest { Content = content } ) ;
59- var items = await stream . GetResponseStream ( ) . Select ( resp => resp . Content ) . ToListAsync ( ) ;
60- Assert . Equal ( content , string . Join ( " " , items ) ) ;
61- }
84+ string content = "The rain in Spain stays mainly on the plain!" ;
85+ var client = CreateClient ( ) ;
86+ var stream = client . Expand ( new ExpandRequest { Content = content } ) ;
87+ var items = await stream . GetResponseStream ( ) . Select ( resp => resp . Content ) . ToListAsync ( ) ;
88+ Assert . Equal ( content , string . Join ( " " , items ) ) ;
6289 }
6390 }
91+
6492}
0 commit comments