コード例 #1
0
        public void ProcessWikiCommands(string[] wikiCommands, List<BreakPoint> breakPoints, System.Threading.Thread activeThread, CommandEditorPage currentPage, bool commandLineMode, List<CommandResult> listOfResults, string fileName)
        {
            bool inComment = false;
            string cleanedCommand = "";

            foreach (string wikiCommand in wikiCommands)
            {
                lineNumber++;
                Command mngrCommand = new Command(wikiCommand.TrimStart('|'));
                cleanedCommand = cleanCommand(wikiCommand);
                if (breakPoints.Count > 0)
                    CheckForBreakPointOnLine(breakPoints, lineNumber, activeThread, currentPage);

                CommandResult returnResult = new CommandResult();
                returnResult.FileName = fileName;
                returnResult.LineNumber = lineNumber;
                returnResult.FullCommand = mngrCommand.FullCommand;
                listOfResults.Add(returnResult);

                if (cleanedCommand.Equals(String.Empty))
                {
                    if (_finishBlockOnFailure)
                    {
                        TestManager.FinishBlockOnFailure = true;
                        _finishBlockOnFailure = false;
                    }
                    TestManager.ResetForNewTable(); 
                }


                if (!cleanedCommand.StartsWith("#") && !inComment && !cleanedCommand.StartsWith("{{{") && !cleanedCommand.StartsWith("}}}") && !isIgnoredCommand(cleanedCommand) && !TestManager.InCompareData)
                {

                    if (cleanedCommand.StartsWith("!"))
                    {
                        if (cleanedCommand.StartsWith("!define"))
                        {
                            try
                            {
                                cleanedCommand = replaceVar(cleanedCommand);
                            }
                            catch (SWATVariableDoesNotExistException e)
                            {
                                returnResult.Success = false;
                                mngrCommand.Passed = false;
                                returnResult.Message = e.Message;
                                returnResult.Command = "Could not be defined";
                                TestManager.LogCommand(mngrCommand);
                                goto Exit;
                            }

                            WikiVariable var = new WikiVariable(cleanedCommand);

                            if (!_variables.ContainsKey(var.Name))
                                _variables.Add(var.Name, var.Value);
                            else
                                _variables[var.Name] = var.Value;

                            returnResult.Success = true;
                            returnResult.Command = string.Format("Defined {0} as {1}", var.Name, var.Value);
                        }
                        if (cleanedCommand.StartsWith("!include"))
                        {
                            WikiInclude include = new WikiInclude(cleanedCommand);

                            try
                            {
                                string newFileName = SWAT.FitnesseSettings.FitnesseRootDirectory.TrimEnd('\\') + "\\" + include.FilePath + "content.txt";
                                string[] lines = File.ReadAllLines(newFileName);

                                //Need an intermediate slot in the results.
                                returnResult.Command = "INCLUDE";
                                returnResult.FullCommand = cleanedCommand;
                                returnResult.Success = true;
                                returnResult.Ignored = false;

                                ProcessWikiCommands(lines, breakPoints, activeThread, currentPage, commandLineMode, returnResult.Children, newFileName);
                            }
                            catch (DirectoryNotFoundException)
                            {
                                returnResult.Success = false;
                                returnResult.Ignored = false;
                                returnResult.Message = string.Format("Could not load macro at {0}", SWAT.FitnesseSettings.FitnesseRootDirectory.TrimEnd('\\') + "\\" + include.FilePath);
                                returnResult.Command = "INCLUDE";
                            }
                        }
                    }
                    else
                    {

                        //string[] sections = cleanedCommand.TrimStart('|').TrimEnd('|').Split('|');
                        // Remove leading pipes
                        cleanedCommand = cleanedCommand.TrimStart('|');
                        // Remove last pipe. Can't use TrimEnd('|') in case we are passing empty parameters
                        string[] sections = parseSections(cleanedCommand.Substring(0, cleanedCommand.LastIndexOf('|')));

                        StringCollection parameters = new StringCollection();

                        if (sections.Length < 1)
                        {
                            returnResult.Success = false;
                            returnResult.Message = "Command is not formated correctly.";
                            returnResult.Command = cleanedCommand;
                            goto Exit;

                        }
                        string command = sections[0];
                        returnResult.Command = command;

                        for (int i = 1; i < sections.Length; i++)
                        {
                            string replace = "";

                            try
                            {
                                replace = replaceVar(sections[i]);
                            }
                            catch (SWATVariableDoesNotExistException e)
                            {
                                parameters.Add(sections[i]);
                                var paramEntryex = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = sections[i] };
                                returnResult.Parameters.Add(paramEntryex);
                                returnResult.Success = false;
                                mngrCommand.Passed = false;
                                returnResult.Message = e.Message;
                                TestManager.LogCommand(mngrCommand);
                                goto Exit;
                            }

                            parameters.Add(replace);

                            var paramEntry = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = replace };
                            returnResult.Parameters.Add(paramEntry);
                        }

                        if (TestManager.ShouldExecute(mngrCommand))
                        {
                            try
                            {
                                string varKey = "";

                                if (command == "GetElementAttribute")
                                {
                                    varKey = parameters[3];
                                    parameters.RemoveAt(3);
                                }

                                if (command == "GetConfigurationItem")
                                {
                                    varKey = parameters[1];
                                    parameters.RemoveAt(1);
                                }

                                if (command.Contains("GetDbRecord") || command.Contains("GetDbDate") || command.Contains("GetLocation")
                                    || command.Contains("GetWindowTitle") || command.Contains("RunScriptSaveResult") || command.Contains("SetVariable")
                                    || command.StartsWith("GetSavedDbDate") || command == "GetTimerValue")
                                {
                                    varKey = parameters[0];
                                    parameters.RemoveAt(0);
                                }

                                if(command == "BeginCompareData")
                                {
                                    TestManager.InCompareData = true;
                                    _inCompareDataIndex = 0;
                                    TestManager.InCompareDataIsCritical = false;
                                }

                                InvokeResult result = _invokeManager.Invoke(command, parameters);

                                if (mngrCommand.IsInverse)
                                {
                                    returnResult.Success = !result.Success;
                                    mngrCommand.Passed = !result.Success;
                                }
                                else
                                {
                                    returnResult.Success = result.Success;
                                    mngrCommand.Passed = result.Success;
                                }

                                if (!mngrCommand.Passed && mngrCommand.FinishBlockOnFailure)
                                {
                                    _finishBlockOnFailure = true;
                                }

                                returnResult.Cond = wikiCommand.StartsWith("|?");

                                //Notify the user on success.
                                if (result.Success)
                                {
                                    //If original command failed, now passes with inverse modifier
                                    if (mngrCommand.IsInverse)
                                        returnResult.Message = "Inverse modifier failed passing command";
                                    else
                                        returnResult.Message = "Success";


                                    //C# Operator == is overloaded, so Equals() method is called when used. That is why it can be used to compare Strings.
                                    if ((command == "GetElementAttribute" || command.Contains("GetDbRecord") || command == "GetDbDate" || command == "GetLocation" || command == "GetConfigurationItem")
                                        || command == "GetWindowTitle" || command == "RunScriptSaveResult" || command == "SetVariable" || command.StartsWith("GetSavedDbDate") || command == "GetTimerValue")
                                    {
                                        if (_variables.ContainsKey(varKey.ToString()))
                                        {
                                            _variables.Remove(varKey);
                                        }

                                        _variables.Add(varKey, result.ReturnValue);
                                    }

                                    if (command == "DisplayVariable" || command == "DisplayTimerValue")
                                    {
                                        returnResult.Parameters[0].ReplacedParam = result.ReturnValue;
                                    }
                                }

                                if (!result.Success)
                                {
                                    if (mngrCommand.IsInverse)
                                        returnResult.Message = "Success - Inverse modifier passed failing command. Original error message: " + result.FailureMessage;
                                    else
                                        returnResult.Message = result.FailureMessage;
                                }

                            }
                            catch (Exception e)
                            {
                                returnResult.Success = false;
                                returnResult.Message = e.Message;
                                if (mngrCommand.Passed && mngrCommand.FinishBlockOnFailure)
                                {
                                    _finishBlockOnFailure = true;
                                }
                            }
                        }
                        else
                        {
                            returnResult.Ignored = true;
                            returnResult.ModIgn = true;
                        }

                        TestManager.LogCommand(mngrCommand);
                    }

                }
                else if (TestManager.InCompareData)
                {
                    cleanedCommand = cleanCommand(wikiCommand);
                    cleanedCommand = cleanedCommand.TrimStart('|');
                    string[] sections = parseSections(cleanedCommand.Substring(0, cleanedCommand.LastIndexOf('|')));

                    // 1. if endCompareData
                    if (wikiCommand.Contains("EndCompareData"))
                    {
                        returnResult.Command = "EndCompareData";
                        returnResult.Success = true;
                        mngrCommand.Passed = true;
                        returnResult.Message = "Success";
                        TestManager.LogCommand(mngrCommand);
                        TestManager.InCompareData = false;
                    }
                    else
                    {
                        //StringCollection rowParameters = new StringCollection();
                        for (int i = 0; i < sections.Length; i++)
                        {
                            string replace = "";
                            replace = replaceVar(sections[i]);
                            //rowParameters.Add(replace);
                            var paramEntry = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = replace };
                            returnResult.Parameters.Add(paramEntry);
                        }

                        // 2. if _inCompareDataIndex = 0 we are reading the columns
                        if (_inCompareDataIndex == 0)
                        {
                            _compareDatafieldNames = new List<string>();

                            for (int colIndex = 0; colIndex < returnResult.Parameters.Count; colIndex++)
                            {
                                _compareDatafieldNames.Add(returnResult.Parameters[colIndex].ReplacedParam);
                            }
                        }
                        // 3. otherwise we are now looking at actual row of data
                        else
                        {
                            for (int colIndex = 0; colIndex < _compareDatafieldNames.Count; colIndex++)
                            {
                                StringCollection parameters = new StringCollection();
                                int dataRowIndex = _inCompareDataIndex - 1;
                                parameters.Add(dataRowIndex.ToString());
                                parameters.Add(_compareDatafieldNames[colIndex]);
                                parameters.Add(returnResult.Parameters[colIndex].ReplacedParam);

                                InvokeResult result = _invokeManager.Invoke("AssertRecordValuesByColumnName", parameters);

                                if (!result.Success)
                                    returnResult.Message = result.FailureMessage;

                                returnResult.CompareDataResults.Add(result.Success.ToString());
                            }
                        }

                        _inCompareDataIndex++;
                    }
                }
                else
                {
                    returnResult.Ignored = true;
                    returnResult.ModIgn = false;

                    if (wikiCommand.StartsWith("{{{"))
                        inComment = true;
                    if (wikiCommand.EndsWith("}}}"))
                        inComment = false;
                }
            Exit:
                if (!commandLineMode)
                    CommandProcessed(returnResult);
            }
        }
