Skip to content

Commit

Permalink
add EditParameterPickWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
lulianqi committed Feb 2, 2019
1 parent 6dc8fea commit a504974
Show file tree
Hide file tree
Showing 74 changed files with 12,983 additions and 831 deletions.
8 changes: 8 additions & 0 deletions AutoTest/CsvFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,20 @@ private static void WriteCsvVeiw(List<List<string>> yourListCsvData, TextWriter
{
foreach(List<string> tempField in yourListCsvData)
{
if (tempField == null || tempField.Count==0)
{
continue;
}
WriteCsvLine(tempField, writer);
}
}

private static void WriteCsvLine(List<string> fields, TextWriter writer)
{
if (fields == null || fields.Count == 0)
{
return;
}
StringBuilder myStrBld = new StringBuilder();
//对于CSV数据来说不可能出现一行的数据元素的数量是0的情况,所以不用考虑fields.Count为0的情况(如果为0则为错误数据直接忽略)
//foreach(string tempField in fields) //使用foreach会产生许多不必要的string拷贝
Expand Down
16 changes: 15 additions & 1 deletion AutoTest/MyExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ public static Dictionary<string, TTargetValue> ToChangeType<TValue,TTargetValue>
}
return null;
}


public static void Add(this List<List<string>> myList, object[] yourValue)
{
if(yourValue!=null)
{
List<string> tempAddList = new List<string>(yourValue.Length);
for(int i =0 ; i<yourValue.Length;i++)
{
//tempAddList.Add((yourValue[i] is System.DBNull)?"":(string)yourValue[i]);
tempAddList.Add((yourValue[i] is string) ? (string)yourValue[i]:"");
}
myList.Add(tempAddList);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public static string GetCurrentParametersData(string yourSourceData, string spli
{
errorMessage = DealErrorAdditionData();
}

yourSourceData = yourSourceData.Replace(splitStr + tempKeyVaule + splitStr, tempVaule);
yourDataResultCollection.MyAdd(tempKeyVaule, tempVaule);
}
Expand Down
14 changes: 9 additions & 5 deletions AutoTest/ParameterizationPick/ParameterPick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

namespace FreeHttp.AutoTest.ParameterizationPick
{

[Serializable]
public class ParameterPick
{
public string ParameterName { get; set; }
public ParameterPickType PickType { get; set; }
public ParameterPickRange PickRange { get; set; }
public string PickTypeAdditional { get; set; }
public string PickTypeExpression { get; set; }
}
Expand All @@ -18,9 +22,9 @@ public class ParameterPickInfo
public ParameterPickType PickType{get;private set;}
public List<KeyValuePair<string, string>> PickTypeAdditionalList { get; private set; }
public bool Editable { get; private set; }
public Func<ParameterPick, string, string> ParameterPickFunc { get; private set; }
public Func<string,string, string, string> ParameterPickFunc { get; private set; }

public ParameterPickInfo(ParameterPickType pickType, List<KeyValuePair<string, string>> pickTypeAdditionalList, bool editable, Func<ParameterPick, string, string> parameterPickFunc)
public ParameterPickInfo(ParameterPickType pickType, List<KeyValuePair<string, string>> pickTypeAdditionalList, bool editable, Func<string,string, string, string> parameterPickFunc)
{
PickType = pickType;
PickTypeAdditionalList = pickTypeAdditionalList;
Expand All @@ -33,9 +37,9 @@ public ParameterPickInfo(ParameterPickType pickType, List<KeyValuePair<string, s
public class ParameterPickTypeEngine
{
public static Dictionary<ParameterPickType, ParameterPickInfo> dictionaryParameterPickFunc = new Dictionary<ParameterPickType, ParameterPickInfo>() {
{ParameterPickType.Str , new ParameterPickInfo(ParameterPickType.Str,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("str-str","StartString-EndString"),new KeyValuePair<string,string>("str-len","StartString-StringLength"),new KeyValuePair<string,string>("index-len","StartIndex-StringLength")},false,null)},
{ParameterPickType.Regex , new ParameterPickInfo(ParameterPickType.Regex,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("1","RegexExpression"),new KeyValuePair<string,string>("0","RegexExpression")},true,null)},
{ParameterPickType.Xml , new ParameterPickInfo(ParameterPickType.Xml,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("1","XpathExpression"),new KeyValuePair<string,string>("0","XpathExpression")},true,null)}
{ParameterPickType.Str , new ParameterPickInfo(ParameterPickType.Str,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("str-str","StartString-EndString"),new KeyValuePair<string,string>("str-len","StartString-StringLength"),new KeyValuePair<string,string>("index-len","StartIndex-StringLength")},false,ParameterPickHelper.ParameterPickStr)},
{ParameterPickType.Regex , new ParameterPickInfo(ParameterPickType.Regex,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("1","RegexExpression"),new KeyValuePair<string,string>("0","RegexExpression")},true,ParameterPickHelper.ParameterPickRegex)},
{ParameterPickType.Xml , new ParameterPickInfo(ParameterPickType.Xml,new List<KeyValuePair<string,string>>(){new KeyValuePair<string,string>("1","XpathExpression"),new KeyValuePair<string,string>("0","XpathExpression")},true,ParameterPickHelper.ParameterPickXml)}
};
}

