Example #1
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(x => x.At(AttributeLevels.Declared));

            if (!string.IsNullOrWhiteSpace(nameAttribute?.Value))
            {
                return(nameAttribute.Value);
            }

            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitionAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
Example #2
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(AttributeLevels.Declared);

            if (nameAttribute != null && !string.IsNullOrWhiteSpace(nameAttribute.Value))
            {
                return(nameAttribute.Value);
            }

            FindByLabelAttribute findByLabelAttribute = findAttribute as FindByLabelAttribute;

            if (findByLabelAttribute != null)
            {
                if (findByLabelAttribute.Values != null && findByLabelAttribute.Values.Any())
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(AttributeLevels.Declared);
                    if (termAttribute != null && termAttribute.Values != null && termAttribute.Values.Any())
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitonAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
Example #3
0
        protected internal override void ApplyMetadata(UIComponentMetadata metadata)
        {
            selectByAttribute = metadata.Get <SelectByTextAttribute>(AttributeLevels.Declared)
                                ?? (TermSettingsAttribute)metadata.Get <SelectByValueAttribute>(AttributeLevels.Declared)
                                ?? new SelectByTextAttribute();

            by = selectByAttribute is SelectByTextAttribute ? SelectBy.Text : SelectBy.Value;

            base.ApplyMetadata(metadata);
        }
Example #4
0
        private static T RandomizeNumber <T>(UIComponentMetadata metadata)
        {
            var attribute = metadata.Get <RandomizeNumberSettingsAttribute>(AttributeLevels.Declared) ?? new RandomizeNumberSettingsAttribute();

            decimal value = Randomizer.GetDecimal(attribute.Min, attribute.Max, attribute.Precision);

            return((T)Convert.ChangeType(value, typeof(T)));
        }
Example #5
0
        private static string GetControlNameFromNameAttribute(UIComponentMetadata metadata)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(x => x.At(AttributeLevels.Declared));

            return(!string.IsNullOrWhiteSpace(nameAttribute?.Value)
                ? nameAttribute.Value
                : null);
        }
Example #6
0
        private static string RandomizeString(UIComponentMetadata metadata)
        {
            var attribute = metadata.Get <RandomizeStringSettingsAttribute>(AttributeLevels.Declared) ?? new RandomizeStringSettingsAttribute();

            string format = NormalizeStringFormat(attribute.Format);

            return(Randomizer.GetString(format, attribute.NumberOfCharacters));
        }
Example #7
0
        private static T[] GetEnumOptionValues <T>(Type enumType, UIComponentMetadata metadata)
        {
            var includeAttribute = metadata.Get <RandomizeIncludeAttribute>(AttributeLevels.Declared);
            var excludeAttribute = metadata.Get <RandomizeExcludeAttribute>(AttributeLevels.Declared);

            T[] values = includeAttribute?.Values?.Cast <T>()?.ToArray();
            if (values == null || values.Length == 0)
            {
                values = enumType.GetIndividualEnumFlags().Cast <T>().ToArray();
            }

            if (excludeAttribute?.Values?.Any() ?? false)
            {
                var valuesToExclude = excludeAttribute.Values.Cast <T>();
                values = values.Except(valuesToExclude).ToArray();
            }

            return(values);
        }
Example #8
0
        protected override void InitValueTermOptions(TermOptions termOptions, UIComponentMetadata metadata)
        {
            base.InitValueTermOptions(termOptions, metadata);

            IPropertySettings findItemAttributeAsSettings = metadata.Get <IFindItemAttribute>(AttributeLevels.Declared) as IPropertySettings;

            if (findItemAttributeAsSettings != null)
            {
                termOptions.MergeWith(findItemAttributeAsSettings);
            }
        }
Example #9
0
        private static string RandomizeString(UIComponentMetadata metadata)
        {
            if (!TryRandomizeOneOfIncluded(metadata, out string value))
            {
                var attribute = metadata.Get <RandomizeStringSettingsAttribute>()
                                ?? new RandomizeStringSettingsAttribute();

                value = Randomizer.GetString(attribute.Format, attribute.NumberOfCharacters);
            }

            return(value);
        }
Example #10
0
        protected internal override void ApplyMetadata(UIComponentMetadata metadata)
        {
            base.ApplyMetadata(metadata);

            WindowTitleAttribute titleAttribute = metadata.Get <WindowTitleAttribute>(x => x.At(AttributeLevels.Component));

            if (titleAttribute != null)
            {
                WindowTitleValues = titleAttribute.GetActualValues(ComponentName);
                WindowTitleMatch  = titleAttribute.Match;
            }
        }
