Exemplo n.º 1
0
        public void ImportTypedEntity_WhereAttributeGroupExistsWithOtherId()
        {
            // Arrange
            //Create entity with system General Group
            TypedEntity entity     = HiveModelCreationHelper.MockTypedEntity(true);
            var         definition = new NodeNameAttributeDefinition(FixedGroupDefinitions.GeneralGroup);

            entity.EntitySchema.AttributeDefinitions.Add(definition);

            //Create new entity with same group, but different Id
            TypedEntity entityToImport = HiveModelCreationHelper.MockTypedEntity(true);
            var         definition2    = new NodeNameAttributeDefinition(FixedGroupDefinitions.GeneralGroup);

            definition2.AttributeGroup.Id = new HiveId(Guid.NewGuid());
            entityToImport.EntitySchema.AttributeDefinitions.Add(definition2);

            //Serialize and deserialize
            IStreamedResult result      = SerializationService.ToStream(entityToImport);
            object          obj         = SerializationService.FromStream(result.ResultStream, typeof(TypedEntity));
            TypedEntity     typedEntity = obj as TypedEntity;

            // Act
            //Save entity with NodeNameAttributeDefinition to repository
            //Id for Group should be set 'automatically'
            using (var uow = Hive.OpenWriter <IContentStore>())
            {
                uow.Repositories.AddOrUpdate(entity);
                uow.Complete();
            }

            //Try to save/import deserialized entity
            using (var uow = Hive.OpenWriter <IContentStore>())
            {
                uow.Repositories.AddOrUpdate(typedEntity);
                uow.Complete();
            }

            // Assert
            Assert.That(entity.AttributeGroups.Any(x => x.Alias == "rebel-internal-general-properties"), Is.True);
            Assert.That(typedEntity.AttributeGroups.Any(x => x.Alias == "rebel-internal-general-properties"), Is.True);

            Assert.That(entity.AttributeGroups.Any(x => x.Id == HiveId.Empty), Is.False);
            Assert.That(typedEntity.AttributeGroups.Any(x => x.Id == HiveId.Empty), Is.False);
        }
Exemplo n.º 2
0
        protected TypedEntity CreateNewEntity()
        {
            var contentSchema = HiveModelCreationHelper.MockEntitySchema("test", "test");
            var nodeNameDef   = new NodeNameAttributeDefinition(FixedGroupDefinitions.GeneralGroup);

            contentSchema.AttributeDefinitions.Add(nodeNameDef);

            contentSchema.RelationProxies.EnlistParentById(FixedHiveIds.ContentRootSchema, FixedRelationTypes.DefaultRelationType, 0);

            var entity = HiveModelCreationHelper.CreateTypedEntity(contentSchema,
                                                                   new[]
            {
                new TypedAttribute(nodeNameDef),
            });

            entity.Id = new HiveId(Guid.NewGuid());

            return(entity);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create some properties for a TypedEntity
        /// </summary>
        /// <param name="assignIds"></param>
        /// <param name="callback"></param>
        private static void CreateMockTypedEntityProperties(
            bool assignIds,
            Action <EntitySchema, TypedAttribute[]> callback)
        {
            //create a tab

            var groupDefinition = CreateAttributeGroup("tab-1", "Tab 1", 0);

            if (assignIds)
            {
                groupDefinition.Id = new HiveId(Guid.NewGuid());
            }
            var generalGroup = FixedGroupDefinitions.GeneralGroup;

            //create some data types

            var typeDefinition = CreateAttributeType(TypeAlias1,
                                                     "test-type-name",
                                                     "test-type-description");

            if (assignIds)
            {
                typeDefinition.Id = new HiveId(Guid.NewGuid());
            }

            var typeDefinition2 = CreateAttributeType(TypeAlias2,
                                                      "test-type-name2",
                                                      "test-type-description2");

            if (assignIds)
            {
                typeDefinition2.Id = new HiveId(Guid.NewGuid());
            }

            //create some documenttype properties

            var attribDef1 = CreateAttributeDefinition(DefAlias1WithType1, "name-1", "test-description", typeDefinition, groupDefinition);

            if (assignIds)
            {
                attribDef1.Id = new HiveId(Guid.NewGuid());
            }

            var attribDef2 = CreateAttributeDefinition(DefAlias2WithType1, "name-2", "test-description", typeDefinition, groupDefinition);

            if (assignIds)
            {
                attribDef2.Id = new HiveId(Guid.NewGuid());
            }

            var attribDef3 = CreateAttributeDefinition("def-alias-3-with-type2", "name-3", "test-description", typeDefinition2, groupDefinition);

            if (assignIds)
            {
                attribDef3.Id = new HiveId(Guid.NewGuid());
            }

            var attribDef4 = CreateAttributeDefinition("def-alias-4-with-type2", "name-4", "test-description", typeDefinition2, groupDefinition);

            if (assignIds)
            {
                attribDef4.Id = new HiveId(Guid.NewGuid());
            }

            var nodeNameAttributeDefinition = new NodeNameAttributeDefinition(generalGroup);

            if (assignIds)
            {
                nodeNameAttributeDefinition.Id = new HiveId(Guid.NewGuid());
            }

            var selectedTemplateDefinition = new SelectedTemplateAttributeDefinition(generalGroup);

            if (assignIds)
            {
                selectedTemplateDefinition.Id = new HiveId(Guid.NewGuid());
            }

            //create the document type

            var schema = CreateEntitySchema("test-doctype-alias", "test-doctype-name",
                                            new[] { attribDef1, attribDef2, attribDef3, attribDef4, nodeNameAttributeDefinition, selectedTemplateDefinition });

            if (assignIds)
            {
                schema.Id = new HiveId(Guid.NewGuid());
            }

            //create some content properties

            var attribute1 = CreateAttribute(attribDef1, "my-test-value1");

            if (assignIds)
            {
                attribute1.Id = new HiveId(Guid.NewGuid());
            }

            var attribute2 = CreateAttribute(attribDef2, "my-test-value2");

            if (assignIds)
            {
                attribute2.Id = new HiveId(Guid.NewGuid());
            }

            var attribute3 = CreateAttribute(attribDef3, "my-test-value3");

            if (assignIds)
            {
                attribute3.Id = new HiveId(Guid.NewGuid());
            }

            var attribute4 = CreateAttribute(attribDef4, "5");

            if (assignIds)
            {
                attribute4.Id = new HiveId(Guid.NewGuid());
            }

            var nodeNameAttribute = new NodeNameAttribute("my-test-name", generalGroup)
            {
                AttributeDefinition = nodeNameAttributeDefinition
            };

            if (assignIds)
            {
                nodeNameAttribute.Id = new HiveId(Guid.NewGuid());
            }

            var selectedTemplateAttribute = new SelectedTemplateAttribute(new HiveId(Guid.NewGuid()), generalGroup)
            {
                AttributeDefinition = selectedTemplateDefinition
            };

            if (assignIds)
            {
                selectedTemplateAttribute.Id = new HiveId(Guid.NewGuid());
            }

            callback(schema, new[] { attribute1, attribute2, attribute3, attribute4, nodeNameAttribute, selectedTemplateAttribute });
        }