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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Xml.Linq;
using CsvHelper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SolidifyProject.Engine.Infrastructure.Enums;
using SolidifyProject.Engine.Infrastructure.Models.Base;
Expand Down Expand Up @@ -100,7 +102,10 @@ private void ParseJson()

private void ParseXml()
{
throw new NotImplementedException();
//hack to convert xml document to dynamic object
XDocument doc = XDocument.Parse(ContentRaw);
string jsonText = JsonConvert.SerializeXNode(doc);
CustomData = JObject.Parse(jsonText);
}

private void ParseYaml()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using SolidifyProject.Engine.Infrastructure.Enums;

namespace SolidifyProject.Engine.Test.Unit.Infrastructure.Models.CustomDataModel.Parse
{
[TestFixture]
public class XmlCustomDataModelTest
{
private string _xml = @"<root>
<links>
<name>facebook</name>
<url>https://facebook.com</url>
</links>
<links>
<name>twitter</name>
<url>https://twitter.com</url>
</links>
</root>";

[Test]
public void ParseXml()
{
var model = new Engine.Infrastructure.Models.CustomDataModel();
model.Id = "file.xml";
model.ContentRaw = _xml;

model.Parse();

Assert.NotNull(model.DataType);
Assert.AreEqual(CustomDataType.Xml.ToString(), model.DataType.ToString());

var data = (dynamic)model.CustomData;
Assert.IsNotNull(data);
Assert.AreEqual(2, data.root.links.Count);

Assert.AreEqual("facebook", (string)data.root.links[0].name);
Assert.AreEqual("https://facebook.com", (string)data.root.links[0].url);

Assert.AreEqual("twitter", (string)data.root.links[1].name);
Assert.AreEqual("https://twitter.com", (string)data.root.links[1].url);
}
}
}