diff --git a/src/MockHttp/Extensions/ResponseBuilderLinqToXmlExtensions.cs b/src/MockHttp/Extensions/ResponseBuilderLinqToXmlExtensions.cs index 9d596686..918bc3cf 100644 --- a/src/MockHttp/Extensions/ResponseBuilderLinqToXmlExtensions.cs +++ b/src/MockHttp/Extensions/ResponseBuilderLinqToXmlExtensions.cs @@ -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; diff --git a/test/MockHttp.Tests/Language/Flow/Response/LinqToXmlBodyDoesNotModifySettings.cs b/test/MockHttp.Tests/Language/Flow/Response/LinqToXmlBodyDoesNotModifySettings.cs new file mode 100644 index 00000000..33c06470 --- /dev/null +++ b/test/MockHttp.Tests/Language/Flow/Response/LinqToXmlBodyDoesNotModifySettings.cs @@ -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(""), OriginalSettings); + } + + protected override Task Should(HttpResponseMessage response) + { + OriginalSettings.Async.Should().BeFalse(); + OriginalSettings.CloseOutput.Should().BeTrue(); + return Task.CompletedTask; + } +}