public void GivenPageTypePropertyDefinitionWithNoEditCaption_GetEditCaptionOrName_ReturnsName()
        {
            string propertyName = TestValueUtility.CreateRandomString();
            PageTypePropertyDefinition definition = 
                new PageTypePropertyDefinition(propertyName, typeof(string), new NativePageType(), new PageTypePropertyAttribute());

            string returnedEditCaption = definition.GetEditCaptionOrName();

            Assert.Equal<string>(propertyName, returnedEditCaption);
        }
        public void GivenPageTypePropertyDefinitionWithEditCaption_GetEditCaptionOrName_ReturnsEditCaptionFromAttribute()
        {
            PageTypePropertyDefinition definition =
                new PageTypePropertyDefinition(TestValueUtility.CreateRandomString(), typeof(string), new NativePageType(), new PageTypePropertyAttribute(), null);
            string editCaption = TestValueUtility.CreateRandomString();
            definition.PageTypePropertyAttribute.EditCaption = editCaption;

            string returnedEditCaption = definition.GetEditCaptionOrName(false);

            Assert.Equal<string>(editCaption, returnedEditCaption);
        }
        protected internal virtual PageDefinition CreateNewPageDefinition(PageTypePropertyDefinition propertyDefinition)
        {
            PageDefinition pageDefinition = new PageDefinition();
            pageDefinition.PageTypeID = propertyDefinition.PageType.ID;
            pageDefinition.Name = propertyDefinition.Name;
            pageDefinition.EditCaption = propertyDefinition.GetEditCaptionOrName();
            SetPageDefinitionType(pageDefinition, propertyDefinition);

            PageDefinitionFactory.Save(pageDefinition);
            
            return pageDefinition;
        }
        public virtual void CreateNewPageDefinition(PageTypePropertyDefinition propertyDefinition)
        {
            PageDefinition pageDefinition = new PageDefinition();
            pageDefinition.PageTypeID = propertyDefinition.PageType.ID;
            pageDefinition.Name = propertyDefinition.Name;
            pageDefinition.EditCaption = propertyDefinition.GetEditCaptionOrName();
            SetPageDefinitionType(pageDefinition, propertyDefinition);

            UpdatePageDefinitionValues(pageDefinition, propertyDefinition);

            pageDefinitionRepository.Save(pageDefinition);
        }
        protected internal virtual void UpdatePageDefinitionValues(PageDefinition pageDefinition, PageTypePropertyDefinition pageTypePropertyDefinition)
        {
            PageTypePropertyAttribute propertyAttribute = pageTypePropertyDefinition.PageTypePropertyAttribute;

            pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();
            pageDefinition.HelpText = propertyAttribute.HelpText ?? string.Empty;
            pageDefinition.Required = propertyAttribute.Required;
            pageDefinition.Searchable = propertyAttribute.Searchable;
            pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null ? propertyAttribute.DefaultValue.ToString() : string.Empty;
            pageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;
            pageDefinition.LanguageSpecific = propertyAttribute.UniqueValuePerLanguage;
            pageDefinition.DisplayEditUI = propertyAttribute.DisplayInEditMode;
            pageDefinition.FieldOrder = propertyAttribute.SortOrder;
            UpdateLongStringSettings(pageDefinition, propertyAttribute);
            UpdatePageDefinitionTab(pageDefinition, propertyAttribute);
        }
        protected virtual void UpdatePageDefinitionValues(PageDefinition pageDefinition, PageTypePropertyDefinition pageTypePropertyDefinition)
        {
            pageDefinition.Name = pageTypePropertyDefinition.Name;

            PageTypePropertyAttribute propertyAttribute = pageTypePropertyDefinition.PageTypePropertyAttribute;
            
            var specifiedType = GetPageDefinitionType(pageTypePropertyDefinition);
            var currentType = pageDefinition.Type;
            
            if(specifiedType.DataType == currentType.DataType)
                pageDefinition.Type = specifiedType;

            if (CanModifyProperty(pageDefinition, propertyAttribute.EditCaptionSet))
                pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();
            else if (!propertyAttribute.EditCaptionSet && string.IsNullOrEmpty(pageDefinition.EditCaption))
                pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();

            if (CanModifyProperty(pageDefinition, propertyAttribute.HelpTextSet))
                pageDefinition.HelpText = propertyAttribute.HelpText ?? string.Empty;

            if (CanModifyProperty(pageDefinition, propertyAttribute.RequiredSet))
                pageDefinition.Required = propertyAttribute.Required;

            if (CanModifyProperty(pageDefinition, propertyAttribute.SearchableSet))
                pageDefinition.Searchable = propertyAttribute.Searchable;

            if (CanModifyProperty(pageDefinition, propertyAttribute.DefaultValueSet))
                pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null ? propertyAttribute.DefaultValue.ToString() : string.Empty;

            if (CanModifyProperty(pageDefinition, propertyAttribute.DefaultValueTypeSet))
                pageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;

            if (CanModifyProperty(pageDefinition, propertyAttribute.UniqueValuePerLanguageSet))
                pageDefinition.LanguageSpecific = propertyAttribute.UniqueValuePerLanguage;

            if (CanModifyProperty(pageDefinition, propertyAttribute.DisplayInEditModeSet))
                pageDefinition.DisplayEditUI = propertyAttribute.DisplayInEditMode;

            if (CanModifyProperty(pageDefinition, propertyAttribute.SortOrderSet))
                pageDefinition.FieldOrder = GetFieldOrder(pageDefinition, propertyAttribute);

            if (CanModifyProperty(pageDefinition, propertyAttribute.TabSet))
                UpdatePageDefinitionTab(pageDefinition, propertyAttribute);
        }
        protected virtual void UpdatePageDefinitionValues(PageDefinition pageDefinition, PageTypePropertyDefinition pageTypePropertyDefinition)
        {
            PageTypePropertyAttribute propertyAttribute = pageTypePropertyDefinition.PageTypePropertyAttribute;
            
            var specifiedType = GetPageDefinitionType(pageTypePropertyDefinition);
            var currentType = pageDefinition.Type;
            if(specifiedType.DataType == currentType.DataType)
            {
                pageDefinition.Type = specifiedType;
            }

            pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();
            pageDefinition.HelpText = propertyAttribute.HelpText ?? string.Empty;
            pageDefinition.Required = propertyAttribute.Required;
            pageDefinition.Searchable = propertyAttribute.Searchable;
            pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null ? propertyAttribute.DefaultValue.ToString() : string.Empty;
            pageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;
            pageDefinition.LanguageSpecific = propertyAttribute.UniqueValuePerLanguage;
            pageDefinition.DisplayEditUI = propertyAttribute.DisplayInEditMode;
            pageDefinition.FieldOrder = GetFieldOrder(pageDefinition, propertyAttribute);
            UpdatePageDefinitionTab(pageDefinition, propertyAttribute);
        }