public void Dev2LanuageParser_ParseExpressionIntoParts_WhenMalformedRecordsetWithInvalidIndex_Expect2Errors() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); const string data = @"[[rec(&&,.a]]"; const string dl = "<DataList><rec><a/></rec></DataList>"; var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), string.Empty.ToStringBuilder(), dl.ToStringBuilder(), out errors); var bdl = compiler.FetchBinaryDataList(dlID, out errors); if(bdl != null) { var intillisenseParts = bdl.FetchIntellisenseParts(); //------------Execute Test--------------------------- // ReSharper disable once RedundantAssignment var parts = dev2LanuageParser.ParseExpressionIntoParts(data, intillisenseParts); parts = dev2LanuageParser.ParseExpressionIntoParts(data, intillisenseParts); //------------Assert Results------------------------- Assert.AreEqual(1, parts.Count); StringAssert.Contains(parts[0].Message, "Recordset name [[rec(&&,]] contains invalid character(s)"); } else { Assert.Fail(); } }
public override string ValidateName(string name) { var parser = new Dev2DataLanguageParser(); if (!string.IsNullOrEmpty(name)) { var fieldName = DataListUtil.ExtractFieldNameFromValue(name); var recName = DataListUtil.ExtractRecordsetNameFromValue(name); if (!string.IsNullOrEmpty(recName)) { ValidateName(parser, recName); } if (!string.IsNullOrEmpty(fieldName)) { name = ValidateName(name, parser, fieldName); } else { var intellisenseResult = parser.ValidateName(name, "Recordset field"); if (intellisenseResult != null) { SetError(intellisenseResult.Message); } } } return(name); }
public static List <string> SplitIntoRegionsForFindMissing(string result) { if (!String.IsNullOrEmpty(result)) { try { var allRegions = new List <string>(); Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); IList <ParseTO> makeParts = parser.MakeParts(result); foreach (var makePart in makeParts.Where(c => !c.HangingOpen)) { allRegions.Add(DataListUtil.AddBracketsToValueIfNotExist(makePart.Payload)); allRegions.AddRange(AddChildrenPartForFindMissing(makePart.Child)); } return(allRegions); } catch (Exception) { return(new List <string> { null }); } } return(new List <string> { null }); }
public void ExtractActualIntellisenseOptions_GivenValidArgs_ShouldExecuteCorrectly() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); var parseTO = new ParseTO { Parent = new ParseTO { Payload = "Name" } }; var parseTORecSet = new ParseTO { Parent = new ParseTO { Payload = "rec().Name" }, Payload = "rec().Name" }; var intellisenseParts = new List <IDev2DataLanguageIntellisensePart>(); var privateObject = new PrivateObject(parser); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { privateObject.Invoke("TryExtractActualIntellisenseOptions", parseTO, intellisenseParts, true); privateObject.Invoke("TryExtractActualIntellisenseOptions", parseTORecSet, intellisenseParts, false); } catch (Exception e) { //---------------Test Result ----------------------- Assert.Fail(e.Message); } }
public void ProcessRecordSetFields_GivenAddCompletePartsFalse_ShouldThrowValidException() { //---------------Set up test pack------------------- //ProcessRecordSetFields(ParseTO payload, bool addCompleteParts, IList<IIntellisenseResult> result, IDev2DataLanguageIntellisensePart t1) var parser = new Dev2DataLanguageParser(); var parseTO = new ParseTO { Parent = new ParseTO { Payload = "Name" }, }; var languageIntellisensePart = new Dev2DataLanguageIntellisensePart("Name", "Desc", new List <IDev2DataLanguageIntellisensePart>()); var results = new List <IIntellisenseResult>(); var privateObject = new PrivateObject(parser); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { privateObject.Invoke("ProcessRecordSetFields", parseTO, false, results, languageIntellisensePart); } catch (Exception e) { Assert.Fail(e.Message); } //---------------Test Result ----------------------- }
public void ParseExpressionIntoParts_GivenExpressionInCache_ShouldReturnFromCache() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); var concurrentDictionary = new ConcurrentDictionary <string, IList <IIntellisenseResult> >(); var tryAdd = concurrentDictionary.TryAdd("[[a]]", new List <IIntellisenseResult> { IntellisenseFactory.CreateErrorResult(1, 2, null, "", enIntellisenseErrorCode.FieldNotFound, false) }); Assert.IsTrue(tryAdd); var fieldInfo = typeof(Dev2DataLanguageParser).GetField("_expressionCache", BindingFlags.Static | BindingFlags.NonPublic); if (fieldInfo != null) { fieldInfo.SetValue(parser, concurrentDictionary); } //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var expressionIntoParts = parser.ParseExpressionIntoParts("[[a]]", new List <IDev2DataLanguageIntellisensePart>()); //---------------Test Result ----------------------- Assert.AreEqual(1, expressionIntoParts.Count); var error = expressionIntoParts.SingleOrDefault(result => !string.IsNullOrEmpty(result.Message)); Assert.IsNull(error); }
public void ProcessForOnlyOpenRegion_GivenValidationArgs_ShouldProcessCorrectly() { //---------------Set up test pack------------------- //ProcessForOnlyOpenRegion(ParseTO payload, IEnumerable<IDev2DataLanguageIntellisensePart> refParts, IList<IIntellisenseResult> result) var parser = new Dev2DataLanguageParser(); var privateObject = new PrivateObject(parser); var refParts = new List <IDev2DataLanguageIntellisensePart> { new Dev2DataLanguageIntellisensePart("Rec().Name", "rec", null) }; var result = new List <IIntellisenseResult>(); var parseTO = new ParseTO { Parent = new ParseTO { Payload = "rec().Name" } }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bool invoke; try { privateObject.Invoke("ProcessForOnlyOpenRegion", parseTO, refParts, result); invoke = true; } catch (Exception) { invoke = false; } //---------------Test Result ----------------------- Assert.IsTrue(invoke); }
public void ProcessForOnlyOpenRegion_GivenValidationArgsAndHasChildrenAndISRecordSet_ShouldProcessCorrectly() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); var privateObject = new PrivateObject(parser); var refParts = new List <IDev2DataLanguageIntellisensePart>(); var children = new List <IDev2DataLanguageIntellisensePart> { new Dev2DataLanguageIntellisensePart("name", "name", new List <IDev2DataLanguageIntellisensePart>()) }; refParts.Add(new Dev2DataLanguageIntellisensePart("Rec().Name", "rec", children)); var result = new List <IIntellisenseResult>(); var parseTO = new ParseTO { Parent = new ParseTO { Payload = "Name" }, }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bool invoke; try { privateObject.Invoke("ProcessForOnlyOpenRegion", parseTO, refParts, result); invoke = true; } catch (Exception) { invoke = false; } //---------------Test Result ----------------------- Assert.IsTrue(invoke, "Cannot invoke new Dev2DataLanguageParser PrivateObject."); }
public void Dev2DataLanguageParser_ParseWithCData() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); const string text = @"<![CDATA[[[]]]]>"; var parts = parser.ParseExpressionIntoParts(text, new List <IDev2DataLanguageIntellisensePart>()); Assert.AreEqual(1, parts.Count); Assert.AreEqual(parts[0].Type, enIntellisenseResultType.Error); Assert.AreEqual(parts[0].ErrorCode, enIntellisenseErrorCode.SyntaxError); Assert.AreEqual(parts[0].Message, ErrorResource.VariableIsMissing); const string textNoBrackets = @"Some text[["; parts = parser.ParseExpressionIntoParts(textNoBrackets, new List <IDev2DataLanguageIntellisensePart>()); Assert.AreEqual(1, parts.Count); Assert.AreEqual(parts[0].Type, enIntellisenseResultType.Error); Assert.AreEqual(parts[0].ErrorCode, enIntellisenseErrorCode.SyntaxError); Assert.AreEqual(parts[0].Message, ErrorResource.InvalidCloseRegion); const string textWithAuto = @"[[varName]]"; parts = parser.ParseExpressionIntoParts(textWithAuto, new List <IDev2DataLanguageIntellisensePart>()); Assert.AreEqual(1, parts.Count); Assert.AreEqual(enIntellisenseResultType.Error, parts[0].Type); Assert.AreEqual(enIntellisenseErrorCode.ScalarNotFound, parts[0].ErrorCode); Assert.AreEqual(" [[varName]] does not exist in your variable list", parts[0].Message); }
public override string ValidateName(string name) { var nameToCheck = name.Replace("@", ""); var isArray = name.EndsWith("()"); Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); if (!string.IsNullOrEmpty(nameToCheck)) { nameToCheck = DataListUtil.RemoveRecordsetBracketsFromValue(nameToCheck); if (!string.IsNullOrEmpty(nameToCheck)) { var intellisenseResult = parser.ValidateName(nameToCheck, "Complex Object"); if (intellisenseResult != null) { SetError(intellisenseResult.Message); } else { if (!string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateValue, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateVariable, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateRecordset, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageEmptyRecordSet, StringComparison.InvariantCulture)) { RemoveError(); } } } } if (isArray) { nameToCheck = nameToCheck + "()"; } return(nameToCheck); }
public override string ValidateName(string name) { Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); if (!string.IsNullOrEmpty(name)) { name = DataListUtil.RemoveRecordsetBracketsFromValue(name); if (!string.IsNullOrEmpty(name)) { var intellisenseResult = parser.ValidateName(name, "Recordset"); if (intellisenseResult != null) { SetError(intellisenseResult.Message); } else { if (!string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateValue, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateVariable, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateRecordset, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageEmptyRecordSet, StringComparison.InvariantCulture)) { RemoveError(); } } } } return(name); }
//2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result public static List <string> SplitIntoRegions(string result) { if (!String.IsNullOrEmpty(result)) { try { var allRegions = new List <string>(); Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); IList <ParseTO> makeParts = parser.MakeParts(result); foreach (var makePart in makeParts.Where(c => !c.HangingOpen)) { if (makePart.Child != null) { int indexOfBracket = makePart.Payload.IndexOf("(", StringComparison.Ordinal); string tmpresult = makePart.Payload.Insert(indexOfBracket + 1, DataListUtil.AddBracketsToValueIfNotExist(makePart.Child.Payload)); allRegions.Add(string.Concat("[[", tmpresult, "]]")); } else { allRegions.Add(string.Concat("[[", makePart.Payload, "]]")); } } return(allRegions); } catch (Exception) { return(new List <string> { null }); } } return(new List <string> { null }); }
//2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result public static List<string> SplitIntoRegions(string result) { if(!String.IsNullOrEmpty(result)) { try { var allRegions = new List<string>(); Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); IList<ParseTO> makeParts = parser.MakeParts(result); foreach(var makePart in makeParts.Where(c => !c.HangingOpen)) { if(makePart.Child != null) { int indexOfBracket = makePart.Payload.IndexOf("(", StringComparison.Ordinal); string tmpresult = makePart.Payload.Insert(indexOfBracket + 1, DataListUtil.AddBracketsToValueIfNotExist(makePart.Child.Payload)); allRegions.Add(string.Concat("[[", tmpresult, "]]")); } else { allRegions.Add(string.Concat("[[", makePart.Payload, "]]")); } } return allRegions; } catch(Exception) { return new List<string> { null }; } } return new List<string> { null }; }
public static List <string> FindAllLanguagePieces(string dataListRegion) { var allValidRegions = new List <string>(); if (!string.IsNullOrEmpty(dataListRegion)) { try { if (DataListUtil.IsEvaluated(dataListRegion)) { Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); var allParts = parser.MakeParts(dataListRegion); foreach (var part in allParts) { var parseTO = part.Child; while (parseTO != null) { AddPart(parseTO, allValidRegions); parseTO = parseTO.Child; } AddPart(part, allValidRegions); } } } catch (Exception) { //Do Something usefull like log Dev2Logger.Log.Info("Error parsing"); } } return(allValidRegions); }
private static void AddScalarOrRecset(string dataPartFieldData, Dev2DataLanguageParser dataLanguageParser, Dictionary <IDataListVerifyPart, string> unique, ref IDataListVerifyPart verifyPart, string[] fieldList, ref string fullyFormattedStringValue) { // If the workflow field is simply a scalar or a record set without a child if (dataPartFieldData.EndsWith(")") && dataPartFieldData == fieldList[0]) { if (dataPartFieldData.Contains("(")) { fullyFormattedStringValue = RemoveRecordSetBrace(fieldList[0]); var intellisenseResult = dataLanguageParser.ValidateName(fullyFormattedStringValue, ""); if (intellisenseResult == null) { verifyPart = IntellisenseFactory.CreateDataListValidationRecordsetPart(fullyFormattedStringValue, String.Empty); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } } else { var intellisenseResult = dataLanguageParser.ValidateName(dataPartFieldData, ""); if (intellisenseResult == null) { verifyPart = IntellisenseFactory.CreateDataListValidationScalarPart(RemoveRecordSetBrace(dataPartFieldData)); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_ErrorOnUnclosed() { var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName([[varName)]]", null, true, null, true); Assert.AreEqual(enIntellisenseErrorCode.SyntaxError, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Error, result[0].Type); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_NoFieldMatches() { const string dataList = @"<doc><recName1 Description=""RecName1 Description""><field1 Description=""field1 Desc"" /><field2 Description=""field2 Desc"" /></recName1><recName2 Description=""RecName2 Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName1.Name", dataList, false, null, true); Assert.AreEqual(0, result.Count); }
public override IActionableErrorInfo Check() { var value = GetValue(); if (string.IsNullOrEmpty(value)) { return(null); } var result = value.TryParseVariables(out _outputValue, DoError, LabelText, _variableValue, _inputs); if (result != null) { if (string.Equals(value, _outputValue)) { _outputValue = _variableValue; } return(result); } var parser = new Dev2DataLanguageParser(); var results = parser.ParseDataLanguageForIntellisense(value, _datalist); if (DataListUtil.IsEvaluated(value) && !DataListUtil.IsValueRecordset(value)) { var validRegions = Dev2.DataList.Contract.DataListCleaningUtils.SplitIntoRegions(value); foreach (var region in validRegions) { var intellisenseResult = parser.ValidateName(DataListUtil.RemoveLanguageBrackets(region), ""); if (intellisenseResult != null && intellisenseResult.Type == enIntellisenseResultType.Error) { results.Add(intellisenseResult); } } } var error = results.FirstOrDefault(r => r.Type == enIntellisenseResultType.Error); if (error != null) { if (string.Equals(value, _outputValue)) { _outputValue = _variableValue; } return(new ActionableErrorInfo(DoError) { ErrorType = ErrorType.Critical, Message = (string.IsNullOrEmpty(LabelText) ? "" : LabelText + " - ") + error.Message }); } return(null); }
public void ParseForActivityDataItems_GivenEmptyPayLoad_ShouldReturnCorreclty() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var forActivityDataItems = parser.ParseForActivityDataItems(""); //---------------Test Result ----------------------- Assert.AreEqual(0, forActivityDataItems.Count); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_TwoMatchingFields_AddCompleteParts() { const string dataList = @"<doc><recName1 Description=""RecName1 Description""><field1 Description=""field1 Desc"" /><field2 Description=""field2 Desc"" /></recName1><recName2 Description=""RecName2 Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName1", dataList, false); Assert.AreEqual(enIntellisenseErrorCode.None, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Selectable, result[0].Type); Assert.AreEqual("RecName1 Description", result[0].Message); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_EmptyClosed() { const string dataList = @"<doc><recName Description=""RecName Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[[[]]]]", dataList, false, null, false); Assert.AreEqual(enIntellisenseErrorCode.SyntaxError, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Error, result[0].Type); Assert.AreEqual("Variable [[]] is missing a name", result[0].Message); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_OneMatchNoParent2() { const string dataList = @"<doc><recName Description=""RecName Description""></recName></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName([[recName).field]]", dataList, false, null, true); Assert.AreEqual(enIntellisenseErrorCode.None, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Selectable, result[0].Type); Assert.AreEqual("RecName Description", result[0].Message); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_EmptyHangingOpen() { const string dataList = @"<doc><recName Description=""RecName Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[", dataList, false, null, false); Assert.AreEqual(enIntellisenseErrorCode.None, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Selectable, result[0].Type); Assert.AreEqual("RecName Description / Select this variable", result[0].Message); }
public void OnCreation_GivenNoErrors_ShouldConstructsCorreclty() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var newDev2DataLanguageParser = new Dev2DataLanguageParser(); //---------------Test Result ----------------------- Assert.IsNotNull(newDev2DataLanguageParser, "Cannot create new Dev2DataLanguageParser object."); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_NoFieldMatchInValidRecordset() { const string dataList = @"<doc><recName Description=""RecName Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName().field]]", dataList, false, null, true); // Note: studio does not allow recordsets with no fields Assert.AreEqual(enIntellisenseErrorCode.NeitherRecordsetNorFieldFound, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Error, result[0].Type); Assert.AreEqual("[[recName()]] does not exist in your variable list", result[0].Message); }
static bool IsJSonInputValid(string dataPartFieldData, Dev2DataLanguageParser dataLanguageParser) { var isValid = false; if (dataPartFieldData.Length < 1 || dataPartFieldData[0] != '@') { return(isValid); } var removeBrace = dataPartFieldData.Contains("()") ? dataPartFieldData.Replace("()", "") : RemoveRecordSetBrace(dataPartFieldData); var replaceAtSign = removeBrace.Replace("@", ""); var intellisenseResult = dataLanguageParser.ValidateName(string.IsNullOrEmpty(replaceAtSign) ? dataPartFieldData : replaceAtSign, ""); if (intellisenseResult == null) { isValid = true; } else { isValid = isValidObject(intellisenseResult); if (!isValid) { isValid = isValidParts(); } } return(isValid); bool isValidObject(IIntellisenseResult resultError) { var indexOfAtSign = dataPartFieldData.IndexOf("@", StringComparison.Ordinal); if (indexOfAtSign == 0 && (dataPartFieldData.Length >= 2) && char.IsLetter(dataPartFieldData[1]) && !resultError.Message.Contains("invalid char")) { return(true); } return(false); } bool isValidParts() { if (dataPartFieldData.Contains(".")) { var fields = dataPartFieldData.Substring(1).Split('.'); if (fields.All(p => !string.IsNullOrEmpty(p) && char.IsLetter(p[0]))) { return(true); } } return(false); } }
public void ParseDataLanguageForIntellisense_GivenInvalidDatalist_ShouldSwallowException() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); var datalist = "Invalid Datalist!!!"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var expressionIntoParts = parser.ParseDataLanguageForIntellisense("some value", datalist); //---------------Test Result ----------------------- Assert.AreEqual(0, expressionIntoParts.Count); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_BlankDescriptions() { const string dataList = @"<doc><recName1 Description=""""><field1 Description="""" /><field2 Description=""field2 Desc"" /></recName1><recName2 Description=""RecName2 Description"" /></doc>"; var parser = new Dev2DataLanguageParser(); var result = parser.ParseDataLanguageForIntellisense("[[recName1.field", dataList, false, null, true); Assert.AreEqual(enIntellisenseErrorCode.None, result[0].ErrorCode); Assert.AreEqual(enIntellisenseResultType.Selectable, result[0].Type); Assert.AreEqual(" Input: Use last row, Result: Append new record", result[0].Message); Assert.AreEqual(enIntellisenseResultType.Selectable, result[2].Type); Assert.AreEqual("field2 Desc", result[2].Message); }
public void ParseForActivityDataItems_GivenPayLoadWithTwoVariables_ShouldReturnCorreclty() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); const string datalist = "[[a]] and [[b]]"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var forActivityDataItems = parser.ParseForActivityDataItems(datalist); //---------------Test Result ----------------------- Assert.AreEqual(2, forActivityDataItems.Count); }
public void ParseDataLanguageForIntellisense_GivenEmpty_ShouldExecutesCorreclty() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); const string trueString = "True"; const string noneString = "None"; var datalist = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var expressionIntoParts = parser.ParseDataLanguageForIntellisense("", datalist); //---------------Test Result ----------------------- Assert.AreEqual(0, expressionIntoParts.Count); }
public IList <string> FormatDsfActivityField(string activityField) { IList <string> result = new List <string>(); var regions = DataListCleaningUtils.SplitIntoRegionsForFindMissing(activityField); foreach (var region in regions) { // Sashen: 09-10-2012 : Using the new parser var intellisenseParser = new SyntaxTreeBuilder(); var nodes = intellisenseParser.Build(region); // No point in continuing ;) if (nodes == null) { return(result); } if (intellisenseParser.EventLog.HasEventLogs) { var languageParser = new Dev2DataLanguageParser(); try { result = languageParser.ParseForActivityDataItems(region); } catch (Dev2DataLanguageParseError) { return(new List <string>()); } catch (NullReferenceException) { return(new List <string>()); } } var allNodes = new List <Node>(); result = FormatDsfActivityField(result, intellisenseParser, nodes, allNodes); } try { FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(activityField); } catch (Exception) { return(result.Where(lang => activityField.Contains("[[" + lang + "]]")).ToList()); } return(result); }
public void ParseExpressionIntoParts_GivenEmptyExpression_ShouldReturnEmptyParts() { //---------------Set up test pack------------------- var parser = new Dev2DataLanguageParser(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var expressionIntoParts = parser.ParseExpressionIntoParts("", new List <IDev2DataLanguageIntellisensePart>()); //---------------Test Result ----------------------- Assert.AreEqual(0, expressionIntoParts.Count); var error = expressionIntoParts.SingleOrDefault(result => !string.IsNullOrEmpty(result.Message)); Assert.IsNull(error); }
public void Dev2DataLanguageParser_ParseDataLanguageForIntellisense_DataListIsEmpty_NoIntellisenseResult() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseDataLanguageForIntellisense("", ""); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public void Dev2DataLanguageParser_ParseExpressionIntoParts_ExpressionIsEmpty_NoIntellisenseResult() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseExpressionIntoParts("", new List<IDev2DataLanguageIntellisensePart>()); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public void Dev2DataLanguageParser_MakeParts_PayloadIsNull_NoParts() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.MakeParts(null); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public void Dev2DataLanguageParser_MakePartsWithOutRecsetIndex_PayloadIsEmpty_NoParts() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.MakePartsWithOutRecsetIndex(""); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public static List<string> SplitIntoRegionsForFindMissing(string result) { if(!String.IsNullOrEmpty(result)) { try { var allRegions = new List<string>(); Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); IList<ParseTO> makeParts = parser.MakeParts(result); foreach(var makePart in makeParts.Where(c => !c.HangingOpen)) { allRegions.Add(DataListUtil.AddBracketsToValueIfNotExist(makePart.Payload)); allRegions.AddRange(AddChildrenPartForFindMissing(makePart.Child)); } return allRegions; } catch(Exception) { return new List<string> { null }; } } return new List<string> { null }; }
public static void BuildDataPart(string dataPartFieldData, Dictionary<IDataListVerifyPart, string> unique) { Dev2DataLanguageParser dataLanguageParser = new Dev2DataLanguageParser(); dataPartFieldData = DataListUtil.StripBracketsFromValue(dataPartFieldData); IDataListVerifyPart verifyPart; string fullyFormattedStringValue; string[] fieldList = dataPartFieldData.Split('.'); if (fieldList.Count() > 1 && !String.IsNullOrEmpty(fieldList[0])) { // If it's a RecordSet Containing a field bool recAdded = false; foreach (var item in fieldList) { if (item.EndsWith(")") && item == fieldList[0]) { if (item.Contains("(")) { fullyFormattedStringValue = RemoveRecordSetBrace(item); var intellisenseResult = dataLanguageParser.ValidateName(fullyFormattedStringValue, ""); if (intellisenseResult == null) { recAdded = true; verifyPart = IntellisenseFactory.CreateDataListValidationRecordsetPart(fullyFormattedStringValue, String.Empty); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } } else if (item == fieldList[1] && !(item.EndsWith(")") && item.Contains(")"))) { // If it's a field to a record set var intellisenseResult = dataLanguageParser.ValidateName(item, ""); if (intellisenseResult == null && recAdded) { verifyPart = IntellisenseFactory.CreateDataListValidationRecordsetPart( RemoveRecordSetBrace(fieldList.ElementAt(0)), item); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } else { break; } } } else if (fieldList.Count() == 1 && !String.IsNullOrEmpty(fieldList[0])) { // If the workflow field is simply a scalar or a record set without a child if (dataPartFieldData.EndsWith(")") && dataPartFieldData == fieldList[0]) { if (dataPartFieldData.Contains("(")) { fullyFormattedStringValue = RemoveRecordSetBrace(fieldList[0]); var intellisenseResult = dataLanguageParser.ValidateName(fullyFormattedStringValue, ""); if (intellisenseResult == null) { verifyPart = IntellisenseFactory.CreateDataListValidationRecordsetPart(fullyFormattedStringValue, String.Empty); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } } else { var intellisenseResult = dataLanguageParser.ValidateName(dataPartFieldData, ""); if (intellisenseResult == null) { verifyPart = IntellisenseFactory.CreateDataListValidationScalarPart(RemoveRecordSetBrace(dataPartFieldData)); AddDataVerifyPart(verifyPart, verifyPart.DisplayValue, unique); } } } }
public void Dev2LanuageParser_Wrap_ValidDoesNothing() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); ConcurrentDictionary<string, string> data = new ConcurrentDictionary<string, string> (); data.TryAdd("a", "b"); dev2LanuageParser.WrapAndClear(() => "bob", data); Assert.AreEqual(data.Count, 1); }
public void Dev2DataLanguageParser_ValidateName_NotLatinCharacter_ShowMessageBox_TextMadeEmpty() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); const string Text = "?????????"; //------------Execute Test--------------------------- var intellisenseResult = dev2LanuageParser.ValidateName(Text, ""); //------------Assert Results------------------------- Assert.IsNotNull(intellisenseResult); Assert.AreEqual(enIntellisenseErrorCode.SyntaxError, intellisenseResult.ErrorCode); }
public void Dev2LanuageParser_Parse_Valid_ExpectCache() { //------------Setup for test-------------------------- PrivateType p = new PrivateType(typeof(Dev2DataLanguageParser)); var cache = p.GetStaticField("_payloadCache") as ConcurrentDictionary<Tuple<string, string>, IList<IIntellisenseResult>>; if(cache != null) { cache.Clear(); } const string dl = "<ADL><rec><val/></rec></ADL>"; const string payload = "[[rec().val]]"; var dev2LanuageParser = new Dev2DataLanguageParser(); IList<IIntellisenseResult> results = ParseDataLanguageForIntellisense(payload, dl, true, false); Assert.IsNotNull(cache); Assert.AreEqual(cache.Count,1); //------------Execute Test--------------------------- //------------Assert Results------------------------- }
public void Dev2LanuageParser_Wrap_ExceptionClearsCache() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); ConcurrentDictionary<string, string> data = new ConcurrentDictionary<string, string> (); data.TryAdd("a", "b"); try { // ReSharper disable CSharpWarnings::CS0162 dev2LanuageParser.WrapAndClear(() => { throw new Exception(); }, data); // ReSharper restore CSharpWarnings::CS0162 Assert.Fail("y u no throw exception"); } catch(Exception) { Assert.AreEqual(data.Count,0); } }
public void Dev2LanuageParser_ParseExpressionIntoParts_WhenInValid_ExpectNoCache() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); PrivateType p = new PrivateType(typeof(Dev2DataLanguageParser)); var cache = p.GetStaticField("_payloadCache") as ConcurrentDictionary<Tuple<string, string>, IList<IIntellisenseResult>>; Assert.IsNotNull(cache); cache.Clear(); Assert.AreEqual(cache.Count, 0); const string data = @"[[rec(*123).a]]"; const string dl = "<DataList><rec><a/></rec></DataList>"; var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), string.Empty.ToStringBuilder(), dl.ToStringBuilder(), out errors); var bdl = compiler.FetchBinaryDataList(dlID, out errors); var intillisenseParts = bdl.FetchIntellisenseParts(); //------------Execute Test--------------------------- dev2LanuageParser.ParseExpressionIntoParts(data, intillisenseParts); //------------Assert Results------------------------- Assert.IsNotNull(cache); Assert.AreEqual(cache.Count, 0); }
/// <summary> /// Determines whether [name is valid]. /// </summary> /// <param name="name">The name.</param> /// <returns> /// <c>true</c> if [name is valid]; otherwise, <c>false</c>. /// </returns> public override string ValidateName(string name) { Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); if(!string.IsNullOrEmpty(name)) { if(IsRecordset) { name = DataListUtil.RemoveRecordsetBracketsFromValue(name); } else if(IsField) { name = DataListUtil.ExtractFieldNameFromValue(name); } if(!string.IsNullOrEmpty(name)) { var intellisenseResult = parser.ValidateName(name, IsRecordset ? "Recordset" : "Variable"); if(intellisenseResult != null) { SetError(intellisenseResult.Message); } else { if(!string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateValue, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateVariable, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageDuplicateRecordset, StringComparison.InvariantCulture) && !string.Equals(ErrorMessage, StringResources.ErrorMessageEmptyRecordSet, StringComparison.InvariantCulture)) { RemoveError(); } } } } return name; }
public void WhenIValidate() { IList<IIntellisenseResult> results = new List<IIntellisenseResult>(); var variable = ScenarioContext.Current.Get<string>("variable"); var parser = new Dev2DataLanguageParser(); IntellisenseFilterOpsTO filterTO = new IntellisenseFilterOpsTO { FilterType = enIntellisensePartType.All }; var datalist = new StringBuilder(); datalist.Append("<DataList>"); datalist.Append("<a>"); datalist.Append("</a>"); datalist.Append("<b>"); datalist.Append("</b>"); datalist.Append("<c>"); datalist.Append("</c>"); datalist.Append("<y>"); datalist.Append("</y>"); datalist.Append("<d>"); datalist.Append("</d>"); datalist.Append("<test>"); datalist.Append("</test>"); datalist.Append("<v>"); datalist.Append("</v>"); datalist.Append("<var>"); datalist.Append("</var>"); datalist.Append("<var1>"); datalist.Append("</var1>"); datalist.Append("<rec>"); datalist.Append("<a/>"); datalist.Append("<b/>"); datalist.Append("</rec>"); datalist.Append("<r>"); datalist.Append("<a/>"); datalist.Append("<b/>"); datalist.Append("</r>"); datalist.Append("</DataList>"); var dataList = datalist.ToString(); var tmpResults = parser.ParseDataLanguageForIntellisense(variable, dataList, true, filterTO, false); tmpResults.ToList().ForEach(r => { if(r.Type == enIntellisenseResultType.Error) { results.Add(r); } }); ScenarioContext.Current.Add("results", results); }
public void Dev2DataLanguageParser_ParseExpressionIntoParts_DataListPartsIsNull_NoIntellisenseResult() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseExpressionIntoParts("[[var]]", null); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public void Dev2LanuageParser_ParseExpressionIntoParts_WhenMissingVariable_Expect1Error() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); const string data = @"[[]]"; const string dl = "<DataList><rec><a/></rec></DataList>"; var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), string.Empty.ToStringBuilder(), dl.ToStringBuilder(), out errors); var bdl = compiler.FetchBinaryDataList(dlID, out errors); if(bdl != null) { var intillisenseParts = bdl.FetchIntellisenseParts(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseExpressionIntoParts(data, intillisenseParts); //------------Assert Results------------------------- Assert.AreEqual(1, parts.Count); StringAssert.Contains(parts[0].Message, "Variable [[]] is missing a name"); } else { Assert.Fail(); } }
public void Dev2DataLanguageParser_ParseForActivityDataItems_PayloadIsEmpty_NoDataListParts() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseForActivityDataItems(""); //------------Assert Results------------------------- Assert.AreEqual(0, parts.Count); }
public void Dev2LanuageParser_Parse_WhenCommaDelimited_ExpectThreeValidParts() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); const string data = @" [[rec().s]], [[rec().e]], [[rec().t]]"; //------------Execute Test--------------------------- var parts = dev2LanuageParser.ParseForActivityDataItems(data); //------------Assert Results------------------------- Assert.AreEqual(3, parts.Count); }
public void Dev2DataLanguageParser_ValidateName_NameIsEmpty_Null() { //------------Setup for test-------------------------- var dev2LanuageParser = new Dev2DataLanguageParser(); //------------Execute Test--------------------------- var res = dev2LanuageParser.ValidateName("", ""); //------------Assert Results------------------------- Assert.IsNull(res); }
public static List<string> FindAllLanguagePieces(string dataListRegion) { var allValidRegions = new List<string>(); if(!string.IsNullOrEmpty(dataListRegion)) { try { if(DataListUtil.IsEvaluated(dataListRegion)) { Dev2DataLanguageParser parser = new Dev2DataLanguageParser(); var allParts = parser.MakeParts(dataListRegion); foreach(var part in allParts) { var parseTO = part.Child; while(parseTO != null) { AddPart(parseTO, allValidRegions); parseTO = parseTO.Child; } AddPart(part, allValidRegions); } } } catch(Exception) { //Do Something usefull like log Dev2Logger.Log.Info("Error parsing"); } } return allValidRegions; }