File tree Expand file tree Collapse file tree
SolidifyProject.Engine.Infrastructure/Models
SolidifyProject.Engine.Test.Unit/Infrastructure/Models/CustomDataModel/Parse Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Dynamic ;
44using System . IO ;
5+ using System . Xml . Linq ;
56using CsvHelper ;
7+ using Newtonsoft . Json ;
68using Newtonsoft . Json . Linq ;
79using SolidifyProject . Engine . Infrastructure . Enums ;
810using 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 ( )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments