Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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]);
            }
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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());
 }
Exemplo n.º 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());
        }
Exemplo n.º 18
0
 public static PageObjectDefinitionAttribute GetPageObjectDefinition(UIComponentMetadata metadata)
 {
     return(metadata.Get <PageObjectDefinitionAttribute>(AttributeLevels.Declared | AttributeLevels.Component) ?? new PageObjectDefinitionAttribute());
 }
Exemplo n.º 19
0
 public static ControlDefinitionAttribute GetControlDefinition(UIComponentMetadata metadata)
 {
     return(metadata.Get <ControlDefinitionAttribute>(AttributeLevels.Declared | AttributeLevels.Component) ?? new ControlDefinitionAttribute());
 }