Skip to content

Commit

Permalink
Expose CreateMessage method overloads with FaultCode parameter (#5169)
Browse files Browse the repository at this point in the history
  • Loading branch information
imcarolwang authored May 30, 2023
1 parent 7a261fa commit 3998aa6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,8 @@ public void Close() { }
public static System.ServiceModel.Channels.Message CreateMessage(System.ServiceModel.Channels.MessageVersion version, string action, System.Xml.XmlReader body) { return default; }
public static System.ServiceModel.Channels.Message CreateMessage(System.Xml.XmlDictionaryReader envelopeReader, int maxSizeOfHeaders, System.ServiceModel.Channels.MessageVersion version) { return default; }
public static System.ServiceModel.Channels.Message CreateMessage(System.Xml.XmlReader envelopeReader, int maxSizeOfHeaders, System.ServiceModel.Channels.MessageVersion version) { return default; }
public static System.ServiceModel.Channels.Message CreateMessage(System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.FaultCode faultCode, string reason, string action) { return default; }
public static System.ServiceModel.Channels.Message CreateMessage(System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.FaultCode faultCode, string reason, object detail, string action) { return default; }
public T GetBody<T>() { return default; }
public T GetBody<T>(System.Runtime.Serialization.XmlObjectSerializer serializer) { return default; }
public string GetBodyAttribute(string localName, string ns) { return default; }
Expand Down
32 changes: 32 additions & 0 deletions src/System.ServiceModel.Primitives/tests/Channels/MessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,36 @@ public static void GetMessageVersion()
string actual = version.ToString();
Assert.Equal(expected, actual);
}

[WcfFact]
public static void CreateMessageWithFaultCode()
{
FaultCode faultCode = new FaultCode("fName");
string faultReason = "fault reason";
object faultDetail = new FaultDetail("fault details");

//create message without fault detail
var message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, faultCode, faultReason, s_action);
Assert.Equal(MessageVersion.Soap12WSAddressing10, message.Version);
Assert.Equal(s_action, message.Headers.Action);
Assert.False(message.IsEmpty);
Assert.True(message.IsFault);

var msgFault = MessageFault.CreateFault(message, int.MaxValue);
Assert.Equal(faultReason, msgFault.Reason.GetMatchingTranslation().Text);

//create message with fault detail
message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, faultCode, faultReason, faultDetail, s_action);
Assert.Equal(MessageVersion.Soap12WSAddressing10, message.Version);
Assert.Equal(s_action, message.Headers.Action);
Assert.False(message.IsEmpty);
Assert.True(message.IsFault);

msgFault = MessageFault.CreateFault(message, int.MaxValue);
Assert.Equal(faultReason, msgFault.Reason.GetMatchingTranslation().Text);
Assert.True(msgFault.HasDetail);
var msgFDetail = msgFault.GetDetail<FaultDetail>();
Assert.NotNull(msgFDetail);
Assert.Equal(((FaultDetail)faultDetail).Message, msgFDetail.Message);
}
}

0 comments on commit 3998aa6

Please sign in to comment.