/// <summary>
        /// Creates Module Attribute
        /// </summary>
        /// <param name="apiModule">ApiModule</param>
        /// <param name="name"> Name of the Module Attribute</param>
        /// <param name="valueRange">ValueRange of the Module Attribute</param>
        /// <param name="value">Default value of the Module Attribute</param>
        /// <param name="pathType">pathType of the Module Attribute</param>
        /// <param name="path">path of the Module Attribute</param>
        /// <param name="actionMode">Default ActionMode of the Module Attribute</param>
        /// <param name="dataType">Data Type of the Module Attribute</param>
        /// <returns>Module Attribute</returns>
        public static XModuleAttribute CreateModuleAttribute(this ApiModule apiModule,
                                                             string name,
                                                             string valueRange,
                                                             string value,
                                                             string pathType,
                                                             string path,
                                                             XTestStepActionMode actionMode =
                                                             XTestStepActionMode.Verify,
                                                             ModuleAttributeDataType dataType =
                                                             ModuleAttributeDataType.String)
        {
            XModuleAttribute xModuleAttribute =
                apiModule.CreateModuleAttribute();

            xModuleAttribute.Name         = name;
            xModuleAttribute.DefaultValue = value;
            if (!string.IsNullOrEmpty(valueRange))
            {
                xModuleAttribute.ValueRange = valueRange;
            }
            xModuleAttribute.EnsureUniqueName();
            xModuleAttribute.AddXParamToModuleAttribute("PathType", pathType, ParamTypeE.TechnicalID);
            xModuleAttribute.AddXParamToModuleAttribute("Path", path, ParamTypeE.TechnicalID);
            xModuleAttribute.AddXParamToModuleAttribute("ExplicitName", "True", ParamTypeE.Configuration);
            xModuleAttribute.DefaultActionMode = actionMode;
            xModuleAttribute.DefaultDataType   = dataType;
            return(xModuleAttribute);
        }
예제 #2
0
        //TODO:
        //When you run this you get an exception. Run in Tosca and fix it derp
        private IEnumerable <XModuleAttribute> CreateClassStructure(XModuleAttribute parent, Type type, XTestStepActionMode defaultMode, int currentDepth, bool isParameter)
        {
            currentDepth++;
            if (currentDepth > MAX_DEPTH)
            {
                yield break;
            }
            //Loop through properties
            var properties = type.GetProperties().Where(x => x.SetMethod.IsPublic);

            foreach (var property in properties)
            {
                var childAttribute = parent.CreateModuleAttribute();
                BuildModuleAttribute(childAttribute, property.Name, property.PropertyType, currentDepth, isParameter, defaultMode);
                yield return(childAttribute);
            }
        }
예제 #3
0
        private void BuildModuleAttribute(XModuleAttribute attribute, string name, Type type, int currentDepth, bool isParameter, XTestStepActionMode defaultMode = XTestStepActionMode.Input)
        {
            attribute.Name = name;
            if (isParameter)
            {
                var paramParam = attribute.CreateConfigurationParam();
                paramParam.Name  = "Parameter";
                paramParam.Value = "True";
            }
            var nameParam = attribute.CreateConfigurationParam();

            nameParam.Name  = "Name";
            nameParam.Value = attribute.Name;

            if (type.IsSimple()) //This is a simple type
            {
                if (IsNumericType(type))
                {
                    attribute.DefaultDataType = ModuleAttributeDataType.Numeric;
                }
                else if (type == typeof(DateTime))
                {
                    attribute.DefaultDataType = ModuleAttributeDataType.Date;
                }
                else if (type == typeof(bool))
                {
                    attribute.DefaultDataType = ModuleAttributeDataType.Boolean;
                    attribute.ValueRange      = "true;false";
                }
                else if (type.IsEnum)
                {
                    attribute.DefaultDataType = ModuleAttributeDataType.String;
                    attribute.ValueRange      = Enum.GetNames(type).Aggregate((x, y) => $"{x};{y}");
                }
                else
                {
                    attribute.DefaultDataType = ModuleAttributeDataType.String;
                }
                attribute.DefaultActionMode = defaultMode;
            }
            else //class
            {
                attribute.DefaultActionMode = XTestStepActionMode.Select;
                var structureModules = CreateClassStructure(attribute, type, defaultMode, currentDepth, isParameter).ToArray();
            }
        }
