コード例 #1
0
        private void PerformIsChildOfTests(ContentTypeDefinition childContentType, ContentTypeDefinition parentContentType)
        {
            // by ct
            Assert.IsTrue(ContentTypeDefinitionSyntax.IsChildOf(childContentType, parentContentType));
            Assert.IsFalse(ContentTypeDefinitionSyntax.IsChildOf(parentContentType, childContentType));

            var parentId = parentContentType.GetContentTypeId();
            var childId  = childContentType.GetContentTypeId();

            // by strings
            Assert.IsTrue(ContentTypeDefinitionSyntax.IsChildOf(childId, parentId));
            Assert.IsFalse(ContentTypeDefinitionSyntax.IsChildOf(parentId, childId));

            //  upper-lower case strings
            var parentIdAsLower = string.Join(string.Empty, parentId.Select(s => char.ToLower(s)));
            var parentIdAsUpper = string.Join(string.Empty, parentId.Select(s => char.ToUpper(s)));

            var childIdAsLower = string.Join(string.Empty, childId.Select(s => char.ToLower(s)));
            var childIdAsUpper = string.Join(string.Empty, childId.Select(s => char.ToUpper(s)));

            Assert.IsTrue(ContentTypeDefinitionSyntax.IsChildOf(childIdAsLower, parentIdAsLower));
            Assert.IsFalse(ContentTypeDefinitionSyntax.IsChildOf(parentIdAsUpper, childIdAsLower));

            Assert.IsTrue(ContentTypeDefinitionSyntax.IsChildOf(childIdAsUpper, parentIdAsUpper));
            Assert.IsFalse(ContentTypeDefinitionSyntax.IsChildOf(parentIdAsUpper, childIdAsUpper));
        }
コード例 #2
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanDeployHierarhicalContentTypes()
        {
            var rootDocumentContentType = new ContentTypeDefinition
            {
                Name = "A root document",
                Id   = new Guid("b0ec3794-8bf3-49ed-b8d1-24a4df5ac75b"),
                ParentContentTypeId = BuiltInContentTypeId.Document,
                Group = "SPMeta2.Samples"
            };

            var childDocumentContentType = new ContentTypeDefinition
            {
                Name = "A child document",
                Id   = new Guid("84ab43ee-1f9d-4436-a9de-868bd7a36400"),
                // use GetContentTypeId() to get the content type ID and refer as a parent ID
                ParentContentTypeId = rootDocumentContentType.GetContentTypeId(),
                Group = "SPMeta2.Samples"
            };

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site
                .AddContentType(rootDocumentContentType)
                .AddContentType(childDocumentContentType);
            });

            DeployModel(model);
        }
コード例 #3
0
 public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeDefinition definition, Action <ModelNode> action)
 {
     return(AddContentTypeLink(model, new ContentTypeLinkDefinition
     {
         ContentTypeId = definition.GetContentTypeId(),
         ContentTypeName = definition.Name
     }, action));
 }
コード例 #4
0
 public static TModelNode AddContentTypeLink <TModelNode>(this TModelNode model, ContentTypeDefinition definition,
                                                          Action <ContentTypeLinkModelNode> action)
     where TModelNode : ModelNode, IContentTypeLinkHostModelNode, new()
 {
     return(AddContentTypeLink(model, new ContentTypeLinkDefinition
     {
         ContentTypeId = definition.GetContentTypeId(),
         ContentTypeName = definition.Name
     }, action));
 }
コード例 #5
0
        public override DefinitionBase GenerateRandomDefinition(Action <DefinitionBase> action)
        {
            return(WithEmptyDefinition(def =>
            {
                def.Title = Rnd.String();
                def.FileName = Rnd.String() + ".aspx";

                def.Description = Rnd.String();
                def.Content = Rnd.Bool()
                        ? PublishingPageLayoutTemplates.ArticleLeft :
                              PublishingPageLayoutTemplates.ArticleRight;

                def.AssociatedContentTypeId = PublishingPageContentType.GetContentTypeId();

                def.NeedOverride = true;
            }));
        }
コード例 #6
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanDeploySimplePublishingPageLayoutDefinition()
        {
            var publishingPageContentType = new ContentTypeDefinition
            {
                Name  = "M2 Article",
                Id    = new Guid("664CFB31-AFF3-433E-9F3F-D8812199B0BC"),
                Group = "SPMeta2.Samples",
                ParentContentTypeId = BuiltInPublishingContentTypeId.ArticlePage
            };

            var publshingPageLayout = new PublishingPageLayoutDefinition
            {
                Title    = "M2 Article Left Layout",
                FileName = "m2-article-left.aspx",
                // replace with your publishing page layout content
                Content = DefaultPublishingPageLayoutTemplates.ArticleLeft,
                AssociatedContentTypeId = publishingPageContentType.GetContentTypeId(),
                NeedOverride            = true
            };

            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddContentType(publishingPageContentType);
            });

            var rootWebModel = SPMeta2Model.NewWebModel(web =>
            {
                web.AddHostList(BuiltInListDefinitions.Catalogs.MasterPage, list =>
                {
                    list.AddPublishingPageLayout(publshingPageLayout);
                });
            });

            DeployModel(siteModel);
            DeployModel(rootWebModel);
        }
コード例 #7
0
 public static bool IsChildOf(this ContentTypeDefinition childContentTypeDefinition,
                              string parentContentTypId)
 {
     return(IsChildOf(childContentTypeDefinition.GetContentTypeId(), parentContentTypId));
 }