Expand Down
203 changes: 192 additions & 11 deletions AutoTest/ParameterizationPick/ParameterPickHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;

Expand All @@ -24,11 +25,19 @@ public static string[] PickXmlParameter(string yourTarget, string yourSouce)
xml.LoadXml(yourSouce);

}
catch (Exception ex)
catch (Exception)
{
return null;
}
XmlNodeList tempNodeList;
try
{
tempNodeList = xml.SelectNodes("//" + yourTarget);
}
catch (Exception)
{
return null;
}
XmlNodeList tempNodeList = xml.SelectNodes("//" + yourTarget);
if (tempNodeList.Count > 0)
{
string[] backStrs = new string[tempNodeList.Count];
Expand All @@ -41,6 +50,29 @@ public static string[] PickXmlParameter(string yourTarget, string yourSouce)
return null;
}

public static string[] PickRegexParameter(string yourTarget, string yourSouce)
{
MatchCollection mc;
try
{
mc = Regex.Matches(yourSouce, yourTarget);
}
catch (Exception )
{
return null;
}
if (mc.Count > 0)
{
string[] backStrs = new string[mc.Count];
for (int i = 0; i < mc.Count; i++)
{
backStrs[i] = mc[i].Value;
}
return backStrs;
}
return null;
}

public static string PickStrParameter(int yourStrStart, int yourStrLen, string yourSouce)
{
if (yourStrStart < 0 || yourStrLen < 0)
Expand All @@ -54,13 +86,6 @@ public static string PickStrParameter(int yourStrStart, int yourStrLen, string y
return null;
}

/// <summary>
/// 查找指定字符串并截取指定长度
/// </summary>
/// <param name="yourTarget">匹配字符串</param>
/// <param name="yourStrLen">指定长度,如果为0则表示长度为取后面所有</param>
/// <param name="yourSouce">源数据</param>
/// <returns>结果,如果没有匹配到返回null</returns>
public static string PickStrParameter(string yourTarget, int yourStrLen, string yourSouce)
{
if (yourStrLen < 0)
Expand Down Expand Up @@ -100,8 +125,26 @@ public static string PickStrParameter(string yourTarget, string yourStrEnd, stri
}
return null;
}



public static bool GetStrPickData(string yourSouce, out string yourFrontTarget, out string yourBackStr)
{
yourFrontTarget = null;
yourBackStr = null;
if (yourSouce.Contains("-"))
{
yourFrontTarget = yourSouce.Remove(yourSouce.LastIndexOf("-"));
yourBackStr = yourSouce.Remove(0, yourSouce.LastIndexOf("-") + 1);
return true;
}
else
{
yourFrontTarget = yourSouce;
}
return false;
}

public static string CheckParameterPickExpression(ParameterPick yourParameterPick)
{
if (string.IsNullOrEmpty(yourParameterPick.PickTypeExpression))
Expand Down Expand Up @@ -158,19 +201,157 @@ public static string CheckParameterPickExpression(ParameterPick yourParameterPic
}
break;
case ParameterPickType.Str:
string frontStr;
string backStr;
if (!GetStrPickData(yourParameterPick.PickTypeExpression, out frontStr, out backStr))
{
return string.Format("this Expressions error :{0}", "it should contain '-'");
}
if (string.IsNullOrEmpty(frontStr) || string.IsNullOrEmpty(backStr))
{
return string.Format("this Expressions error :{0}", "the '-' position is illegal");
}
if (yourParameterPick.PickTypeAdditional == "str-str")
{

}
else if (yourParameterPick.PickTypeAdditional == "str-len")
{

if(!int.TryParse(backStr,out tempAdditionalIndex))
{
return string.Format("this Expressions error :{0}", "the len should be a int value");
}
}
else if (yourParameterPick.PickTypeAdditional == "index-len")
{
if (!int.TryParse(frontStr, out tempAdditionalIndex))
{
return string.Format("this Expressions error :{0}", "the index should be a int value");
}
if (!int.TryParse(backStr, out tempAdditionalIndex))
{
return string.Format("this Expressions error :{0}", "the len should be a int value");
}
}
break;
default:
return "unknow ParameterPickType";
}
return null;
}


