Example #1
0
        public void InstanceDeserialize()
        {
            DynamicEntity entity = MockData.CreateEntityAndChildEntity();

            DEEntityInstanceBase sourceInstance = entity.CreateInstance();

            //序列化之后的数据
            string json = JSONSerializerExecute.Serialize(sourceInstance);

            //反序列化
            DEEntityInstanceBase deserializedInstance = JSONSerializerExecute.Deserialize <DEEntityInstanceBase>(json);

            foreach (var sourceField in sourceInstance.Fields)
            {
                EntityFieldValue deserializedFieldValue = deserializedInstance.Fields.Where(p => p.Definition.Name == sourceField.Definition.Name).FirstOrDefault();

                Assert.IsNotNull(deserializedFieldValue);

                if (sourceField.Definition.FieldType == FieldTypeEnum.Collection)
                {
                    Assert.AreEqual(sourceField.Definition.ReferenceEntityCodeName, deserializedFieldValue.Definition.ReferenceEntityCodeName);
                }
                else
                {
                    Assert.AreEqual(sourceField.StringValue, deserializedFieldValue.StringValue);
                }
            }
        }
Example #2
0
        public void EntityAndChildSerializeTest()
        {
            DynamicEntity entity = MockData.CreateEntityAndChildEntity();
            string        json   = JSONSerializerExecute.Serialize(entity);

            var fields = entity.Fields.Where(p => p.FieldType == FieldTypeEnum.Collection);

            fields.ForEach(f =>
            {
                Assert.IsTrue(json.Contains(f.CodeName), string.Format("不能再序列化的JSON中找到属性名{0}", f.CodeName));
            });

            Assert.IsTrue(json.Contains(entity.CodeName), string.Format("不能再序列化的JSON中找到属性名{0}", entity.CodeName));
        }
Example #3
0
        public void EntityAndChildDeSerializeTest()
        {
            DynamicEntity entity = MockData.CreateEntityAndChildEntity();

            string        json            = JSONSerializerExecute.Serialize(entity);
            DynamicEntity deDynamicEntity = JSONSerializerExecute.Deserialize <DynamicEntity>(json);

            Assert.AreEqual(entity.CodeName, deDynamicEntity.CodeName);
            Assert.AreEqual(entity.Fields.Count, deDynamicEntity.Fields.Count);

            IEnumerable <DynamicEntityField> sourceFields = entity.Fields.Where(p => p.FieldType == FieldTypeEnum.Collection);

            sourceFields.ForEach(sf =>
            {
                DynamicEntityField def = deDynamicEntity.Fields[sf.ID];

                Assert.AreEqual(FieldTypeEnum.Collection, def.FieldType);
                Assert.AreEqual(sf.CodeName, def.CodeName);
            });
        }
Example #4
0
        public void InstanceSerializeTest()
        {
            DynamicEntity entity = MockData.CreateEntityAndChildEntity();

            DEEntityInstanceBase instance = entity.CreateInstance();

            string json = JSONSerializerExecute.Serialize(instance);

            instance.Fields.ForEach(f =>
            {
                if (f.Definition.FieldType == FieldTypeEnum.Collection)
                {
                    foreach (var item in f.Definition.ReferenceEntity.Fields)
                    {
                        Assert.IsTrue(json.Contains(item.Name));
                    }
                }
                else
                {
                    Assert.IsTrue(json.Contains(f.Definition.Name));
                }
            });
        }