diff --git a/src/Fallout.Common/IO/XmlTasks.cs b/src/Fallout.Common/IO/XmlTasks.cs index 684b0eddb..5305c060f 100644 --- a/src/Fallout.Common/IO/XmlTasks.cs +++ b/src/Fallout.Common/IO/XmlTasks.cs @@ -28,7 +28,7 @@ public static IEnumerable XmlPeekElements(string path, string xpath, p public static IEnumerable XmlPeekElementsFromString(string content, string xpath, params (string prefix, string uri)[] namespaces) { - return XmlPeekElements(XDocument.Load(content), xpath, namespaces); + return XmlPeekElements(XDocument.Parse(content), xpath, namespaces); } public static string XmlPeekSingle(string path, string xpath, params (string prefix, string uri)[] namespaces) diff --git a/tests/Fallout.Common.Specs/XmlTasksSpecs.cs b/tests/Fallout.Common.Specs/XmlTasksSpecs.cs new file mode 100644 index 000000000..94b9f819c --- /dev/null +++ b/tests/Fallout.Common.Specs/XmlTasksSpecs.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; +using System.Xml; +using Fallout.Common.IO; +using FluentAssertions; +using Xunit; + +namespace Fallout.Common.Specs; + +public class XmlTasksSpecs +{ + [Fact] + public void Loading_from_xml_string_works() + { + var content = @"value"; + var elements = XmlTasks.XmlPeekElementsFromString(content, "/root/element").ToList(); + + elements.Should().HaveCount(1); + elements.Single().Value.Should().Be("value"); + } + + [Fact] + public void Loading_from_file_path_throws() + { + var content = "C:\\temp\\test.xml"; + + Action action = () => XmlTasks.XmlPeekElementsFromString(content, "/root/element"); + + action.Should().Throw(); + } + + [Fact] + public void Loading_from_url_throws() + { + var content = "https://example.com/test.xml"; + + Action action = () => XmlTasks.XmlPeekElementsFromString(content, "/root/element"); + + action.Should().Throw(); + } +}