public virtual ContentType Map(PageType pageType) { if (pageType == null) throw new ArgumentNullException("pageType"); if (string.IsNullOrEmpty(pageType.Name)) throw new ArgumentException("PageType must have a name.", "pageType"); var contentTypeCategory = GetContentTypeCategory(pageType); var contentType = new ContentType { Name = pageType.Name, Description = pageType.Description, GUID = pageType.GUID, // As all Composer Function page types are set as not available we reverse this here IsAvailable = pageType.IsAvailable || contentTypeCategory == ContentTypeCategory.Block, SortOrder = pageType.SortOrder, ACL = pageType.ACL, ContentTypeCategory = contentTypeCategory, Defaults = pageType.Defaults }; EnsureValidNaming(contentType); // Set DisplayName to original name if (contentType.Name != pageType.Name) { contentType.DisplayName = pageType.Name.StartsWith(ComposerPageTypes.Prefix) ? pageType.Name.Substring(ComposerPageTypes.Prefix.Length).TrimStart() : pageType.Name; } contentType.Namespace = CalculateNamespace(contentType); MapProperties(pageType, contentType); return contentType; }
public void Map_ShouldFilterOutComposerSystemProperties() { var validProperty = "MainBody"; var definitionType = new PageDefinitionType { DataType = "String" }; var source = new PageType { Name = "SomePage", GUID = Guid.NewGuid(), Definitions = { new PageDefinition { Name = validProperty, Type = definitionType }, new PageDefinition { Name = ComposerProperties.Page, Type = definitionType }, new PageDefinition { Name = ComposerProperties.ContainerPage, Type = definitionType }, new PageDefinition { Name = ComposerProperties.ContentFunction, Type = definitionType }, new PageDefinition { Name = ComposerProperties.NeverUsed, Type = definitionType }, new PageDefinition { Name = ComposerProperties.PersonalizationData, Type = definitionType } } }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(validProperty, result.PropertyDefinitions.Single().Name); }
public void Map_NameIsNotChanged_ShouldNotSetDisplayName() { var source = new PageType { Name = "Homepage" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.IsNull(result.DisplayName); }
public void Map_ShouldMapACL() { var source = new PageType { Name = "Name", ACL = new AccessControlList { Entries = new List<AccessControlEntry> { new AccessControlEntry { Name = "Everyone", EntityType = SecurityEntityType.User, Access = AccessLevel.Create } } } }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(1, result.ACL.Entries.Count); Assert.AreEqual("Everyone", result.ACL.Entries[0].Name); }
private void MapProperties(PageType pageType, ContentType contentType) { foreach (var pageDefinition in pageType.Definitions.Where(SupportedPropertiesPredicate)) { var propertyDefinition = _propertyMapper.Map(pageDefinition); if (propertyDefinition != null) { contentType.PropertyDefinitions.Add(propertyDefinition); } } }
private ContentTypeCategory GetContentTypeCategory(PageType pageType) { // If the filename ends with .ascx we assume its a function type if (pageType.ExportableFileName != null && pageType.ExportableFileName.EndsWith(UserControlExtension, StringComparison.OrdinalIgnoreCase)) { return ContentTypeCategory.Block; } return ContentTypeCategory.Page; }
public void Map_ShouldMapAllSimpleProperties() { var source = new PageType { Name = "SomePage", Description = "Some description", GUID = Guid.NewGuid(), IsAvailable = true, SortOrder = 43 }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(source.Name, result.Name); Assert.AreEqual(source.Description, result.Description); Assert.AreEqual(source.GUID, result.GUID); Assert.AreEqual(source.IsAvailable, result.IsAvailable); Assert.AreEqual(source.SortOrder, result.SortOrder); }
public void Map_WhenTypeIsBlock_ShouldSetIsAvailableToTrue() { var source = new PageType { Name = "MyBlock", IsAvailable = false, ExportableFileName = "~/Templates/Blocks/MyBlock.ascx" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.IsTrue(result.IsAvailable); }
public void Map_WhenNameIsNotValidIdentifier_ShouldSetDisplayNameToPageTypeName() { var source = new PageType { Name = "My Page" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(source.Name, result.DisplayName); }
public void Map_WhenNameHasGroup_ShouldSetDisplayNameToPageTypeNameWithoutGroup() { var source = new PageType { Name = "[My group] Page" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(source.Name, result.DisplayName); }
public void Map_WhenNameHasExtensionGroup_ShouldRemoveGroupFromDisplayName() { var source = new PageType { Name = "[ExtensionSys] Page" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual("Page", result.DisplayName); }
public void Map_WhenFileNameIsUserControl_ShouldSetIsBlockType() { var source = new PageType { Name = "MyBlock", ExportableFileName = "~/Templates/Blocks/MyBlock.ascx" }; var subject = CreateSubject(); var result = subject.Map(source); Assert.AreEqual(ContentTypeCategory.Block, result.ContentTypeCategory); }