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); } }
public void TestAdManagerApiExceptionForFault() { SoapFaultInspector <AdManagerApiException> inspector = new SoapFaultInspector <AdManagerApiException>() { ErrorType = typeof(AdManager.v202202.ApiException) }; XmlDocument xDoc = XmlUtilities.CreateDocument(fault_xml); Message message = Message.CreateMessage(new XmlNodeReader(xDoc), Int32.MaxValue, TestMessageVersion); AdManagerApiException exception = Assert.Throws <AdManagerApiException>( 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(PublisherQueryLanguageContextError), apiException.errors[0].GetType()); PublisherQueryLanguageContextError error = (PublisherQueryLanguageContextError)apiException.errors[0]; Assert.AreEqual(PublisherQueryLanguageContextErrorReason.UNEXECUTABLE, error.reason); Assert.AreEqual("Mapping requested for unknown identifer", error.fieldPath); }
public void TestNoExceptionForNoFault() { SoapFaultInspector <AdWordsApiException> inspector = new SoapFaultInspector <AdWordsApiException>() { ErrorType = typeof(ApiException) }; Message message = Message.CreateMessage(TestMessageVersion, null); Assert.DoesNotThrow( delegate() { inspector.AfterReceiveReply(ref message, this.channel); }, "Exception was thrown for a response that wasn't a fault."); }