Skip to content

Commit

Permalink
fix(xml): do not modify XmlSettings supplied to XmlBody.
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Nov 19, 2023
1 parent bdf52d3 commit 1098129
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IWithContentResult XmlBody(this IWithContent builder, XContainer x
throw new ArgumentNullException(nameof(xmlContent));
}

settings ??= new XmlWriterSettings();
settings = settings?.Clone() ?? new XmlWriterSettings();
// Ensure the stream is not closed/disposed on disposal of the XML writer.
// It will be disposed by HttpClient instead.
settings.CloseOutput = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Xml;
using System.Xml.Linq;
using MockHttp.Specs;

namespace MockHttp.Language.Flow.Response;

public sealed class LinqToXmlBodyDoesNotModifySettings : ResponseSpec
{
private static readonly XmlWriterSettings OriginalSettings = new() { CloseOutput = true, Async = false };

protected override void Given(IResponseBuilder with)
{
with.XmlBody(XDocument.Parse("<xml/>"), OriginalSettings);
}

protected override Task Should(HttpResponseMessage response)
{
OriginalSettings.Async.Should().BeFalse();
OriginalSettings.CloseOutput.Should().BeTrue();
return Task.CompletedTask;
}
}

0 comments on commit 1098129

Please sign in to comment.