Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CreateMessage method overloads with FaultCode parameter #5169

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}