예제 #1
0
        public void TestAdWordsApiExceptionForFault()
        {
            SoapFaultInspector <AdWordsApiException> inspector =
                new SoapFaultInspector <AdWordsApiException>()
            {
                ErrorType = typeof(ApiException)
            };

            foreach (string faultXml in faultXmls)
            {
                XmlDocument xDoc    = XmlUtilities.CreateDocument(faultXml);
                Message     message = Message.CreateMessage(new XmlNodeReader(xDoc), Int32.MaxValue,
                                                            TestMessageVersion);

                AdWordsApiException exception = Assert.Throws <AdWordsApiException>(
                    delegate() { inspector.AfterReceiveReply(ref message, this.channel); },
                    "No exception was thrown for a SOAP Fault response");
                Assert.AreEqual(typeof(ApiException), exception.ApiException.GetType());
                ApiException apiException = (ApiException)exception.ApiException;
                Assert.AreEqual(1, apiException.errors.Length);
                Assert.AreEqual(typeof(AuthenticationError), apiException.errors[0].GetType());
                AuthenticationError error = (AuthenticationError)apiException.errors[0];
                Assert.AreEqual(AuthenticationErrorReason.CUSTOMER_NOT_FOUND, error.reason);
            }
        }
 /// <summary>
 /// Gets the batch job error.
 /// </summary>
 /// <param name="e">The AdWords API Exception.</param>
 /// <returns>The underlying batch job error if available, null otherwise.</returns>
 private BatchJobError GetBatchJobError(AdWordsApiException e)
 {
     return((e.ApiException as ApiException).GetAllErrorsByType <BatchJobError>().
            FirstOrDefault());
 }