Example #1
0
        public void Can_Compose_Nested_Composite_ContentType_Collection()
        {
            // Arrange
            ContentType  metaContentType   = ContentTypeBuilder.CreateMetaContentType();
            ContentType  simpleContentType = ContentTypeBuilder.CreateSimpleContentType();
            PropertyType propertyType      = new PropertyTypeBuilder()
                                             .WithAlias("coauthor")
                                             .WithName("Co-author")
                                             .Build();
            ContentType simple2ContentType = ContentTypeBuilder.CreateSimpleContentType(
                "anotherSimple",
                "Another Simple Page",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType
            }));

            // Act
            bool addedMeta = simple2ContentType.AddContentType(metaContentType);
            bool added     = simpleContentType.AddContentType(simple2ContentType);
            IEnumerable <PropertyGroup> compositionPropertyGroups = simpleContentType.CompositionPropertyGroups;
            IEnumerable <IPropertyType> compositionPropertyTypes  = simpleContentType.CompositionPropertyTypes;

            // Assert
            Assert.That(addedMeta, Is.True);
            Assert.That(added, Is.True);
            Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(2));
            Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(6));
            Assert.That(simpleContentType.ContentTypeCompositionExists("meta"), Is.True);
        }
Example #2
0
        public void Can_Avoid_Circular_Dependencies_In_Composition()
        {
            ContentType  textPage      = ContentTypeBuilder.CreateTextPageContentType();
            ContentType  parent        = ContentTypeBuilder.CreateSimpleContentType("parent", "Parent", null, randomizeAliases: true);
            ContentType  meta          = ContentTypeBuilder.CreateMetaContentType();
            PropertyType propertyType1 = new PropertyTypeBuilder()
                                         .WithAlias("coauthor")
                                         .WithName("Co-author")
                                         .Build();
            ContentType mixin1 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin1",
                "Mixin1",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType1
            }));
            PropertyType propertyType2 = new PropertyTypeBuilder()
                                         .WithAlias("author")
                                         .WithName("Author")
                                         .Build();
            ContentType mixin2 = ContentTypeBuilder.CreateSimpleContentType(
                "mixin2",
                "Mixin2",
                propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> {
                propertyType2
            }));

            // Act
            bool addedMetaMixin2 = mixin2.AddContentType(meta);
            bool addedMixin2     = mixin1.AddContentType(mixin2);
            bool addedMeta       = parent.AddContentType(meta);

            bool addedMixin1 = parent.AddContentType(mixin1);

            bool addedMixin1Textpage = textPage.AddContentType(mixin1);
            bool addedTextpageParent = parent.AddContentType(textPage);

            IEnumerable <string>        aliases        = textPage.CompositionAliases();
            IEnumerable <IPropertyType> propertyTypes  = textPage.CompositionPropertyTypes;
            IEnumerable <PropertyGroup> propertyGroups = textPage.CompositionPropertyGroups;

            // Assert
            Assert.That(mixin2.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(mixin1.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(parent.ContentTypeCompositionExists("meta"), Is.True);
            Assert.That(textPage.ContentTypeCompositionExists("meta"), Is.True);

            Assert.That(aliases.Count(), Is.EqualTo(3));
            Assert.That(propertyTypes.Count(), Is.EqualTo(8));
            Assert.That(propertyGroups.Count(), Is.EqualTo(2));

            Assert.That(addedMeta, Is.True);
            Assert.That(addedMetaMixin2, Is.True);
            Assert.That(addedMixin2, Is.True);
            Assert.That(addedMixin1, Is.False);
            Assert.That(addedMixin1Textpage, Is.True);
            Assert.That(addedTextpageParent, Is.False);
        }