public void ValidTrailer_GetRpcStatus() { var status = new Status { Code = 123, Message = "This is a message", }; var metadata = new Metadata(); metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray()); RpcException ex = new RpcException(s_status, metadata); Assert.Equal(status, ex.GetRpcStatus()); // We don't have any details Assert.Null(ex.GetBadRequest()); Assert.Null(ex.GetErrorInfo()); Assert.Null(ex.GetStatusDetail <DebugInfo>()); }
public void ValidTrailer_ArbitraryMessages() { var debugInfo = new DebugInfo { Detail = "This is some debugging information" }; var requestInfo = new RequestInfo { RequestId = "request-id" }; var badRequest = new BadRequest { FieldViolations = { new BadRequest.Types.FieldViolation { Description = "Negative", Field = "speed" } } }; var status = new Status { Code = 123, Message = "This is a message", Details = { Any.Pack(debugInfo), Any.Pack(requestInfo), Any.Pack(badRequest) } }; var metadata = new Metadata(); metadata.Add("key-1", "value1"); metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray()); metadata.Add("other-info-bin", new byte[] { 1, 2, 3 }); metadata.Add("key-2", "value2"); RpcException ex = new RpcException(s_status, metadata); Assert.Equal(badRequest, ex.GetBadRequest()); Assert.Null(ex.GetErrorInfo()); Assert.Equal(debugInfo, ex.GetStatusDetail <DebugInfo>()); Assert.Equal(requestInfo, ex.GetStatusDetail <RequestInfo>()); Assert.Equal(badRequest, ex.GetStatusDetail <BadRequest>()); }
public void GetStatusDetail_BadlyPackedMessage() { var debugInfo = new DebugInfo { Detail = "Debug information" }; var any = Any.Pack(debugInfo); any.Value = ByteString.CopyFromUtf8("This isn't valid data!"); var status = new Status { Details = { any } }; var metadata = new Metadata(); metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray()); RpcException ex = new RpcException(s_status, metadata); Assert.Equal(status, ex.GetRpcStatus()); Assert.Null(ex.GetStatusDetail <DebugInfo>()); }
public void GetErrorInfo_Present() { var errorInfo = new ErrorInfo { Domain = "googleapis.com", Reason = "broken" }; var status = new Status { Code = 123, Message = "This is a message", Details = { Any.Pack(errorInfo), } }; var metadata = new Metadata(); metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray()); RpcException ex = new RpcException(s_status, metadata); Assert.Equal(errorInfo, ex.GetErrorInfo()); }