예제 #4
0
        /// <summary>
        /// Creates and set module attributes at module and teststep
        /// </summary>
        /// <param name="wseTestStepValue">TestStepValues of WSE Teststep</param>
        /// <param name="tcPath">XPath and JsonPath for xml and Json respectively</param>
        /// <param name="xModule">xModule and xModuleAttribute of ApiEngine</param>
        /// <param name="xModuleDemo">ApiModule</param>
        /// <param name="parameterPathType">Enum which define creation of xml and json moduleattributes</param>
        /// <param name="parentTest">TestStep and TestStepValues for ApiTestStep</param>
        /// <param name="cardinality">Cardinality of WSE XModule</param>
        /// <param name="isArray">True if Wse Xmodule attributes is array</param>
        /// <returns></returns>
        public static XTestStepValue CreateBusinessParameterInTosca(XTestStepValue wseTestStepValue,
                                                                    string tcPath,
                                                                    dynamic xModule,
                                                                    ApiModule xModuleDemo,
                                                                    BusinessParameterPathTypes parameterPathType,
                                                                    dynamic parentTest,
                                                                    string cardinality,
                                                                    bool isArray)
        {
            string businessParameterName  = wseTestStepValue.Name;
            string businessParameterValue = wseTestStepValue.Value == "{NULL}" ? string.Empty : wseTestStepValue.Value;
            XTestStepActionMode     xTestStepActionMode = wseTestStepValue.ActionModeToUse;
            ModuleAttributeDataType attributeDataType   = wseTestStepValue.DataType;

            var mAttributes = xModuleDemo.Search("=>SUBPARTS:XModuleAttribute").Cast <XModuleAttribute>();

            XModuleAttribute xModuleAttribute = GetExistingXModuleAttribute(mAttributes, tcPath, parameterPathType);

            if (xModuleAttribute != null)
            {
                if (!string.IsNullOrEmpty(xModuleAttribute.ValueRange))
                {
                    if (!xModuleAttribute.ValueRange.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                        .Contains(businessParameterValue))
                    {
                        xModuleAttribute.ValueRange =
                            $"{xModuleAttribute.ValueRange};{businessParameterValue}";
                    }
                }
                else
                {
                    xModuleAttribute.ValueRange =
                        $"{businessParameterValue}";
                }
            }
            else
            {
                xModuleAttribute      = xModule.CreateModuleAttribute();
                xModuleAttribute.Name = businessParameterName;
                xModuleAttribute.AddXParamToModuleAttribute("PathType",
                                                            parameterPathType == BusinessParameterPathTypes.XPATH
                                                                    ? "XPath"
                                                                    : parameterPathType
                                                            == BusinessParameterPathTypes.JSONPATH
                                                                            ? "JsonPath"
                                                                            : "",
                                                            ParamTypeE.TechnicalID);
                xModuleAttribute.AddXParamToModuleAttribute("Path",
                                                            tcPath,
                                                            ParamTypeE.TechnicalID);
                xModuleAttribute.AddXParamToModuleAttribute("ExplicitName",
                                                            "True",
                                                            ParamTypeE.Configuration);
                xModuleAttribute.DefaultActionMode = xTestStepActionMode;
                xModuleAttribute.DefaultDataType   = wseTestStepValue.ModuleAttribute.DefaultDataType;
                xModuleAttribute.DefaultValue      = wseTestStepValue.ModuleAttribute?.DefaultValue == "{NULL}"
                                                        ? string.Empty
                                                        : wseTestStepValue.ModuleAttribute?.DefaultValue;
                xModuleAttribute.ValueRange  = $"{businessParameterValue}";
                xModuleAttribute.Cardinality = isArray ? "0-N" : cardinality;
                xModuleAttribute.EnsureUniqueName();
            }

            XTestStepValue testStepValue = parentTest.CreateXTestStepValue(xModuleAttribute);

            testStepValue.ActionProperty = wseTestStepValue.ActionProperty;
            testStepValue.Operator       = wseTestStepValue.Operator;
            testStepValue.Value          = wseTestStepValue.Value;
            testStepValue.ActionMode     = xTestStepActionMode;
            testStepValue.DataType       = attributeDataType;
            testStepValue.Disabled       = wseTestStepValue.Disabled;
            SetConstraintIndexProperty(wseTestStepValue, testStepValue);
            return(testStepValue);
        }