public static string ParameterPickStr(string sourceStr,string pickExpression,string pickExpressionAdditional)
{
if (string.IsNullOrEmpty(sourceStr) || string.IsNullOrEmpty(pickExpression) || string.IsNullOrEmpty(pickExpressionAdditional))
{
throw new Exception("your ParameterPick data is null or empty");
}
string frontStr;
string backStr;
int frontIndex;
int strLen;
if (!GetStrPickData(pickExpression, out frontStr, out backStr))
{
throw new Exception( string.Format("this Expressions error :{0}", "it should contain '-'"));
}
if (string.IsNullOrEmpty(frontStr) || string.IsNullOrEmpty(backStr))
{
throw new Exception( string.Format("this Expressions error :{0}", "the '-' position is illegal"));
}
switch(pickExpressionAdditional)
{
case "str-str":
return PickStrParameter(frontStr, backStr, sourceStr);
case "str-len":
if(!int.TryParse(backStr,out strLen))
{
throw new Exception(string.Format("this Expressions error :{0}", "the len should be a int value"));
}
return PickStrParameter(frontStr, strLen, sourceStr);
case "index-len":
if (!int.TryParse(backStr, out strLen) )
{
throw new Exception(string.Format("this Expressions error :{0}", "the len should be a int value"));
}
if(!int.TryParse(frontStr, out frontIndex))
{
throw new Exception(string.Format("this Expressions error :{0}", "the index should be a int value"));
}
return PickStrParameter(frontIndex, strLen, sourceStr);
default:
throw new Exception("your ParameterPick data is null or empty");
}
}

public static string ParameterPickXml(string sourceStr, string pickExpression, string pickExpressionAdditional)
{
if (string.IsNullOrEmpty(sourceStr) || string.IsNullOrEmpty(pickExpression) || string.IsNullOrEmpty(pickExpressionAdditional))
{
throw new Exception("your ParameterPick data is null or empty");
}
int returnIndex;
if (!int.TryParse(pickExpressionAdditional, out returnIndex))
{
throw new Exception("this PickTypeAdditional should be a number");
}
if (returnIndex<0)
{
throw new Exception("this PickTypeAdditional should greater than 0");
}
string[] returnArray = PickXmlParameter(pickExpressionAdditional, sourceStr);
if (returnArray==null)
{
return null;
}
if (returnIndex==0)
{
return string.Join(",", returnArray);
}
else if (returnIndex > returnArray.Length)
{
return null;
}
else
{
return returnArray[returnIndex - 1];
}
}

public static string ParameterPickRegex(string sourceStr, string pickExpression, string pickExpressionAdditional)
{
{
if (string.IsNullOrEmpty(sourceStr) || string.IsNullOrEmpty(pickExpression) || string.IsNullOrEmpty(pickExpressionAdditional))
{
throw new Exception("your ParameterPick data is null or empty");
}
int returnIndex;
if (!int.TryParse(pickExpressionAdditional, out returnIndex))
{
throw new Exception("this PickTypeAdditional should be a number");
}
if (returnIndex < 0)
{
throw new Exception("this PickTypeAdditional should greater than 0");
}
string[] returnArray = PickRegexParameter(pickExpression, sourceStr);
if (returnArray == null)
{
return null;
}
if (returnIndex == 0)
{
return string.Join(",", returnArray);
}
else if (returnIndex > returnArray.Length)
{
return null;
}
else
{
return returnArray[returnIndex - 1];
}
}
}
}
}
10 changes: 10 additions & 0 deletions AutoTest/ParameterizationPick/ParameterPickType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@

namespace FreeHttp.AutoTest.ParameterizationPick
{

[Serializable]
public enum ParameterPickType
{
Str,
Xml,
Regex
}


[Serializable]
public enum ParameterPickRange
{
Line,
Heads,
Entity
}
}
Loading

0 comments on commit a504974

Please sign in to comment.