private void EnsureMandatoryValuesAreProvided(CustomFieldData customFieldData)
        {
            var dataErrorFound        = false;
            var customFieldDataErrors = new StringBuilder();

            customFieldDataErrors.Append("The feature file " + FeatureContext.FeatureInfo.Title + " has the following data issues:");
            if (string.IsNullOrWhiteSpace(customFieldData.ApplyTo.ToString()))
            {
                dataErrorFound = true;
                customFieldDataErrors.Append("\n- ApplyTo was not set");
            }

            if (string.IsNullOrWhiteSpace(customFieldData.Name))
            {
                dataErrorFound = true;
                customFieldDataErrors.Append("\n- Name was not set");
            }

            if (string.IsNullOrWhiteSpace(customFieldData.DisplayName))
            {
                dataErrorFound = true;
                customFieldDataErrors.Append("\n- Display Name was not set");
            }

            if (dataErrorFound)
            {
                throw new ArgumentException(customFieldDataErrors.ToString());
            }
        }
        public void DeleteCustomField(CustomFieldData customField)
        {
            var customFieldCheckbox = FindElementByXPath(string.Format(CUSTOM_FIELD_CHECKBOX, customField.Name));

            ClickElement(customFieldCheckbox);
            ClickElement(_btnDelete);
        }
        private void PopulateDynamicFieldsBasedOnCustomFieldType(CustomFieldData customField)
        {
            var type = GetCustomFieldType();

            switch (type)
            {
            case "Text":
            case "Multiline":
                if (customField.CharacterLimit == 0)
                {
                    throw new ArgumentException("Character limit cannot be 0");
                }
                if (_txtCharacterLimit.Enabled)
                {
                    ClearInputAndTypeValue(_txtCharacterLimit, customField.CharacterLimit.ToString());
                }
                if (_txtDefaultValue.Enabled)
                {
                    ClearInputAndTypeValueIfRequired(_txtDefaultValue, customField.DefaultText);
                }
                if (!customField.ApplyTo.ToString().Equals("Client"))
                {
                    SetReactCheckBoxState(_chkMandatory, customField.Mandatory);
                }
                break;

            case "MultiSelect":
                DeleteAllMultiSelectOptions();
                AddMultiSelectOptions(customField.MultiSelectOptions);
                if (!customField.ApplyTo.ToString().Equals("Client"))
                {
                    SetReactCheckBoxState(_chkMandatory, customField.Mandatory);
                }
                break;

            case "Image":
                if (customField.Resolution != null)
                {
                    ClearInputAndTypeValueIfRequired(_txtWidth, customField.Resolution.Width);
                    ClearInputAndTypeValueIfRequired(_txtHeight, customField.Resolution.Height);
                }
                break;

            case "DatePicker":
                if (!customField.ApplyTo.ToString().Equals("Client"))
                {
                    SetReactCheckBoxState(_chkMandatory, customField.Mandatory);
                }
                break;

            default:
                throw new NotSupportedException($"Custom field type: '{type}' not supported.");
            }
        }
