public void prepareDataFieldsTest() { TestingHelper_Accessor target = new TestingHelper_Accessor(); // TODO: Initialize to an appropriate value Dictionary<string, CoreDataField> dataFields = new Dictionary<string, CoreDataField>(); CoreDataField dataField = new CoreDataField(); target.currentProcess = new Process(); target.currentActivity = new Activity(); string keyToSet = "blah"; string assertValue = "AssertBlah"; dataField.Name = keyToSet; dataField.Check = "setToVariable"; dataField.Value = keyToSet; dataFields.Add(keyToSet, dataField); target.dataFieldDictionary[keyToSet] = assertValue; target.prepareDataFields(dataFields); Assert.AreEqual(dataFields[keyToSet].Value.ToString(), assertValue); }
private CoreDataField ConstructDataField(XmlNode datafieldNode) { CoreDataField dataField = new CoreDataField(); string strdatafieldType = XmlHelper.GetAttributeValue(datafieldNode, "type"); if (string.IsNullOrEmpty(strdatafieldType)) { strdatafieldType = Enum.GetName(typeof(CoreDataFieldType), CoreDataFieldType.Process); } CoreDataFieldType datafieldType = (CoreDataFieldType)Enum.Parse(typeof(CoreDataFieldType), strdatafieldType); dataField.Name = XmlHelper.GetAttributeValue(datafieldNode, "name", XmlHelper.NameCaseSensitive.No); dataField.Check = XmlHelper.GetAttributeValue(datafieldNode, "action", "set"); dataField.Type = datafieldType; dataField.Value = datafieldNode.InnerText; return dataField; }
private bool AssertValue(CoreDataField mockwfdf, string whatToCheck, CoreDataField df) { bool retVal = false; switch (whatToCheck) { case "ne": retVal = !(mockwfdf.Value.ToString().Equals(df.Value.ToString())); break; case "eq": retVal = mockwfdf.Value.ToString().Equals(df.Value.ToString()); break; default: throw new NotImplementedException(string.Format("whatToCheck was {0}, but I've only programmed 'ne' and 'eq' so far", whatToCheck)); break; } if (retVal) { SendResult(new TestResultArgs(currentProcess, currentActivity, TestResultStage.DebugMessage, string.Format("Assert passed: {0} {1} {2}: {3} {4} {5}'", currentProcess.ProcessName, currentActivity.Name, mockwfdf.Name, mockwfdf.Value, whatToCheck, df.Value))); } else { string err = string.Format("Assert failed: {0} {1} {2}: {3} {4} {5}'", currentProcess.ProcessName, currentActivity.Name, mockwfdf.Name, mockwfdf.Value, whatToCheck, df.Value); FailTest(err, TestResultStage.ActivityExecutionError, currentProcess, currentActivity); } return retVal; }
private void processDataFields(Process p, Activity a, out bool breakFromLoop) { bool needsUpdate = false; breakFromLoop = false; foreach (var df in a.DataFields) { string dfValue = null; int i = 0; while (dfValue == null) { dfValue = SmartObjectHelper.GetProcessDataFieldValue(K2Server, p.ProcessInstanceID, df.Key); System.Threading.Thread.Sleep(1000); i++; if (i > 10) { break; } } var mockDF = new CoreDataField(); mockDF.Name = df.Key; SendResult(new TestResultArgs(p,a, TestResultStage.DebugMessage, string.Format(new NullFormat(), "dfKey:{0} - dfvalue:{0}",df.Key, dfValue))); if (dfValue == null) { dfValue = "NULL"; } mockDF.Value = dfValue; processDataField(df.Value, null, mockDF, out needsUpdate, out breakFromLoop); } }
private void processDataField(CoreDataField dfToProcess, DataField wfdf, CoreDataField dfThatMocksWFDF, out bool needsUpdate, out bool breakFromLoop) { string checkText = dfToProcess.Check; needsUpdate = false; breakFromLoop = false; try { //Two modes, one setting and getting, one getting only, which does not need wfDataField if (checkText.Length == 0 || checkText.Equals("set")) { if (wfdf == null) { throw new WfdfNullReferenceException("Cannot set df in this mode"); } wfdf.Value = dfToProcess.Value; needsUpdate = true; } else if (checkText.StartsWith("check:", StringComparison.OrdinalIgnoreCase)) { string[] partsOfCheck = checkText.Split(new char[] { ':' }); string whatToCheck = partsOfCheck[1]; if (dfThatMocksWFDF == null) { throw new DddfNullReferenceException("cannot check df in this mode"); } if (!AssertValue(dfThatMocksWFDF, whatToCheck, dfToProcess)) { FailTest("Assert Failed", TestResultStage.ActivityExecutionError, currentProcess, currentActivity); breakFromLoop = true; } } else if (checkText.StartsWith("store:", StringComparison.OrdinalIgnoreCase)) { string[] partsOfCheck = checkText.Split(new char[] { ':' }); string keyToStoreAgainst = partsOfCheck[1]; //will add if it doesn't exist and overwrite if it does exist //I want this behaviour .... for now!!! Change to .Add() if you want to throw an error if it exists if (dfThatMocksWFDF == null) { throw new DddfNullReferenceException("Cannot store df in this mode"); } dataFieldDictionary[keyToStoreAgainst] = dfThatMocksWFDF.Value.ToString(); string debugMessage = String.Format("keyToStoreAgainst '{0}' set to value:{1}", keyToStoreAgainst, dfThatMocksWFDF.Value.ToString()); SendResult(new TestResultArgs(currentProcess, currentActivity, TestResultStage.DebugMessage, debugMessage) ); } else if (checkText.StartsWith("setToVariable", StringComparison.OrdinalIgnoreCase)) { if (!this.AutoActionTasks) { if (dataFieldDictionary.ContainsKey(dfToProcess.Value.ToString())) { if (wfdf == null) { throw new WfdfNullReferenceException("Cannot set df in this mode"); } wfdf.Value = dataFieldDictionary[dfToProcess.Value.ToString()]; string debugMessage = String.Format("wfdf.Value '{0}' dfdictkey: {1} set to value:{2}", wfdf.Value, dfToProcess.Name, dataFieldDictionary[dfToProcess.Value.ToString()]); SendResult(new TestResultArgs(currentProcess, currentActivity, TestResultStage.DebugMessage, debugMessage)); } else { string err = string.Format("Problem setting datafield. configured to set from temp variable, but temp variable name does not exist varName:{0} dfvalue:{1}", dfToProcess.Name, dfToProcess.Value); FailTest(err, TestResultStage.ActivityExecutionError, currentProcess, currentActivity); } } else { //Do not set Datafields in this mode. Allow the UI to do it. } } else { throw new NotImplementedException(string.Format("only catering for checking 'set', '', 'check:?', 'store:?' but got '{0}'", dfToProcess.Check)); } } catch (NullReferenceException ex) { string methodProperties = string.Format("mode: '{0}' p:{1}, a:{2}", checkText, currentProcess.ToString(), currentActivity.Name); if (ex is WfdfNullReferenceException) { throw new ArgumentException("cannot set workflow datafield in this activity mode " + methodProperties, ex); } else if (ex is DddfNullReferenceException) { throw new ArgumentException("cannot lookup workflow values in this activity mode" + methodProperties, ex); } else { throw ex; } } }