Exemplo n.º 1
0
        public bool ParseRespondToOutputParams()
        {
            if (Response != null)
            {
                mAct.AddOrUpdateReturnParamActual("Header: Status Code ", Response.StatusCode.ToString());
                Reporter.ToLog(eLogLevel.DEBUG, "Retrieve Response Status Code passed successfully");
                foreach (var Header in Response.Headers)
                {
                    string headerValues = string.Empty;
                    foreach (string val in Header.Value.ToArray())
                    {
                        headerValues = val + ",";
                    }
                    headerValues = headerValues.Remove(headerValues.Length - 1);
                    mAct.AddOrUpdateReturnParamActual("Header: " + Header.Key.ToString(), headerValues);
                }
                Reporter.ToLog(eLogLevel.DEBUG, "responseHeadersCollection passed successfully");
            }
            else
            {
                mAct.AddOrUpdateReturnParamActual("Respond", "Respond returned as null");
            }



            string prettyResponse = XMLDocExtended.PrettyXml(ResponseMessage);

            mAct.AddOrUpdateReturnParamActual("Response:", prettyResponse);

            if (!ActWebAPIBase.ParseNodesToReturnParams(mAct, ResponseMessage))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static string SaveToFile(string fileType, string fileContent, string saveDirectory, ActWebAPIBase mAct)
        {
            string extension   = string.Empty;
            string contentType = string.Empty;
            string actName     = string.Empty;

            if (fileType == "Request")
            {
                contentType = mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType);
            }
            else if (fileType == "Response")
            {
                contentType = mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType);
            }

            if (contentType == ApplicationAPIUtils.eContentType.XML.ToString())
            {
                extension = "xml";
            }
            else if (contentType == ApplicationAPIUtils.eContentType.JSon.ToString())
            {
                extension = "json";
            }
            else if (contentType == ApplicationAPIUtils.eContentType.PDF.ToString())
            {
                extension = "pdf";
            }
            else
            {
                extension = "txt";
            }

            string directoryFullPath = Path.Combine(saveDirectory.Replace("~//", WorkSpace.Instance.Solution.ContainingFolderFullPath), fileType + "s");

            if (!Directory.Exists(directoryFullPath))
            {
                Directory.CreateDirectory(directoryFullPath);
            }

            string fullFileName = "";

            lock (thisObj)
            {
                String timeStamp = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss");
                actName      = PathHelper.CleanInValidPathChars(mAct.Description);
                fullFileName = Path.Combine(directoryFullPath, actName + "_" + timeStamp + "_" + fileType + "." + extension);

                if (contentType != ApplicationAPIUtils.eContentType.PDF.ToString())
                {
                    File.WriteAllText(fullFileName, fileContent);
                }
                else
                {
                    byte[] bytes = Encoding.Default.GetBytes(fileContent);
                    File.WriteAllBytes(fullFileName, bytes);
                }
            }

            return(fullFileName);
        }
Exemplo n.º 3
0
 private void CopyExecutionAttributes(Act act, ActWebAPIBase actWebAPI)
 {
     act.Error  = actWebAPI.Error;
     act.ExInfo = actWebAPI.ExInfo;
 }
