mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -10:00
It's an optional element according to [1] and we were simply throwing a NotImplementedException when encountering it. Fixed by reading the element value instead. I noticed that we had a 'details' variable that was never assigned, so the check for `details == null` was always true and can be removed. This makes inlining the body of the CreateFault() call easier since we no longer need to choose different overloads and makes the code consistent with the CreateFault12 method. Also added a better exception in case of an unrecognized element. The CreateFault12 method (handles SOAP 1.2) does not need a similar fix since actor is not an element in that version [2]. Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=42226 [1] https://www.w3.org/TR/soap11/#_Toc478383507 [2] https://www.w3.org/TR/soap12/#soapfault
86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using System.ServiceModel;
|
|
using System.ServiceModel.Channels;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using NUnit.Framework;
|
|
|
|
namespace MonoTests.System.ServiceModel.Channels
|
|
{
|
|
[TestFixture]
|
|
public class MessageFaultTest
|
|
{
|
|
[Test]
|
|
public void CreateFault ()
|
|
{
|
|
var msg = Message.CreateMessage (XmlReader.Create (new StreamReader ("Test/System.ServiceModel.Channels/soap-fault.xml")), 0x10000, MessageVersion.Default);
|
|
MessageFault.CreateFault (msg, 0x10000);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateFaultMessageVersionNone ()
|
|
{
|
|
var msg = Message.CreateMessage (MessageVersion.None, new FaultCode ("DestinationUnreachable"), "typical error", null);
|
|
var fault = MessageFault.CreateFault (msg, 0x10000);
|
|
Assert.AreEqual ("DestinationUnreachable", fault.Code.Name, "#1");
|
|
Assert.AreEqual ("typical error", fault.Reason.ToString (), "#2");
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (CommunicationException))]
|
|
public void CreateFaultIncomplete ()
|
|
{
|
|
var msg = Message.CreateMessage (XmlReader.Create (new StreamReader ("Test/System.ServiceModel.Channels/soap-fault-incomplete.xml")), 0x10000, MessageVersion.Default);
|
|
MessageFault.CreateFault (msg, 0x10000);
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
public void CreateFaultIncomplete2 ()
|
|
{
|
|
MessageFault.CreateFault (new FaultCode ("s:Sender"), (FaultReason) null);
|
|
}
|
|
|
|
[Test]
|
|
// [ExpectedException (typeof (CommunicationException))]
|
|
public void CreateFaultIncomplete3 ()
|
|
{
|
|
MessageFault.CreateFault (new FaultCode ("s:Sender"), new FaultReason ("anyways"));
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (CommunicationException))]
|
|
public void CreateFaultIncomplete4 ()
|
|
{
|
|
var msg = Message.CreateMessage (XmlReader.Create (new StreamReader ("Test/System.ServiceModel.Channels/soap-fault-incomplete4.xml")), 0x10000, MessageVersion.Default);
|
|
MessageFault.CreateFault (msg, 0x10000);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateFaultFromMessage ()
|
|
{
|
|
var xml = @"
|
|
<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>
|
|
<faultactor>Random</faultactor>
|
|
</s:Fault>
|
|
</s:Body>
|
|
</s:Envelope>";
|
|
var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml)), 0x1000, MessageVersion.Soap11WSAddressing10);
|
|
MessageFault.CreateFault (msg, 1000);
|
|
msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml)), 0x1000, MessageVersion.Soap11WSAddressing10);
|
|
var mb = msg.CreateBufferedCopy (1000);
|
|
MessageFault.CreateFault (mb.CreateMessage (), 1000);
|
|
}
|
|
}
|
|
}
|