コード例 #2
0
 //DDE mode
 public List<CommandResult> ProcessWikiCommands(string fileName, string[] wikiCommands, System.Threading.Thread activeThread, CommandEditorPage currentPage)
 {
     List<CommandResult> listOfResults = new List<CommandResult>();
     lineNumber = 0;
     ProcessWikiCommands(wikiCommands, new List<BreakPoint>(), activeThread, currentPage, false, listOfResults, fileName);
     return listOfResults;
 }
コード例 #3
0
 public void ProcessWikiCommands(string[] wikiCommands, List<BreakPoint> breakPoints, System.Threading.Thread activeThread, CommandEditorPage currentPage)
 {
     lineNumber = 0;
     ProcessWikiCommands(wikiCommands, breakPoints, activeThread, currentPage, false, new List<CommandResult>(), string.Empty);
 }
コード例 #4
0
 public void CheckForBreakPointOnLine(List<BreakPoint> breakPoints, int lineNumber, System.Threading.Thread activeThread, CommandEditorPage currentPage)
 {
     for (int i = 0; i < breakPoints.Count; i++)
     {
         if (breakPoints[i].BPLineNumber == lineNumber && breakPoints[i].BPActive)
         {
             currentPage.EnableCurrentBreakPoint(lineNumber);
             //currentPage.getEditor().EnableSelectedLine(lineNumber);
             breakPoints[i].PauseForBreakPoint(activeThread);
             currentPage.DisableCurrentBreakPoint(lineNumber, "normal");
             return;
         }
     }
     if (breakPoints[breakPoints.Count - 1].TempBP)
     {
         breakPoints.RemoveAt(breakPoints.Count - 1);
         currentPage.EnableCurrentBreakPoint(lineNumber);
         //currentPage.getEditor().EnableSelectedLine(lineNumber);
         breakPoints[0].PauseForBreakPoint(activeThread);
         currentPage.DisableCurrentBreakPoint(lineNumber, "temp");
         return;
     }
 }