Пример #4
0
        private bool AttachObjectCustomFieldWithDefaultValue(Session session
                                                             , DAL.CMS.ObjectDocument.Object CMSObject
                                                             , NAS.DAL.CMS.ObjectDocument.ObjectTypeCustomField objectTypeCustomField
                                                             , CustomFieldTypeFlag option)
        {
            try
            {
                //Create ObjectCustomField
                ObjectCustomField objectCustomField = new ObjectCustomField(session)
                {
                    ObjectCustomFieldId     = Guid.NewGuid(),
                    ObjectId                = CMSObject,
                    ObjectTypeCustomFieldId = objectTypeCustomField,
                    CustomFieldType         = option.Value
                };
                objectCustomField.Save();

                //Insert default value for custom field
                CustomFieldData customFieldData = null;

                string customFieldTypeCode = objectTypeCustomField.CustomFieldId.CustomFieldTypeId.Code;

                BasicCustomFieldTypeEnum basicCustomFieldType = BasicCustomFieldTypeEnum.NONE;

                bool isBasicType =
                    Enum.TryParse <BasicCustomFieldTypeEnum>(customFieldTypeCode, out basicCustomFieldType);

                if (isBasicType)
                {
                    customFieldData = InitDefaultDataForBasicCustomFieldType(session,
                                                                             (BasicCustomFieldTypeEnum)Enum.Parse(typeof(BasicCustomFieldTypeEnum), customFieldTypeCode),
                                                                             objectTypeCustomField.CustomFieldId.CustomFieldId);

                    if (customFieldData != null)
                    {
                        //Insert into ObjectCustomFieldData
                        ObjectCustomFieldData defaultObjectCustomFieldData =
                            new ObjectCustomFieldData(session)
                        {
                            ObjectCustomFieldDataId = Guid.NewGuid(),
                            CustomFieldDataId       = customFieldData,
                            ObjectCustomFieldId     = objectCustomField
                        };
                        defaultObjectCustomFieldData.Save();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void AddCustomField(CustomFieldData customField)
        {
            EnsureMandatoryValuesAreProvided(customField);

            ClickElement(_btnAdd);
            SelectSingleValueFromReactDropdownByText(_ddlApplyTo, customField.ApplyTo.ToString());
            SelectSingleValueFromReactDropdownByText(_ddlName, customField.Name);
            ClearInputAndTypeValue(_txtDisplayName, customField.DisplayName);
            PopulateDynamicFieldsBasedOnCustomFieldType(customField);
            ClickElement(_btnSave);
            WaitForElementToBeInvisible(By.XPath("//div[@class='modal-sm modal-dialog']"));
        }
        public void EditCustomField(CustomFieldData customField)
        {
            EnsureMandatoryValuesAreProvided(customField);

            var customFieldCheckbox = FindElementByXPath(string.Format(CUSTOM_FIELD_CHECKBOX, customField.Name));

            ClickElement(customFieldCheckbox);
            ClickElement(_btnEdit);
            ClearInputAndTypeValue(_txtDisplayName, customField.DisplayName);
            PopulateDynamicFieldsBasedOnCustomFieldType(customField);
            ClickElement(_btnSave);
            WaitForElementToBeInvisible(By.XPath("//div[@class='modal-sm modal-dialog']"));
        }
Пример #7
0
        private CustomFieldData InitDefaultDataForBasicCustomFieldType(
            Session session,
            BasicCustomFieldTypeEnum basicCustomFieldType,
            Guid customFieldId)
        {
            CustomFieldData customFieldData = null;
            CustomField     customField     = null;

            customField = session.GetObjectByKey <CustomField>(customFieldId);

            if (customField == null)
            {
                throw new Exception("Could not found the custom field");
            }

            switch (basicCustomFieldType)
            {
            case BasicCustomFieldTypeEnum.STRING:
                customFieldData = new CustomFieldDataString(session)
                {
                    CustomFieldDataId = Guid.NewGuid(),
                    CustomFieldId     = customField,
                    StringValue       = String.Empty
                };
                customFieldData.Save();
                break;

            case BasicCustomFieldTypeEnum.DATETIME:
                customFieldData = new CustomFieldDataDateTime(session)
                {
                    CustomFieldDataId = Guid.NewGuid(),
                    CustomFieldId     = customField,
                    DateTimeValue     = DateTime.MinValue
                };
                customFieldData.Save();
                break;

            case BasicCustomFieldTypeEnum.FLOAT:
                customFieldData = new CustomFieldDataFloat(session)
                {
                    CustomFieldDataId = Guid.NewGuid(),
                    CustomFieldId     = customField,
                    FloatValue        = float.MinValue
                };
                customFieldData.Save();
                break;

            case BasicCustomFieldTypeEnum.INTEGER:
                customFieldData = new CustomFieldDataInt(session)
                {
                    CustomFieldDataId = Guid.NewGuid(),
                    CustomFieldId     = customField,
                    IntValue          = int.MinValue
                };
                customFieldData.Save();
                break;

            default:
                break;
            }

            return(customFieldData);
        }
 public bool DoesCustomFieldExist(CustomFieldData customField)
 {
     return(IsElementPresent(By.XPath(string.Format(DYNAMIC_CUSTOM_FIELD_XPATH, customField.Name))));
 }