X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.ServiceModel%2FTest%2FSystem.ServiceModel.Channels%2FFaultConverterTest.cs;h=7df58d9954f6aaa128e47d9036c0b04018076c80;hb=2d23bfcbce7a3f7e54dcd5911adb88b244baca35;hp=60587df22dcb44db3011677f36b815a517d6ba63;hpb=4323fbeaebf249f016dfdd6dc9b3b52a515f87c4;p=mono.git diff --git a/mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/FaultConverterTest.cs b/mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/FaultConverterTest.cs index 60587df22dc..7df58d9954f 100644 --- a/mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/FaultConverterTest.cs +++ b/mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/FaultConverterTest.cs @@ -38,7 +38,8 @@ namespace MonoTests.System.ServiceModel.Channels 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 () { @@ -48,7 +49,7 @@ namespace MonoTests.System.ServiceModel.Channels } [Test] - public void TryCreateExceptionDefault () + public void TryCreateFaultMessageDefault () { Message msg; Assert.IsFalse (s12.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#1-1"); @@ -57,11 +58,108 @@ namespace MonoTests.System.ServiceModel.Channels Assert.IsFalse (s12.TryCreateFaultMessage (new FaultException ("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 ("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 ("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 = @" + + + http://www.w3.org/2005/08/addressing/fault + + + + a:ActionNotSupported + some error + + +"; + + [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"); } } }