Skip to content
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
2 changes: 1 addition & 1 deletion src/Fallout.Common/IO/XmlTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IEnumerable<XElement> XmlPeekElements(string path, string xpath, p

public static IEnumerable<XElement> 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)
Expand Down
41 changes: 41 additions & 0 deletions tests/Fallout.Common.Specs/XmlTasksSpecs.cs
Original file line number Diff line number Diff line change
@@ -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 = @"<root><element>value</element></root>";
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<XmlException>();
}

[Fact]
public void Loading_from_url_throws()
{
var content = "https://example.com/test.xml";

Action action = () => XmlTasks.XmlPeekElementsFromString(content, "/root/element");

action.Should().Throw<XmlException>();
}
}
Loading