Ejemplo n.º 1
0
        public void ParseCollectionOfStructures(string fileName)
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = fileName;
            model.ContentRaw = @"
                -
                  name:     John
                  phones:
                    - iPhone
                                   
                -
                  name:     Bob
                  phones:
                    - Samsung
            ";

            model.Parse();

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

            var data = (dynamic)model.CustomData;

            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Count);

            Assert.AreEqual("John", data[0].name);
            Assert.AreEqual(1, data[0].phones.Count);
            Assert.AreEqual("iPhone", data[0].phones[0]);

            Assert.AreEqual("Bob", data[1].name);
            Assert.AreEqual(1, data[1].phones.Count);
            Assert.AreEqual("Samsung", data[1].phones[0]);
        }
Ejemplo n.º 2
0
        public void ParseCsv()
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = "file.csv";
            model.ContentRaw =
                @"fName,    lName,    age
                  John,     Doe,      16
                  Mr,       Smith,    42";

            model.Parse();

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

            var data = (List <dynamic>)model.CustomData;

            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Count);


            var item = data[0];

            Assert.AreEqual("John", item.fName);
            Assert.AreEqual("Doe", item.lName);
            Assert.AreEqual("16", item.age);

            item = data[1];
            Assert.AreEqual("Mr", item.fName);
            Assert.AreEqual("Smith", item.lName);
            Assert.AreEqual("42", item.age);
        }
Ejemplo n.º 3
0
        public void ParseText(string raw, string expected)
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = "file.txt";
            model.ContentRaw = raw;

            model.Parse();

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

            var data = (string)model.CustomData;

            Assert.IsNotNull(data);
            Assert.AreEqual(expected, data);
        }
Ejemplo n.º 4
0
        public void ParseCollectionOfScalars(string fileName)
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = fileName;
            model.ContentRaw = @"
                - aaa
                - bbb
            ";

            model.Parse();

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

            var data = (dynamic)model.CustomData;

            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Count);
            Assert.AreEqual("aaa", data[0]);
            Assert.AreEqual("bbb", data[1]);
        }
Ejemplo n.º 5
0
        public void ParseScalar(string fileName)
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = fileName;
            model.ContentRaw = @"
                this
                is
                just
                text
            ";

            model.Parse();

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

            var data = (string)model.CustomData;

            Assert.IsNotNull(data);
            Assert.AreEqual("this is just text", data);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public void ParseStructure(string fileName)
        {
            var model = new Engine.Infrastructure.Models.CustomDataModel();

            model.Id         = fileName;
            model.ContentRaw = @" 
                name:    John
                phones:  
                  - iPhone
            ";

            model.Parse();

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

            var data = (dynamic)model.CustomData;

            Assert.IsNotNull(data);

            Assert.AreEqual("John", data.name);
            Assert.AreEqual(1, data.phones.Count);
            Assert.AreEqual("iPhone", data.phones[0]);
        }