Skip to content

Commit 4cc5198

Browse files
author
L0ndra
authored
Merge pull request #28 from L0ndra/master
move branch to source repo
2 parents e2ae24c + db2ef56 commit 4cc5198

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/SolidifyProject.Engine.Infrastructure/Models/CustomDataModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.Dynamic;
44
using System.IO;
5+
using System.Xml.Linq;
56
using CsvHelper;
7+
using Newtonsoft.Json;
68
using Newtonsoft.Json.Linq;
79
using SolidifyProject.Engine.Infrastructure.Enums;
810
using SolidifyProject.Engine.Infrastructure.Models.Base;
@@ -100,7 +102,10 @@ private void ParseJson()
100102

101103
private void ParseXml()
102104
{
103-
throw new NotImplementedException();
105+
//hack to convert xml document to dynamic object
106+
XDocument doc = XDocument.Parse(ContentRaw);
107+
string jsonText = JsonConvert.SerializeXNode(doc);
108+
CustomData = JObject.Parse(jsonText);
104109
}
105110

106111
private void ParseYaml()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NUnit.Framework;
2+
using SolidifyProject.Engine.Infrastructure.Enums;
3+
4+
namespace SolidifyProject.Engine.Test.Unit.Infrastructure.Models.CustomDataModel.Parse
5+
{
6+
[TestFixture]
7+
public class XmlCustomDataModelTest
8+
{
9+
private string _xml = @"<root>
10+
<links>
11+
<name>facebook</name>
12+
<url>https://facebook.com</url>
13+
</links>
14+
<links>
15+
<name>twitter</name>
16+
<url>https://twitter.com</url>
17+
</links>
18+
</root>";
19+
20+
[Test]
21+
public void ParseXml()
22+
{
23+
var model = new Engine.Infrastructure.Models.CustomDataModel();
24+
model.Id = "file.xml";
25+
model.ContentRaw = _xml;
26+
27+
model.Parse();
28+
29+
Assert.NotNull(model.DataType);
30+
Assert.AreEqual(CustomDataType.Xml.ToString(), model.DataType.ToString());
31+
32+
var data = (dynamic)model.CustomData;
33+
Assert.IsNotNull(data);
34+
Assert.AreEqual(2, data.root.links.Count);
35+
36+
Assert.AreEqual("facebook", (string)data.root.links[0].name);
37+
Assert.AreEqual("https://facebook.com", (string)data.root.links[0].url);
38+
39+
Assert.AreEqual("twitter", (string)data.root.links[1].name);
40+
Assert.AreEqual("https://twitter.com", (string)data.root.links[1].url);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)