public void TestServerStreamingWithException()
        {
            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.True(logEntry.IsFailure);
                HelloException helloException = logEntry.Exception as HelloException;
                Assert.NotNull(helloException);

                Assert.AreEqual(TEST_REQUEST_ID, helloException.RequestId);

                Assert.NotNull(helloException.Failure);
                Assert.AreEqual(1, helloException.Failure.Errors.Count);
                Assert.NotNull(helloException.Failure.Errors[0].ErrorCode);
                Assert.NotNull(helloException.Failure.Errors[0].ErrorCode.RequestError);
            };
            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);

                // Response is null if there's an exception.
                Assert.IsNull(logEntry.Response);

                Assert.AreEqual(TEST_CUSTOMER_ID, logEntry.CustomerId);
                Assert.True(logEntry.IsFailure);
                HelloException helloException = logEntry.Exception as HelloException;
                Assert.NotNull(helloException);

                Assert.AreEqual(TEST_REQUEST_ID, helloException.RequestId);

                Assert.NotNull(helloException.Failure);
                Assert.AreEqual(1, helloException.Failure.Errors.Count);
                Assert.NotNull(helloException.Failure.Errors[0].ErrorCode);
                Assert.NotNull(helloException.Failure.Errors[0].ErrorCode.RequestError);
            };

            ClientInterceptorContext <HelloRequest, HelloResponse> context =
                GetClientInterceptorContext();
            AsyncServerStreamingCall <HelloResponse> call =
                StreamingContinuationWithException <HelloResponse>();

            handler.HandleAsyncServerStreamingLogging(TEST_REQUEST,
                                                      null, context, new AggregateException(TEST_EXCEPTION),
                                                      call);
        }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        HelloException he = new HelloException();

        try {
            he.Foo();
        } catch (SimpleException ) {
            System.Console.WriteLine("Caught it!");
        }

        try
        {
            File.OpenRead("NonExistentFile");
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

        FileStream outStream = null;
        FileStream inStream = null;
        try
        {
            outStream = File.OpenWrite("DestinationFile.txt");
            inStream = File.OpenRead("BogusInputFile.txt");
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        finally
        {
            if (outStream != null)
            {
                outStream.Close();
                Console.WriteLine("outStream closed.");
            }
            if (inStream != null)
            {
                inStream.Close();
                Console.WriteLine("inStream closed.");
            }
        }

        System.Console.ReadKey();
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogEntryTests"/> class.
        /// </summary>
        public LogEntryTests()
        {
            // Initialize request metadata.
            TEST_REQUEST_METADATA = new Metadata();
            TEST_REQUEST_METADATA.Add(MetadataKeyNames.DeveloperToken, TEST_DEVELOPER_TOKEN);
            TEST_REQUEST_METADATA.Add(TEST_KEY1, TEST_VALUE1);

            // Initialize response metadata.
            TEST_RESPONSE_METADATA = new Metadata();
            TEST_RESPONSE_METADATA.Add(MetadataKeyNames.RequestId, TEST_REQUEST_ID);
            TEST_RESPONSE_METADATA.Add(TEST_KEY2, TEST_VALUE2);

            // Create an exception for testing purposes.

            TEST_EXCEPTION = AdsTestUtils.CreateException(TEST_ERROR_MESSAGE, TEST_ERROR_TRIGGER,
                                                          TEST_REQUEST_ID);

            TEST_STREAMING_RESPONSE_METADATA = new Metadata();
            TEST_STREAMING_RESPONSE_METADATA.Add(TEST_KEY2, TEST_VALUE2);
        }