Esempio n. 1
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);
        }