public class FaultConverterTest
{
static readonly FaultConverter s11 = FaultConverter.GetDefaultFaultConverter (MessageVersion.Soap11WSAddressing10);
- static readonly FaultConverter s12 = FaultConverter.GetDefaultFaultConverter (MessageVersion.Default);
+ static readonly FaultConverter s12 = FaultConverter.GetDefaultFaultConverter (MessageVersion.Soap12WSAddressing10);
+ static readonly FaultConverter none = FaultConverter.GetDefaultFaultConverter (MessageVersion.None);
XmlWriterSettings GetWriterSettings ()
{
}
[Test]
- public void TryCreateExceptionDefault ()
+ public void TryCreateFaultMessageDefault ()
{
Message msg;
Assert.IsFalse (s12.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#1-1");
Assert.IsFalse (s12.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#1-3");
+ Assert.IsTrue (s12.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#1-4");
+ Assert.IsTrue (msg.IsFault, "#1-5");
+ Assert.AreEqual ("http://www.w3.org/2005/08/addressing/fault", msg.Headers.Action, "#1-6");
+ var f = MessageFault.CreateFault (msg, 1000);
+ Assert.AreEqual ("Sender", f.Code.Name, "#1-7");
+ Assert.AreEqual ("http://www.w3.org/2003/05/soap-envelope", f.Code.Namespace, "#1-8");
+ Assert.AreEqual ("ActionNotSupported", f.Code.SubCode.Name, "#1-9");
+ Assert.AreEqual ("http://www.w3.org/2005/08/addressing", f.Code.SubCode.Namespace, "#1-10");
+
Assert.IsFalse (s11.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#2-1");
Assert.IsFalse (s11.TryCreateFaultMessage (new FaultException ("fault happened", FaultCode.CreateSenderFaultCode (new FaultCode ("IAmBroken"))), out msg), "#2-2");
Assert.IsFalse (s11.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#2-3");
+
+ Assert.IsTrue (s11.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#2-4");
+ Assert.IsTrue (msg.IsFault, "#2-5");
+ Assert.AreEqual ("http://www.w3.org/2005/08/addressing/fault", msg.Headers.Action, "#2-6");
+ f = MessageFault.CreateFault (msg, 1000);
+ Assert.AreEqual ("ActionNotSupported", f.Code.Name, "#2-7");
+ Assert.AreEqual ("http://www.w3.org/2005/08/addressing", f.Code.Namespace, "#2-8");
+
+ Assert.IsFalse (none.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#3-1");
+
+ Assert.IsFalse (none.TryCreateFaultMessage (new FaultException ("fault happened", FaultCode.CreateSenderFaultCode (new FaultCode ("IAmBroken"))), out msg), "#3-2");
+
+ Assert.IsFalse (none.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#3-3");
+
+ Assert.IsFalse (none.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#3-4");
+
+ Assert.IsFalse (none.TryCreateFaultMessage (new EndpointNotFoundException (), out msg), "#3-5");
+ }
+
+ string xml1 = @"
+<s:Envelope xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
+ <s:Header>
+ <a:Action s:mustUnderstand='1'>http://www.w3.org/2005/08/addressing/fault</a:Action>
+ </s:Header>
+ <s:Body>
+ <s:Fault>
+ <faultcode>a:ActionNotSupported</faultcode>
+ <faultstring xml:lang='en-US'>some error</faultstring>
+ </s:Fault>
+ </s:Body>
+</s:Envelope>";
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void TryCreateExceptionMessageNullDefault ()
+ {
+ var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
+ var mf = MessageFault.CreateFault (msg, 1000);
+ Exception ex;
+ s11.TryCreateException (null, mf, out ex);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void TryCreateExceptionFaultNullDefault ()
+ {
+ var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
+ Exception ex;
+ s11.TryCreateException (msg, null, out ex);
+ }
+
+ [Test]
+ public void TryCreateExceptionDefault ()
+ {
+ var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
+ var mf = MessageFault.CreateFault (msg, 1000);
+ msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
+ Exception ex;
+ Assert.IsTrue (s11.TryCreateException (msg, mf, out ex), "#1");
+ // foobar -> false
+ Assert.IsFalse (s11.TryCreateException (msg, MessageFault.CreateFault (new FaultCode ("foobar"), new FaultReason ("foobar reason")), out ex), "#2");
+ // SOAP 1.1 ActionNotSupported -> true
+ Assert.IsTrue (s11.TryCreateException (msg, MessageFault.CreateFault (new FaultCode ("ActionNotSupported", Constants.WsaNamespace), new FaultReason ("foobar reason")), out ex), "#3");
+ Assert.IsTrue (ex is ActionNotSupportedException, "#3-2");
+ Assert.IsTrue (ex.Message.IndexOf ("foobar") >= 0, "#3-3");
+
+ // SOAP 1.1 Sender/ActionNotSupported -> false
+ mf = MessageFault.CreateFault (new FaultCode ("Sender", new FaultCode ("ActionNotSupported", Constants.WsaNamespace)), new FaultReason ("foobar reason"));
+ Assert.IsFalse (s11.TryCreateException (msg, mf, out ex), "#4");
+ // SOAP 1.2 ActionNotSupported -> false
+ mf = MessageFault.CreateFault (new FaultCode ("ActionNotSupported", Constants.WsaNamespace), new FaultReason ("foobar reason"));
+ Assert.IsFalse (s12.TryCreateException (msg, mf, out ex), "#5");
+ // SOAP 1.2 Sender/ActionNotSupported -> true
+ mf = MessageFault.CreateFault (new FaultCode ("Sender", new FaultCode ("ActionNotSupported", Constants.WsaNamespace)), new FaultReason ("foobar reason"));
+ Assert.IsTrue (s12.TryCreateException (msg, mf, out ex), "#6");
+ Assert.IsTrue (ex is ActionNotSupportedException, "#6-2");
+ Assert.IsTrue (ex.Message.IndexOf ("foobar") >= 0, "#6-3");
+ }
+
+ [Test]
+ public void TryCreateException2Default ()
+ {
+ // test buffered copy (which used to fail)
+ var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
+ var mb = msg.CreateBufferedCopy (1000);
+ var mf = MessageFault.CreateFault (mb.CreateMessage (), 1000);
+ Exception ex;
+ Assert.IsTrue (s11.TryCreateException (mb.CreateMessage (), mf, out ex), "#7");
}
}
}