public void Can_Copy_ContentType_By_Performing_Clone()
        {
            // Arrange
            var service         = ServiceContext.ContentTypeService;
            var metaContentType = MockedContentTypes.CreateMetaContentType();

            service.Save(metaContentType);

            var simpleContentType = MockedContentTypes.CreateSimpleContentType("category", "Category", metaContentType);

            service.Save(simpleContentType);
            var categoryId = simpleContentType.Id;

            // Act
            var sut = simpleContentType.Clone("newcategory");

            service.Save(sut);

            // Assert
            Assert.That(sut.HasIdentity, Is.True);

            var contentType = service.GetContentType(sut.Id);
            var category    = service.GetContentType(categoryId);

            Assert.That(contentType.CompositionAliases().Any(x => x.Equals("meta")), Is.True);
            Assert.AreEqual(contentType.ParentId, category.ParentId);
            Assert.AreEqual(contentType.Level, category.Level);
            Assert.AreEqual(contentType.PropertyTypes.Count(), category.PropertyTypes.Count());
            Assert.AreNotEqual(contentType.Id, category.Id);
            Assert.AreNotEqual(contentType.Key, category.Key);
            Assert.AreNotEqual(contentType.Path, category.Path);
            Assert.AreNotEqual(contentType.SortOrder, category.SortOrder);
            Assert.AreNotEqual(contentType.PropertyTypes.First(x => x.Alias.Equals("title")).Id, category.PropertyTypes.First(x => x.Alias.Equals("title")).Id);
            Assert.AreNotEqual(contentType.PropertyGroups.First(x => x.Name.Equals("Content")).Id, category.PropertyGroups.First(x => x.Name.Equals("Content")).Id);
        }
Exemple #2
0
        public void Can_Compose_Nested_Composite_ContentType_Collection()
        {
            // Arrange
            var metaContentType    = MockedContentTypes.CreateMetaContentType();
            var simpleContentType  = MockedContentTypes.CreateSimpleContentType();
            var simple2ContentType = MockedContentTypes.CreateSimpleContentType("anotherSimple", "Another Simple Page",
                                                                                new PropertyTypeCollection(true,
                                                                                                           new List <PropertyType>
            {
                new PropertyType("test", ValueStorageType.Ntext, "coauthor")
                {
                    Name        = "Co-Author",
                    Description = "Name of the Co-Author",
                    Mandatory   = false,
                    SortOrder   = 4,
                    DataTypeId  = -88
                }
            }));

            // Act
            var addedMeta = simple2ContentType.AddContentType(metaContentType);
            var added     = simpleContentType.AddContentType(simple2ContentType);
            var compositionPropertyGroups = simpleContentType.CompositionPropertyGroups;
            var 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);
        }
Exemple #3
0
        public void Can_Avoid_Circular_Dependencies_In_Composition()
        {
            var textPage = MockedContentTypes.CreateTextPageContentType();
            var parent   = MockedContentTypes.CreateSimpleContentType("parent", "Parent", null, true);
            var meta     = MockedContentTypes.CreateMetaContentType();
            var mixin1   = MockedContentTypes.CreateSimpleContentType("mixin1", "Mixin1", new PropertyTypeCollection(true,
                                                                                                                     new List <PropertyType>
            {
                new PropertyType("test", ValueStorageType.Ntext, "coauthor")
                {
                    Name        = "Co-Author",
                    Description = "Name of the Co-Author",
                    Mandatory   = false,
                    SortOrder   = 4,
                    DataTypeId  = -88
                }
            }));
            var mixin2 = MockedContentTypes.CreateSimpleContentType("mixin2", "Mixin2", new PropertyTypeCollection(true,
                                                                                                                   new List <PropertyType>
            {
                new PropertyType("test", ValueStorageType.Ntext, "author")
                {
                    Name        = "Author",
                    Description = "Name of the Author",
                    Mandatory   = false,
                    SortOrder   = 4,
                    DataTypeId  = -88
                }
            }));

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

            var addedMixin1 = parent.AddContentType(mixin1);

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

            var aliases        = textPage.CompositionAliases();
            var propertyTypes  = textPage.CompositionPropertyTypes;
            var 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);
        }