Ejemplo n.º 1
0
        public void InstanceDeserializeWithData()
        {
            DEEntityInstanceBase sourceInstance = MockData.CreateEntityInstance();

            string json = JSONSerializerExecute.Serialize(sourceInstance);

            DEEntityInstanceBase deserializedInstance = JSONSerializerExecute.Deserialize <DEEntityInstanceBase>(json);

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

                Assert.IsNotNull(deserializedField);

                if (sourceField.Definition.FieldType == FieldTypeEnum.Collection)
                {
                    DEEntityInstanceBaseCollection sourceChildren       = sourceField.GetRealValue() as DEEntityInstanceBaseCollection;
                    DEEntityInstanceBaseCollection deserializedChildren = deserializedField.GetRealValue() as DEEntityInstanceBaseCollection;

                    foreach (var sourceChild in sourceChildren)
                    {
                        var deserializedChild = deserializedChildren[sourceChild.ID];

                        Assert.IsNotNull(deserializedChild);
                    }
                }
                else
                {
                    Assert.AreEqual(sourceField.StringValue, deserializedField.StringValue);
                }
            }
        }
Ejemplo n.º 2
0
        public void InstanceSerializeWithDataTest()
        {
            bool flag = true;

            DEEntityInstanceBase instance = MockData.CreateEntityInstance();

            string json = JSONSerializerExecute.Serialize(instance);

            Console.WriteLine(json);

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

            Assert.IsTrue(flag, "序列化实体实例出错");
        }