コード例 #1
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);
        }