Example #11
0
        private static T RandomizeNumber <T>(UIComponentMetadata metadata)
        {
            if (!TryRandomizeOneOfIncluded(metadata, out T value))
            {
                var attribute = metadata.Get <RandomizeNumberSettingsAttribute>()
                                ?? new RandomizeNumberSettingsAttribute();

                decimal valueAsDecimal = Randomizer.GetDecimal(attribute.Min, attribute.Max, attribute.Precision);
                value = (T)Convert.ChangeType(valueAsDecimal, typeof(T));
            }

            return(value);
        }
Example #12
0
        private static string RandomizeString(UIComponentMetadata metadata)
        {
            string value;

            if (!TryRandomizeOneOfIncluded(metadata, out value))
            {
                var attribute = metadata.Get <RandomizeStringSettingsAttribute>(x => x.At(AttributeLevels.Declared)) ?? new RandomizeStringSettingsAttribute();

                string format = NormalizeStringFormat(attribute.Format);
                value = Randomizer.GetString(format, attribute.NumberOfCharacters);
            }

            return(value);
        }
Example #13
0
        private static string GetControlNameFromFindAttribute(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(null);
        }
Example #14
0
        private static T RandomizeFlagsEnum <T>(Type enumType, UIComponentMetadata metadata)
        {
            var optionValues   = GetEnumOptionValues <T>(enumType, metadata);
            var countAttribute = metadata.Get <RandomizeCountAttribute>(x => x.At(AttributeLevels.Declared));

            int minCount = countAttribute?.Min ?? 1;
            int maxCount = countAttribute?.Max ?? 1;

            T[] valuesAsArray = Randomizer.GetManyOf(minCount, maxCount, optionValues);

            if (valuesAsArray.Length > 1)
            {
                Enum first = (Enum)(object)valuesAsArray[0];
                return((T)(object)valuesAsArray.Skip(1).Cast <Enum>().Aggregate(first, (a, b) => a.AddFlag(b)));
            }
            else
            {
                return(valuesAsArray[0]);
            }
        }
Example #15
0
        private static FindAttribute GetPropertyFindAttribute(UIComponentMetadata metadata)
        {
            FindAttribute findAttribute = metadata.Get <FindAttribute>(x => x.At(AttributeLevels.Declared));

            if (findAttribute != null)
            {
                return(findAttribute);
            }
            else
            {
                Type controlType         = metadata.ComponentType;
                Type parentComponentType = metadata.ParentComponentType;

                ControlFindingAttribute controlFindingAttribute =
                    GetNearestControlFindingAttribute(controlType, parentComponentType, metadata.ParentComponentAttributes) ??
                    GetNearestControlFindingAttribute(controlType, parentComponentType, metadata.AssemblyAttributes) ??
                    GetNearestDefaultControlFindingAttribute(parentComponentType, metadata.ComponentAttributes);

                return(controlFindingAttribute != null
                    ? controlFindingAttribute.CreateFindAttribute()
                    : GetDefaultFindAttribute(metadata));
            }
        }
Example #16
0
 // TODO: Remove this method when IItemsControl will be removed.
 private static IFindItemAttribute GetPropertyFindItemAttribute(UIComponentMetadata metadata)
 {
     return(metadata.Get <IFindItemAttribute>(x => x.At(AttributeLevels.Declared)) ?? new FindItemByLabelAttribute());
 }
Example #17
0
        private static T[] GetRandomizeIncludeValues <T>(UIComponentMetadata metadata)
        {
            var includeAttribute = metadata.Get <RandomizeIncludeAttribute>(x => x.At(AttributeLevels.Declared));

            return(includeAttribute?.Values?.Cast <T>()?.ToArray());
        }
 public static PageObjectDefinitionAttribute GetPageObjectDefinition(UIComponentMetadata metadata)
 {
     return(metadata.Get <PageObjectDefinitionAttribute>(AttributeLevels.Declared | AttributeLevels.Component) ?? new PageObjectDefinitionAttribute());
 }
 public static ControlDefinitionAttribute GetControlDefinition(UIComponentMetadata metadata)
 {
     return(metadata.Get <ControlDefinitionAttribute>(AttributeLevels.Declared | AttributeLevels.Component) ?? new ControlDefinitionAttribute());
 }