Exemplo n.º 1
0
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        public static void Main(string[] args)
        {
            // Turn on logging. This is useful for debugging your requests.
            TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
                                     "C:\\logs\\details.log", System.Diagnostics.SourceLevels.All);

            // If the API log doesn't give you enough details, then you can enable more low level
            // logging at grpc level. Keep in mind that this can get pretty detailed and long. The
            // grpc logs are written to stderr.
            // You can find all the supported environment variables here:
            // https://github.com/grpc/grpc/blob/master/doc/environment_variables.md
            // Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "DEBUG");
            // Environment.SetEnvironmentVariable("GRPC_TRACE", "http");

            // If you simply want to try out a code example, you can create an instance of it here,
            // and call it's Run method. E.g.

            // Optional: If you have specified these keys in the App.config file, you can skip
            // creating a GoogleAdsConfig object and do
            // GoogleAdsClient googleAdsClient = new GoogleAdsClient();

            // string developerToken = "INSERT_YOUR_DEVELOPER_TOKEN_HERE";
            // string oAuth2clientId = "INSERT_OAUTH2_CLIENT_ID_HERE";
            // string oAuth2Secret = "INSERT_OAUTH2_CLIENT_SECRET_HERE";
            // string oAuth2RefreshToken = "INSERT_OAUTH2_REFRESH_TOKEN_HERE";
            // long loginCustomerId = long.Parse("INSERT_LOGIN_CUSTOMER_ID_HERE");

            // GoogleAdsConfig googleAdsConfig = new GoogleAdsConfig()
            // {
            //     DeveloperToken = developerToken,
            //     LoginCustomerId = loginCustomerId.ToString(),
            //     OAuth2ClientId = oAuth2clientId,
            //     OAuth2ClientSecret = oAuth2Secret,
            //     OAuth2RefreshToken = oAuth2RefreshToken,
            // };

            //GoogleAdsClient googleAdsClient = new GoogleAdsClient(googleAdsConfig);

            // Run the code example.
            //new V1.GetCampaigns().Run(new GoogleAdsClient(), 1234567890);

            // Alternatively, you can pass command line arguments to run the code example. E.g.
            // V1.GetCampaigns --customerId=1234567890
            // The first argument has the form VersionName.ExampleName, e.g. V1.GetCampaigns to run
            // Google.Ads.GoogleAds.Examples.V1.GetCampaigns example.
            // The subsequent arguments can be inferred by looking at the Run method of the code
            // example and skipping the first parameter.
            // E.g. GetCampaigns.cs has a Run method is defined as
            //
            //     public void Run(GoogleAdsClient client, long customerId)
            //
            // So, this example can be run with the command line arguments
            //
            //     V1.GetCampaigns --customerId=1234567890
            RunExamplesFromCommandLineArguments(args);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies that the text logged by <paramref name="loggingAction"/> contains
        /// <paramref name="markerToVerify"/> text.
        /// </summary>
        /// <param name="logSource">The log source.</param>
        /// <param name="loggingAction">The logging action.</param>
        /// <param name="markerToVerify">The marker to verify.</param>
        private void VerifyLog(string logSource, Action loggingAction, string markerToVerify)
        {
            using (var stream = new MemoryStream())
            {
                TraceUtilities.Configure(logSource, new StreamWriter(stream), SourceLevels.All);

                loggingAction();
                // Ensure failure summaries are logged at the warning level.
                TraceUtilities.WriteSummaryRequestLogs(TEST_LOG_MESSAGE, true);

                string logFromMemStream = Encoding.UTF8.GetString(stream.ToArray());
                StringAssert.Contains(markerToVerify, logFromMemStream);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoggingInterceptorTests"/> class.
        /// </summary>
        public LoggingInterceptorTests() : base(new GoogleAdsConfig())
        {
            // Initialize request metadata.
            TEST_REQUEST_METADATA = new Metadata();
            TEST_REQUEST_METADATA.Add(GoogleAdsConfig.DEVELOPER_TOKEN_KEYNAME,
                                      TEST_DEVELOPER_TOKEN);

            // Initialize response metadata.
            TEST_RESPONSE_METADATA = new Metadata();
            TEST_RESPONSE_METADATA.Add(GoogleAdsException.REQUEST_ID_KEY, TEST_REQUEST_ID);

            // Create the test exception.
            TEST_EXCEPTION = TestUtils.CreateRpcException(TEST_ERROR_MESSAGE, TEST_ERROR_TRIGGER,
                                                          TEST_REQUEST_ID);
            TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
                                     new StringWriter(), SourceLevels.All);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoggingHandlerTests"/> class.
        /// </summary>
        public LoggingHandlerTests()
        {
            // Initialize request metadata.
            TEST_REQUEST_METADATA = new Metadata();
            TEST_REQUEST_METADATA.Add(MetadataKeyNames.DeveloperToken, TEST_DEVELOPER_TOKEN);

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

            // Initialize trailers metadata.
            TEST_TRAILERS_METADATA = new Metadata();

            // Create the test exception.
            TEST_EXCEPTION = TestUtils.CreateRpcException(TEST_ERROR_MESSAGE, TEST_ERROR_TRIGGER,
                                                          TEST_REQUEST_ID);
            TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
                                     new StringWriter(), SourceLevels.All);
        }
Exemplo n.º 5
0
 public void RunBeforeAnyTests()
 {
     // Turn on logging.
     TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
                              "C:\\logs\\details.log", System.Diagnostics.SourceLevels.All);
 }