示例#1
0
        public void TestDeleteEntityAndMapping()
        {
            var entity = creatEntity();

            //添加实体
            DEObjectOperations.InstanceWithoutPermissions.AddEntity(entity);
            //获取实体
            var entityLoad = DESchemaObjectAdapter.Instance.Load(entity.ID) as DynamicEntity;

            //外部实体
            var newOutEntity = createOuterEntity();

            List <EntityFieldMapping> entityFieldMappingCollection = new List <EntityFieldMapping>();

            List <string> outerFieldIDs = new List <string>();

            //新建外部属性
            entity.Fields.ForEach(f =>
            {
                var guid = Guid.NewGuid().ToString();
                EntityFieldMapping mapping = new EntityFieldMapping();
                mapping.BuildFromField(f);
                //mapping.OuterFieldID = guid;
                //mapping.OuterFieldName = "Name_" + f.Name;
                outerFieldIDs.Add(guid);
                entityFieldMappingCollection.Add(mapping);
            });

            //mapping对象
            EntityMapping entityMapping = new EntityMapping()
            {
                InnerEntity     = entityLoad,
                OuterEntityID   = newOutEntity.ID,
                OuterEntityName = newOutEntity.Name,
                EntityFieldMappingCollection = entityFieldMappingCollection
            };

            //mapping入库
            DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(entityMapping);

            //删除实体
            DEObjectOperations.InstanceWithoutPermissions.DeleteEntity(entity.ID);

            //实体
            var resultEntity = DESchemaObjectAdapter.Instance.Load(entity.ID, false) as DynamicEntity;

            //外部实体
            var resultOEntity = DESchemaObjectAdapter.Instance.Load(newOutEntity.ID, false) as OuterEntity;

            bool entitySuccess = resultEntity.Status == SchemaObjectStatus.Deleted;

            bool oEntitySuccess = resultOEntity.Status == SchemaObjectStatus.Deleted;

            Assert.IsTrue(entitySuccess && oEntitySuccess, "删除mapping失败");
        }
示例#2
0
        public void TestDeleteEntityMapping()
        {
            var entity = creatEntity();

            //添加实体
            DEObjectOperations.InstanceWithoutPermissions.AddEntity(entity);
            //获取实体
            var entityLoad = DESchemaObjectAdapter.Instance.Load(entity.ID) as DynamicEntity;

            //外部实体
            var newOutEntity = createOuterEntity();

            List <EntityFieldMapping> entityFieldMappingCollection = new List <EntityFieldMapping>();

            List <string> outerFieldIDs = new List <string>();

            //新建外部属性
            entity.Fields.ForEach(f =>
            {
                var guid = Guid.NewGuid().ToString();
                EntityFieldMapping mapping = new EntityFieldMapping();
                mapping.BuildFromField(f);
                //mapping.OuterFieldID = guid;
                //mapping.OuterFieldName = "Name_" + f.Name;
                outerFieldIDs.Add(guid);
                entityFieldMappingCollection.Add(mapping);
            });

            //mapping对象
            EntityMapping entityMapping = new EntityMapping()
            {
                InnerEntity     = entityLoad,
                OuterEntityID   = newOutEntity.ID,
                OuterEntityName = newOutEntity.Name,
                EntityFieldMappingCollection = entityFieldMappingCollection
            };

            //mapping入库
            DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(entityMapping);
            //实体
            var resultEntity = DESchemaObjectAdapter.Instance.Load(entity.ID) as DynamicEntity;
            //外部实体
            var resultOEntity = DESchemaObjectAdapter.Instance.Load(newOutEntity.ID) as OuterEntity;

            //删除mapping
            DEObjectOperations.InstanceWithoutPermissions.DeleteEntityMapping(resultEntity, resultOEntity);



            //实体
            var resultEntityL = DESchemaObjectAdapter.Instance.Load(entity.ID, false) as DynamicEntity;

            //外部实体
            var resultOEntityL = DESchemaObjectAdapter.Instance.Load(newOutEntity.ID, false) as OuterEntity;

            //实体与外部结构的mapping是否删除
            bool entityMappingSuccess = true;// !(resultEntityL.OuterEntities.Any(e => e.ID == resultOEntity.ID));
            //外部实体是否删除
            bool outerEntitySuccess = resultOEntityL.Status == DataObjects.Schemas.SchemaProperties.SchemaObjectStatus.Deleted;
            //实体字段mapping是否删除
            bool fieldMapping = true;

            foreach (var f in resultEntityL.Fields)
            {
                fieldMapping = !f.AllMemberOfRelations.Any(r =>
                                                           outerFieldIDs.Contains(r.ID)
                                                           );
                if (!fieldMapping)
                {
                    break;
                }
            }

            bool outerFieldSuccess = true;

            foreach (var fID in outerFieldIDs)
            {
                var fObj = DESchemaObjectAdapter.Instance.Load(fID, false) as OuterEntityField;
                if (fObj != null)
                {
                    outerFieldSuccess = fObj.Status == SchemaObjectStatus.Deleted;
                }
                if (!outerFieldSuccess)
                {
                    break;
                }
            }

            Assert.IsTrue(entityMappingSuccess && outerEntitySuccess && fieldMapping && outerFieldSuccess, "mapping删除失败");
        }