Tests.ORecordParsingTests.TestWikiExample2Deserialization C# (CSharp) Method

TestWikiExample2Deserialization() private method

private TestWikiExample2Deserialization ( ) : void
return void
        public void TestWikiExample2Deserialization()
        {
            string raw = "name:\"ORole\",id:0,defaultClusterId:3,clusterIds:[3],properties:[(name:\"mode\",type:17,offset:0,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:,index:),(name:\"rules\",type:12,offset:1,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:17,index:)]";

            ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw));

            Assert.IsTrue(record.Fields["name"].GetType() == typeof(string));
            Assert.IsTrue((string)record.Fields["name"] == "ORole");

            Assert.IsTrue(record.Fields["id"].GetType() == typeof(int));
            Assert.IsTrue((int)record.Fields["id"] == 0);

            Assert.IsTrue(record.Fields["defaultClusterId"].GetType() == typeof(int));
            Assert.IsTrue((int)record.Fields["defaultClusterId"] == 3);

            Assert.IsTrue(record.Fields["properties"].GetType() == typeof(List<object>));
            List<object> properties = (List<object>)record.Fields["properties"];

            Dictionary<string, object> embedded = (Dictionary<string, object>)properties[0];

            Assert.IsTrue(embedded["name"].GetType() == typeof(string));
            Assert.IsTrue((string)embedded["name"] == "mode");

            Assert.IsTrue(embedded["type"].GetType() == typeof(int));
            Assert.IsTrue((int)embedded["type"] == 17);

            Assert.IsTrue(embedded["offset"].GetType() == typeof(int));
            Assert.IsTrue((int)embedded["offset"] == 0);

            Assert.IsTrue(embedded["mandatory"].GetType() == typeof(bool));
            Assert.IsTrue((bool)embedded["mandatory"] == false);

            Assert.IsTrue(embedded["notNull"].GetType() == typeof(bool));
            Assert.IsTrue((bool)embedded["notNull"] == false);

            Assert.IsTrue(embedded["min"] == null);

            Assert.IsTrue(embedded["max"] == null);

            Assert.IsTrue(embedded["linkedClass"] == null);

            Assert.IsTrue(embedded["linkedType"] == null);

            Assert.IsTrue(embedded["index"] == null);

            embedded = (Dictionary<string, object>)properties[1];

            Assert.IsTrue(embedded["name"].GetType() == typeof(string));
            Assert.IsTrue((string)embedded["name"] == "rules");

            Assert.IsTrue(embedded["type"].GetType() == typeof(int));
            Assert.IsTrue((int)embedded["type"] == 12);

            Assert.IsTrue(embedded["offset"].GetType() == typeof(int));
            Assert.IsTrue((int)embedded["offset"] == 1);

            Assert.IsTrue(embedded["mandatory"].GetType() == typeof(bool));
            Assert.IsTrue((bool)embedded["mandatory"] == false);

            Assert.IsTrue(embedded["notNull"].GetType() == typeof(bool));
            Assert.IsTrue((bool)embedded["notNull"] == false);

            Assert.IsTrue(embedded["min"] == null);

            Assert.IsTrue(embedded["max"] == null);

            Assert.IsTrue(embedded["linkedClass"] == null);

            Assert.IsTrue(embedded["linkedType"].GetType() == typeof(int));
            Assert.IsTrue((int)embedded["linkedType"] == 17);

            Assert.IsTrue(embedded["index"] == null);
        }