Exemplo n.º 4
0
        public override void RunAction(Act act)
        {
            //TODO: add func to Act + Enum for switch

            if (act is ActWebService)
            {
                mActWebService = (ActWebService)act;
                string     ReqXML       = String.Empty;
                FileStream ReqXMLStream = System.IO.File.OpenRead(mActWebService.XMLfileName.ValueForDriver.Replace(@"~\", mActWebService.SolutionFolder));
                using (StreamReader reader = new StreamReader(ReqXMLStream))
                {
                    ReqXML = reader.ReadToEnd();
                }

                string XMLwithValues = SetDynamicValues(mActWebService, ReqXML);
                int    timeOut       = string.IsNullOrEmpty(Convert.ToString(act.Timeout)) ? 350 : ((int)act.Timeout) * 1000;
                RunWebService(XMLwithValues, timeOut);
            }
            else if (act is ActSoapUI)
            {
                if (string.IsNullOrEmpty(SoapUIDirectoryPath))
                {
                    throw new Exception("SoapUI Directory Path has not been set to the Agent");
                }
                runSoapCommand(act);
            }
            else if (act is ActWebAPISoap || act is ActWebAPIRest)
            {
                mActWebAPI = (ActWebAPIBase)act;
                HandleWebApiRequest((ActWebAPIBase)act);
            }
            else if (act is ActWebAPIModel)
            {
                if (Reporter.CurrentAppLogLevel == eAppReporterLoggingLevel.Debug)
                {
                    Reporter.ToLog(eLogLevel.INFO, "Start Execution");
                }

                //pull pointed API Model
                ApplicationAPIModel AAMB = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ApplicationAPIModel>().Where(x => x.Guid == ((ActWebAPIModel)act).APImodelGUID).FirstOrDefault();
                if (AAMB == null)
                {
                    act.Error  = "Failed to find the pointed API Model";
                    act.ExInfo = string.Format("API Model with the GUID '{0}' was not found", ((ActWebAPIModel)act).APImodelGUID);
                    return;
                }

                //init matching real WebAPI Action
                ActWebAPIBase actWebAPI = null;
                if (AAMB.APIType == ApplicationAPIUtils.eWebApiType.REST)
                {
                    actWebAPI = CreateActWebAPIREST((ApplicationAPIModel)AAMB, (ActWebAPIModel)act);
                }
                else if (AAMB.APIType == ApplicationAPIUtils.eWebApiType.SOAP)
                {
                    actWebAPI = CreateActWebAPISOAP((ApplicationAPIModel)AAMB, (ActWebAPIModel)act);
                }

                if (Reporter.CurrentAppLogLevel == eAppReporterLoggingLevel.Debug)
                {
                    Reporter.ToLog(eLogLevel.INFO, "ActWebAPIBase created successfully");
                }

                //Execution
                mActWebAPI = actWebAPI;
                HandleWebApiRequest(actWebAPI);

                //Post Execution Copy execution result fields from actWebAPI to ActWebAPIModel (act)
                CopyExecutionAttributes(act, actWebAPI);
            }
            else if (act is ActScreenShot)
            {
            }
            else
            {
                throw new Exception("The Action from type '" + act.GetType().ToString() + "' is unknown/Not Implemented by the Driver - " + this.GetType().ToString());
            }
        }
        //private ObservableList<ActReturnValue> GetAPIModelActionReturnValues(ObservableList<ActReturnValue> modelReturnValues)
        //{
        //    ObservableList<ActReturnValue> returnValuesList = new ObservableList<ActReturnValue>();
        //    foreach (ActReturnValue modelRV in modelReturnValues)
        //    {
        //        ActReturnValue rv = new ActReturnValue();
        //        rv.AddedAutomatically = true;
        //        rv.Guid = modelRV.Guid;
        //        rv.Active = modelRV.Active;
        //        rv.Param = modelRV.Param;
        //        rv.Path = modelRV.Path;
        //        rv.Expected = modelRV.Expected;
        //        if (!string.IsNullOrEmpty(modelRV.StoreToValue))
        //        {
        //            rv.StoreTo = ActReturnValue.eStoreTo.ApplicationModelParameter;
        //            rv.StoreToValue = modelRV.StoreToValue;
        //        }
        //        returnValuesList.Add(rv);
        //    }
        //    return returnValuesList;
        //}


        /// <summary>
        /// This method is used to check if the app parameter is already added in the list if not then it will add the parameter
        /// </summary>
        /// <param name="aPIModel"></param>
        /// <param name="act"></param>
        /// <param name="actApiModel"></param>
        private Dictionary <System.Tuple <string, string>, List <string> > ParseParametersOptionalValues(ApplicationAPIModel aPIModel, ActWebAPIBase actionToConvert)
        {
            Dictionary <System.Tuple <string, string>, List <string> > optionalValuesPerParameterDict = new Dictionary <Tuple <string, string>, List <string> >();

            try
            {
                string requestBody = null;
                if (!string.IsNullOrEmpty(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.TemplateFileNameFileBrowser)))
                {
                    string fileUri = WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.TemplateFileNameFileBrowser));
                    if (File.Exists(fileUri))
                    {
                        requestBody = System.IO.File.ReadAllText(fileUri);
                    }
                }
                else if (!string.IsNullOrEmpty(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.RequestBody)))
                {
                    requestBody = actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.RequestBody);
                }

                if (requestBody != null)
                {
                    ImportParametersOptionalValues ImportOptionalValues = new ImportParametersOptionalValues();
                    if (!string.IsNullOrEmpty(requestBody) && requestBody.StartsWith("{"))
                    {
                        ImportOptionalValues.GetJSONAllOptionalValuesFromExamplesFile(requestBody, optionalValuesPerParameterDict);
                        ImportOptionalValues.PopulateJSONOptionalValuesForAPIParameters(aPIModel, optionalValuesPerParameterDict);
                    }
                    else if (!string.IsNullOrEmpty(requestBody) && requestBody.StartsWith("<"))
                    {
                        ImportOptionalValues.GetXMLAllOptionalValuesFromExamplesFile(requestBody, optionalValuesPerParameterDict);
                        ImportOptionalValues.PopulateXMLOptionalValuesForAPIParameters(aPIModel, optionalValuesPerParameterDict);
                    }
                }
                return(optionalValuesPerParameterDict);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Error occurred while parsing the app parameter", ex);
                return(optionalValuesPerParameterDict);
            }
        }