/// <summary> /// construct json payload for Api modules /// </summary> /// <param name="rawRequestPayload">WSE XTestStepValues</param> /// <param name="jObject">json payload</param> /// <returns>json payload</returns> public static JObject ConstructJsonStructure(XTestStepValue rawRequestPayload, JObject jObject) { try { foreach (var testStepValue in rawRequestPayload.SubValues) { if (testStepValue.ModuleAttribute.BusinessType == "JsonValue") { jObject.Add(testStepValue.Name, testStepValue.Value); } else if (testStepValue.ModuleAttribute.BusinessType == "JsonObject") { JObject nestedObject = new JObject(); nestedObject = ConstructJsonStructure(testStepValue, nestedObject); jObject.Add(testStepValue.Name, nestedObject); } else if (testStepValue.ModuleAttribute.BusinessType == "JsonArray") { JArray arrayAttributes = new JArray(); JObject arrayObject = new JObject(); arrayObject = ConstructJsonStructure(testStepValue, arrayObject); arrayAttributes.Add(arrayObject.Values()); jObject.Add(testStepValue.Name, arrayAttributes); } } } catch (Exception ex) { FileLogger.Instance.Error(ex.Message); } return(jObject); }
private XTestStepValue GetOrCreateApiXTestStepValue(XTestStep apiTestStep, KeyValuePair <string, string> wseTestStepValue) { XTestStepValue apiTeststepValue = (XTestStepValue)apiTestStep .Search(string.Format(TqlToGetApiTestStepValue, wseTestStepValue.Key)) .FirstOrDefault(); //if xTestStepValue not present,create it. if (apiTeststepValue == null) { //check if module attribute is present. var xModuleAttribute = (XModuleAttribute)apiTestStep .Module.Search( string.Format(TqlToGetModuleAttributeInApiModule, wseTestStepValue.Key)).FirstOrDefault(); //if not present, Create it. if (xModuleAttribute == null) { XModuleAttribute m = CreateModuleAttribute(apiTestStep.Module as ApiModule, wseTestStepValue); apiTeststepValue = apiTestStep.CreateXTestStepValue(m); } //if already present, use it. else { apiTeststepValue = apiTestStep.CreateXTestStepValue(xModuleAttribute); } } return(apiTeststepValue); }
static void Main(string[] args) { using (TCAPI tcapi = TCAPI.CreateInstance()) { TCWorkspace workspace = tcapi.OpenWorkspace(@"C:\Users\estan\Desktop\trainings\TOSCA Customizations\Tosca Workspace\Training Customizations\Training Customizations.tws", "Admin", ""); TCProject project = workspace.GetProject(); List <TCObject> result = project.Search($"=>SUBPARTS:TCFolder[UniqueId==\"{unique_id_test_case_folder}\"]"); TCFolder testCaseFolder = (TCFolder)result.First(); testCaseFolder.Checkout(); TestCase testCase = testCaseFolder.CreateTestCase(); testCase.Name = "Test Creating Test Case"; XModule tboxSetBuffer = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_set_buffer}\"]").First(); XModule tboxWait = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_wait}\"]").First(); XTestStep setBufferTestStep = testCase.CreateXTestStepFromXModule(tboxSetBuffer); XTestStepValue setBUfferStepvalue = setBufferTestStep.CreateXTestStepValue(tboxSetBuffer.Attributes.First()); setBUfferStepvalue.Name = "Test Buffer Creation"; setBUfferStepvalue.Value = "42"; setBUfferStepvalue.ActionMode = XTestStepActionMode.Input; XTestStep tboxSetWaitTimeStep = testCase.CreateXTestStepFromXModule(tboxWait); XTestStepValue tboxWaitSettimeStepValue = tboxSetWaitTimeStep.TestStepValues.First(); tboxWaitSettimeStepValue.Value = "500"; } }
/// <summary> /// Parses WSE XTestStep to get payload /// </summary> /// <param name="xTestStep">WSE XTestStep</param> /// <param name="tql">tql to get root json object from request/reponse object</param> /// <returns>payload</returns> public string Parse(XTestStep xTestStep, string tql = "") { try { if (xTestStep == null) { return(string.Empty); } XTestStepValue jsonObject = xTestStep.Search(tql).Cast <XTestStepValue>().FirstOrDefault( x => x.ModuleAttribute.BusinessType == "JsonObject" || x.ModuleAttribute.BusinessType == "JsonArray"); if (jsonObject != null) { JArray arrayObject = new JArray(); JObject plainObject = CommonUtilities.ConstructJsonStructure(jsonObject, new JObject()); if (jsonObject.ModuleAttribute.BusinessType == "JsonObject") { return(Convert.ToString(plainObject)); } arrayObject.Add(plainObject.Values()); return(Convert.ToString(arrayObject)); } } catch (Exception e) { FileLogger.Instance.Error( $"Failed to create Json payload for request :{xTestStep?.Name}", e); } return(string.Empty); }
/// <summary> /// Fills XML payload using recursive call to method /// </summary> /// <param name="tcObjects">XML payload testStepValues</param> /// <param name="apiTestStep">apiTestStep</param> /// <param name="wseTestStep">wseTestStep</param> /// <param name="xPath">xpTah</param> /// <param name="parent">xModule and xModuleAttribute of API</param> /// <param name="parentTest">XTestStep and xTestStepValue of ApiTesstep</param> public virtual void FillPayloadInternal(IEnumerable <XTestStepValue> tcObjects, XTestStep apiTestStep, XTestStep wseTestStep, string xPath, dynamic parent, dynamic parentTest) { XTestStepValue wseTestStepValue = null; string tXpathFormat = "/*[local-name()='{0}']"; if (!tcObjects.Any()) { return; } var firstObject = tcObjects.First(); var lastObject = tcObjects.Last(); foreach (var tcObject in tcObjects.Where(x => x.ModuleAttribute.BusinessType == "XmlElement")) { bool isArray = false; try { wseTestStepValue = tcObject; string currXpath; if (firstObject.Name == lastObject.Name && !ReferenceEquals(firstObject, lastObject)) { currXpath = xPath + string.Format(tXpathFormat, wseTestStepValue.Name); isArray = true; } else { currXpath = xPath + string.Format(tXpathFormat, wseTestStepValue.Name); } XTestStepValue apiTestStepValue = CreateModuleAttributeForPayload(wseTestStepValue, currXpath, parent, (ApiModule)apiTestStep.Module, parentTest, wseTestStepValue .ModuleAttribute ?.Cardinality, isArray ); FillPayloadInternal(tcObject.SubValues, apiTestStep, wseTestStep, currXpath, apiTestStepValue.ModuleAttribute, apiTestStepValue); } catch (Exception ex) { FileLogger.Instance.Error( $"Error occurred while creating Business Parameter for WSE TestStep : 'Name: {wseTestStep?.Name}' NodePath:'{wseTestStep?.NodePath}' TestStepValue:'{wseTestStepValue?.Name}' Exception:'{ex.ToString()}'"); } } }
/// <summary> /// Evaluates Json path of wseteststep values. /// </summary> /// <param name="wseTestStep">parent node of wseteststep</param> /// <param name="wseTestStepValue">node for which json path is to be evaluated</param> /// <param name="jsonPath">reform json path for static or dynamic payload</param> /// <returns></returns> public virtual string GetJsonPath(XTestStep wseTestStep, XTestStepValue wseTestStepValue, string jsonPath) { TCObject rootObject = wseTestStep .Search("=>SUBPARTS:XTestStepValue[Name==\"Response\"]->SUBPARTS") .FirstOrDefault(); var rootObjectNodePath = rootObject?.NodePath; return(ExtractToscaJsonPath(rootObjectNodePath, wseTestStepValue, jsonPath)); }
CreateModuleAttribute(ApiModule apiModule, XTestStepValue wseTestStepValue) { return(apiModule.CreateModuleAttribute( "StatusCode", HttpStatusCodeExtension.ValueRange(), wseTestStepValue.ModuleAttribute.DefaultValue, "StatusCode", "StatusCode", wseTestStepValue.ModuleAttribute.DefaultActionMode, wseTestStepValue.ModuleAttribute.DefaultDataType)); }
CreateModuleAttribute(ApiModule apiModule, XTestStepValue wseTestStepValue) { return(apiModule.CreateModuleAttribute( "Endpoint", GetRefinedWseTestStepValue(wseTestStepValue.Value), GetRefinedWseTestStepValue(wseTestStepValue.Value), "Endpoint", "Endpoint", wseTestStepValue.ModuleAttribute.DefaultActionMode, wseTestStepValue.ModuleAttribute.DefaultDataType)); }
private static void SetConstraintIndexProperty(XTestStepValue wseTestStepValue, XTestStepValue testStepValue) { string constraintIndex = wseTestStepValue.RelevantXParams.FirstOrDefault(x => x.Name == "ConstraintIndex")?.Value; if (!StringExtensions.IsNullOrBlankInTosca(constraintIndex)) { testStepValue.ActionProperty = $"Index"; testStepValue.Operator = Operator.Equals; testStepValue.Value = constraintIndex; } }
private string Parse(XTestStepValue root) { string payload = string.Empty; if (root == null) { return(payload); } XElement xmlStructure = XmlHelper.ConstructXmlStructure(root); xmlStructure = XmlHelper.RemoveNodeFromXml(xmlStructure, "Fault", "Body"); payload = Convert.ToString(xmlStructure); return(payload); }
//Implement this for header private static void UpdateValueRange(XTestStepValue apiTeststepValue, string wseValue) { if (!String.IsNullOrEmpty(wseValue) && !apiTeststepValue.ModuleAttribute.ValueRange.Contains(wseValue)) { if (!string.IsNullOrEmpty(apiTeststepValue.ModuleAttribute.ValueRange)) { apiTeststepValue.ModuleAttribute.ValueRange = $"{apiTeststepValue.ModuleAttribute.ValueRange};{Regex.Replace(wseValue, ";", @"\;")}"; } else { apiTeststepValue.ModuleAttribute.ValueRange = Regex.Replace(wseValue, ";", @"\;"); } } }
CreateModuleAttribute(ApiModule apiModule, XTestStepValue wseTestStepValue) { return(apiModule.CreateModuleAttribute( "Method", HttpMethodExtension.ValueRangeString(), wseTestStepValue .ModuleAttribute.DefaultValue, "Method", "Method", wseTestStepValue .ModuleAttribute .DefaultActionMode, wseTestStepValue .ModuleAttribute .DefaultDataType)); }
/// <summary> /// Creates module attributes for payload /// </summary> /// <param name="wseTestStepValue">TestStepValues of WSE Teststep</param> /// <param name="xpath">XPath and JsonPath for xml</param> /// <param name="parent">xModule and xModuleAttribute of ApiEngine</param> /// <param name="apiModule">ApiModule</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 XtestTestValue of API</returns> public XTestStepValue CreateModuleAttributeForPayload(XTestStepValue wseTestStepValue, string xpath, dynamic parent, ApiModule apiModule, dynamic parentTest, string cardinality, bool isArray = false) { return(BusinessParameterHandler.CreateBusinessParameterInTosca(wseTestStepValue, xpath, parent, apiModule, BusinessParameterPathTypes.XPATH, parentTest, cardinality, isArray)); }
/// <summary> /// Extracts method from WSE TestStep /// </summary> /// <param name="xTestStep">WSE TestStep</param> /// <returns>HTTP Method</returns> public string Parse(XTestStep xTestStep) { try { XTestStepValue method = (XTestStepValue)xTestStep.Search(AddOnConstants.TestStepMethodTql).FirstOrDefault(); if (method == null) { return(string.Empty); } return(method.Value); } catch (Exception ex) { FileLogger.Instance.Error(ex); } return(string.Empty); }
/// <summary> /// Updates Value range of api module /// </summary> /// <param name="apiTeststepValue">value range to update in module attribute of apiTeststepValue</param> /// <param name="apiValue">value to set in Value range</param> /// <param name="wseValue">value to set in Value range in case of header</param> protected override void UpdateValueRange(XTestStepValue apiTeststepValue, string apiValue, string wseValue) { if (String.IsNullOrEmpty(apiTeststepValue.ModuleAttribute.ValueRange)) { if (!String.IsNullOrEmpty(apiValue)) { apiTeststepValue.ModuleAttribute.ValueRange = Regex.Replace(apiValue, ";", @"\;"); apiTeststepValue.ModuleAttribute.DefaultValue = Regex.Replace(apiValue, ";", @"\;"); } UpdateValueRange(apiTeststepValue, wseValue); } else { UpdateValueRange(apiTeststepValue, wseValue); } }
/// <summary> /// Creates Xml structure from Wse XTestStepValue for API Modules Payload section /// </summary> /// <param name="xTestStepValue">Wse XTestStepValues</param> /// <param name="xmlStructure">XElement used to create Payload Structure</param> /// <param name="parent">XElement used to identify and create parent nodes in xml structure </param> /// <returns>xml structure for API Modules Payload Section</returns> public static XElement ConstructXmlStructure(XTestStepValue xTestStepValue, XElement xmlStructure = null, XElement parent = null) { XNamespace xNamespace = GetNamespace(xTestStepValue.ModuleAttribute); List <XAttribute> xAttribute = GetXAttribute(xTestStepValue.ModuleAttribute); if (xmlStructure == null) { xmlStructure = new XElement(xNamespace != null ? xNamespace + xTestStepValue.Name : xTestStepValue.Name, xAttribute, xTestStepValue.Value == "{NULL}" ? "" : xTestStepValue.Value); parent = xmlStructure; } else if (xmlStructure == parent) { parent = new XElement( xNamespace != null ? xNamespace + xTestStepValue.Name : xTestStepValue.Name, xAttribute, xTestStepValue.Value == "{NULL}" ? "" : xTestStepValue.Value); xmlStructure.Add(parent); } else { var e = new XElement( xNamespace != null ? xNamespace + xTestStepValue.Name : xTestStepValue.Name, xAttribute, xTestStepValue.Value == "{NULL}" ? "" : xTestStepValue.Value); parent?.Add(e); parent = e; } var childSubAttributes = xTestStepValue.SubValues; foreach (var childSubAttribute in childSubAttributes.Where( x => x.ModuleAttribute.BusinessType == "XmlElement")) { xmlStructure = ConstructXmlStructure(childSubAttribute, xmlStructure, parent); } return(xmlStructure); }
public void Execute(XTestStep apiTestStep, XTestStep wseTestStep) { try { Dictionary <string, string> testStepKeyValueList = GetWseTestStepValueAsKeyValPair(wseTestStep); if (!testStepKeyValueList.Any()) { return; } foreach (var wseTestStepValue in testStepKeyValueList) { //Extract value need to be filled in api test step string wseValue = wseTestStepValue.Value; string apiValue = String.Empty; //Note: we ignore this step in case of response. if (!IsResponseTestStepValue) { //get api value apiValue = GetValueInApiModule(apiTestStep.Module as ApiModule, wseTestStepValue.Key); //if values match,do nothing. if (!Regex.IsMatch(wseValue, @"\{.*\}") && apiValue == CommonUtilities.RemoveExtraDoubleQuotes(wseValue)) { return; } } //if values does not match , Search if there is already a API xTestStepValue present. XTestStepValue apiTeststepValue = GetOrCreateApiXTestStepValue(apiTestStep, wseTestStepValue); //API xTestStepValue is present now. Assign Values to it now. UpdateValueRange(apiTeststepValue, apiValue, wseValue); apiTeststepValue.Value = wseTestStepValue.Value; apiTeststepValue.ActionMode = IsResponseTestStepValue ? XTestStepActionMode.Verify : XTestStepActionMode.Insert; } } catch (Exception e) { FileLogger.Instance.Error("Multiple value setter failed", e); } }
/// <summary> /// Gets Response Status Code from WSE TestStep /// </summary> /// <param name="xTestStep">WSE TestStep</param> /// <returns>Status code</returns> public string ParseResponseStatus(XTestStep xTestStep) { try { TCObject statusCodeModuleAttribute = xTestStep.Search(AddOnConstants.TestStepResponseStatusTql) .FirstOrDefault(); if (statusCodeModuleAttribute == null) { return(string.Empty); } XTestStepValue statusCodeXModuleAttribute = statusCodeModuleAttribute as XTestStepValue; return(statusCodeXModuleAttribute?.Value); } catch (Exception ex) { FileLogger.Instance.Error("Failed to retrieve response Status Code :", ex); } return(string.Empty); }
private XTestStepValue CreateModuleAttributeForPayload(XTestStepValue wseTestStepValue, string jsonPath, dynamic parent, ApiModule apiModule, dynamic parentTest, string cardinality, bool isArray = false) { if (jsonPath.StartsWith(".")) { jsonPath = jsonPath.Remove(0, 1); } return(BusinessParameterHandler.CreateBusinessParameterInTosca(wseTestStepValue, jsonPath, parent, apiModule, BusinessParameterPathTypes.JSONPATH, parentTest, cardinality, isArray)); }
/// <summary> /// Returns Json path supported by Tosca for every field of payload from nodepath. /// </summary> /// <param name="rootObjectNodePath"> node path of root/main object</param> /// <param name="wseTestStepValue">test step value for which json path is to be evaluated</param> /// <param name="jsonPath">raw json path</param> /// <returns></returns> public string ExtractToscaJsonPath(string rootObjectNodePath, XTestStepValue wseTestStepValue, string jsonPath) { string nodePath = wseTestStepValue.NodePath; nodePath = nodePath.Replace(wseTestStepValue.ParentValue.NodePath, string.Empty); var name = wseTestStepValue.RelevantXParams.FirstOrDefault(x => x.Name == "Name"); if (name?.Value != null && name.Value.EndsWith("*")) { nodePath = Regex.Replace(nodePath, @"/item#(\d*)$", Evaluator); } else { nodePath = Regex.Replace(nodePath, @"/item#(\d*)$", Evaluator2); } jsonPath = Regex.Replace(jsonPath, @"\[[\d | ""*""]*\]$", nodePath); return(jsonPath); }
/// <summary> /// Get Endpoint, Resource and Query Params from WSE XTestStep /// </summary> /// <param name="xTestStep"></param> /// <returns>AddressParserResult object which contains Endpoint, Resource and Query Params</returns> public AddressParserResult Parse(XTestStep xTestStep) { var addressParserResult = new AddressParserResult(); try { XTestStepValue address = (XTestStepValue) xTestStep.Search(AddOnConstants.TestStepAddressValueTql).FirstOrDefault(); if (address == null) { return(addressParserResult); } if (string.IsNullOrEmpty(address.Value)) { return(addressParserResult); } ParseAddressInternal(addressParserResult, address.Value); } catch (Exception ex) { FileLogger.Instance.Error(ex); } return(addressParserResult); }
/// <summary> /// Gets headers from WSE XTestStep /// </summary> /// <param name="xTestStep">WSE XTestStep</param> /// <param name="tql">tql to get Header XTestStepValue from WSE XTestStep</param> /// <returns>All headers as a dictionary</returns> public Dictionary <string, string> Parse(XTestStep xTestStep, string tql) { var headersDict = new Dictionary <string, string>(); try { List <TCObject> headers = xTestStep.Search(tql); foreach (TCObject header in headers) { XTestStepValue headerAttribute = (XTestStepValue)header; if (string.IsNullOrEmpty(headerAttribute.Value)) { continue; } headersDict.Add(headerAttribute.Name, CommonUtilities.RemoveExtraDoubleQuotes(headerAttribute.Value)); } } catch (Exception) { // do nothing as this could happen possibly, just move on with the other attributes } return(headersDict); }
public void CreateTestStepFromSET(string setName, Dictionary <string, TestStepValueData> testStepValues) { TestStepFolder testStepFolder = parentObject as TestStepFolder; if (testStepFolder == null) { throw new NullReferenceException("CurrentFolder is not set"); } string query = "->PROJECT->AllOwnedSubItems=>SUBPARTS:XModule[SetWizard ==\"" + setName + "\"]"; TCObject tcObject = testStepFolder.Search(query)[0]; XModule xModule = tcObject as XModule; if (xModule == null) { return; } XTestStep testStep = testStepFolder.CreateXTestStepFromXModule(xModule); foreach (KeyValuePair <string, TestStepValueData> testStepValuePair in testStepValues) { foreach (XModuleAttribute xModuleAttribute in xModule.Attributes) { if (xModuleAttribute.Name != testStepValuePair.Key) { continue; } XTestStepValue testStepValue = testStep.CreateXTestStepValue(xModuleAttribute); TestStepValueData testStepValueData = testStepValuePair.Value; testStepValue.Value = testStepValueData.Value; testStepValue.ActionMode = ConvertActionMode(testStepValueData.ActionMode); } } }
public void Execute(XTestStep apiTestStep, XTestStep wseTestStep) { try { //Get Raw Value XTestStepValue wseTestStepValue = (XTestStepValue)wseTestStep.Search(TqlToGetWseTestStepValue).FirstOrDefault(); if (wseTestStepValue == null) { return; } //Extract value need to be filled in api test step string wseValue = GetRefinedWseTestStepValue(wseTestStepValue.Value); //Note: we ignore this step in case of response. if (!IsResponseTestStepValue) { //get api value string apiValue = GetValueInApiModule(apiTestStep.Module as ApiModule); //if values match,do nothing. if (!Regex.IsMatch(wseValue, @"\{.*\}") && apiValue == wseValue) { return; } } //if values does not match , Search if there is already a API xTestStepValue present. XTestStepValue apiTeststepValue = (XTestStepValue)apiTestStep.Search(TqlToGetApiTestStepValue).FirstOrDefault(); //if xTestStepValue not present,create it. if (apiTeststepValue == null) { //check if module attribute is present. var xModuleAttribute = (XModuleAttribute)apiTestStep .Module.Search(TqlToGetModuleAttributeInApiModule).FirstOrDefault(); //if not present, Create it. if (xModuleAttribute == null) { XModuleAttribute m = CreateModuleAttribute(apiTestStep.Module as ApiModule, wseTestStepValue); apiTeststepValue = apiTestStep.CreateXTestStepValue(m); } //if already present, use it. else { apiTeststepValue = apiTestStep.CreateXTestStepValue(xModuleAttribute); } } //API xTestStepValue is present now. Assign Values to it now. apiTeststepValue.Disabled = wseTestStepValue.Disabled; apiTeststepValue.Value = wseValue; apiTeststepValue.ActionMode = wseTestStepValue.ActionMode; apiTeststepValue.Condition = wseTestStepValue.Condition; apiTeststepValue.Path = wseTestStepValue.Path; } catch (Exception e) { FileLogger.Instance.Error("Setting value failed : ", e); } }
public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext) { //ITestDataHandler testDataHandler = new TestDataHandler.ToscaTestDataHandler(objectToExecuteOn); //AssistantMain assistant = new AssistantMain(testDataHandler); //assistant.StartMainWindow(); //string toscahome = Path.GetFullPath(Environment.GetEnvironmentVariable("TRICENTIS_HOME")); System.Diagnostics.Process.Start("c:\\Temp\\ToscaAssistant.exe"); var currentTescase = objectToExecuteOn as TestCase; var folder = objectToExecuteOn as TCFolder; Thread.Sleep(5000); if (folder != null && folder.Name == "Modules") { XModule xModuleHome = folder.CreateXModule(); XModule xModuleManuals = folder.CreateXModule(); xModuleHome.Name = "Home"; xModuleManuals.Name = "Manuals"; return(null); } var query = "->PROJECT->AllOwnedSubItems=>SUBPARTS: XModule[SetWizard == \"File\"]"; XModule xModule = objectToExecuteOn.Search(query)[0] as XModule; var currentTestStep = currentTescase.CreateXTestStepFromXModule(xModule); foreach (var testValue in currentTestStep.TestStepValues) { if (testValue.Name == "Directory") { testValue.Value = "C:\\GIG"; } if (testValue.Name == "File") { testValue.Value = "createdFile.txt"; } if (testValue.Name == "Text") { testValue.Value = "Usability"; } } foreach (var attribute in xModule.Attributes) { if (attribute.Name == "Encoding") { XTestStepValue testStepValue = currentTestStep.CreateXTestStepValue(attribute); testStepValue.Value = "UTF-8"; } if (attribute.Name == "Overwrite") { XTestStepValue testStepValue = currentTestStep.CreateXTestStepValue(attribute); testStepValue.Value = "True"; } } return(null); }
protected override void UpdateValueRange(XTestStepValue apiTeststepValue, string apiValue, string wseValue) { }
/// <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); }
protected abstract XModuleAttribute CreateModuleAttribute(ApiModule apiModule, XTestStepValue wseTestStepValue);
public override string GetJsonPath(XTestStep wseTestStep, XTestStepValue wseTestStepValue, string jsonPath) { return(jsonPath); }
protected abstract void UpdateValueRange(XTestStepValue apiTeststepValue, string apiValue, string wseValue);