public void TestAsyncUnaryCallWithPartialFailure() { GoogleAdsConfig config = new GoogleAdsConfig(); LoggingHandler handler = new LoggingHandler(config); handler.WriteSummaryLogs = delegate(LogEntry logEntry) { Assert.AreEqual(config.ServerUrl, logEntry.Host); Assert.AreEqual(TEST_METHOD_IN_LOGS, logEntry.Method); CompareMetadata(TEST_REQUEST_METADATA, logEntry.RequestHeaders); Assert.False(logEntry.IsFailure); }; handler.WriteDetailedLogs = delegate(LogEntry logEntry) { Assert.AreEqual(config.ServerUrl, logEntry.Host); Assert.AreEqual(TEST_METHOD_IN_LOGS, logEntry.Method); CompareMetadata(TEST_REQUEST_METADATA, logEntry.RequestHeaders); CompareMetadata(TEST_RESPONSE_METADATA, logEntry.ResponseHeaders); Assert.AreSame(TEST_REQUEST, logEntry.Request); Assert.AreSame(TEST_RESPONSE_PARTIAL_FAILURES, logEntry.Response); Assert.AreEqual(TEST_CUSTOMER_ID, logEntry.CustomerId); Assert.False(logEntry.IsFailure); Assert.AreEqual(TEST_PARTIAL_FAILURE_TEXT, logEntry.PartialFailures); }; ClientInterceptorContext <HelloRequest, HelloResponse> context = GetClientInterceptorContext(); AsyncUnaryCall <HelloResponse> call = ContinuationWithPartialFailures(TEST_REQUEST, context); handler.HandleAsyncUnaryLogging(TEST_REQUEST, context, call.ResponseAsync, call); }
public void TestAsyncUnaryCallWithException() { GoogleAdsConfig config = new GoogleAdsConfig(); LoggingHandler handler = new LoggingHandler(config); handler.WriteLogs = delegate(LogEntry logEntry) { Assert.AreEqual(config.ServerUrl, logEntry.Host); Assert.AreEqual(TEST_METHOD_IN_LOGS, logEntry.Method); CompareMetadata(TEST_REQUEST_METADATA, logEntry.RequestHeaders); CompareMetadata(TEST_RESPONSE_METADATA, logEntry.ResponseHeaders); Assert.AreSame(TEST_REQUEST, logEntry.Request); // Response is null if there's an exception. Assert.IsNull(logEntry.Response); Assert.AreEqual(TEST_CUSTOMER_ID, logEntry.CustomerId); Assert.True(logEntry.IsFailure); GoogleAdsException googleAdsException = logEntry.Exception as GoogleAdsException; Assert.NotNull(googleAdsException); Assert.AreEqual(TEST_REQUEST_ID, googleAdsException.RequestId); Assert.NotNull(googleAdsException.Failure); Assert.AreEqual(1, googleAdsException.Failure.Errors.Count); Assert.NotNull(googleAdsException.Failure.Errors[0].ErrorCode); Assert.NotNull(googleAdsException.Failure.Errors[0].ErrorCode.DistinctError); }; ClientInterceptorContext <HelloRequest, HelloResponse> context = GetClientInterceptorContext(); AsyncUnaryCall <HelloResponse> call = ContinuationWithException(TEST_REQUEST, context); handler.HandleAsyncUnaryLogging(TEST_REQUEST, context, call.ResponseAsync, call); }
/// <summary> /// Intercepts an asynchronous invocation of a simple remote call. /// </summary> /// <param name="request">The request message of the invocation.</param> /// <param name="context">The <see cref="ClientInterceptorContext{TRequest, TResponse}" /> /// associated with the current invocation.</param> /// <param name="continuationCallback">The callback that continues the invocation process. /// This can be invoked zero or more times by the interceptor. /// The interceptor can invoke the continuation passing the given /// request value and context arguments, or substitute them as it sees fit.</param> /// <returns> /// An instance of <see cref="AsyncUnaryCall{TResponse}" /> /// representing an asynchronous unary invocation. /// The interceptor can simply return the return value of the /// <paramref name="continuationCallback"/> delegate passed to it intact, or construct its /// own substitute. /// </returns> public override AsyncUnaryCall <TResponse> AsyncUnaryCall <TRequest, TResponse>( TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncUnaryCallContinuation <TRequest, TResponse> continuationCallback) { AsyncUnaryCall <TResponse> call = continuationCallback(request, context); Task t = call.ResponseAsync.ContinueWith( delegate(Task <TResponse> oldTask) { loggingHandler.HandleAsyncUnaryLogging(request, context, oldTask, call); }); t.Wait(); return(UnaryRpcInterceptor.Intercept(call)); }