public void TestCommandIsInverse(string command, bool isInverse)
 {
     SWAT.Fitnesse.Command objCommand = new Command(command);
     Assert.AreEqual(isInverse, objCommand.IsInverse);
 }
 public void TestCommandName(string command, string name)
 {
   Command objCommand = new Command(command);
   Assert.AreEqual(name, objCommand.Name);
 }
 public void TestCommandIsCritical(string command, bool isCritical)
 {
   SWAT.Fitnesse.Command objCommand = new Command(command);
   Assert.AreEqual(isCritical, objCommand.IsCritical);
 }
 public void TestIfStatement(string command, IfStatementType ifStatementType)
 {
   SWAT.Fitnesse.Command objCommand = new Command(command);
   Assert.AreEqual(ifStatementType, objCommand.IfStatementType);
 }
    public void TestManagerShouldExecuteIgnoreAbandonTest()
    {
        Command abandonCommand = new Command("AbandonTest");
        TestManager.IgnoreRemainingTableRows = true;
        TestManager.ShouldExecute(abandonCommand);
        Assert.IsFalse(TestManager.AbandonTest, "TestManager should ignore AbandonTest when IgnoreRemainingTableRows is true");
        TestManager.IgnoreRemainingTableRows = false;

        TestManager.IgnoreRemainingTestRows = true;
        TestManager.ShouldExecute(abandonCommand);
        Assert.IsFalse(TestManager.AbandonTest, "TestManager should ignore AbandonTest when IgnoreRemainingTestRows is true");
        TestManager.IgnoreRemainingTestRows = false;
        TestManager.ResetForNewTest();

    }
 public void TestManagerShouldExecuteWorksWithResumeTest()
 {
     Command resumeCommand = new Command("ResumeTest");
     Assert.IsTrue(TestManager.ShouldExecute(resumeCommand), "ShouldExecute should return true for ResumeTest!");
     Command abandonCommand = new Command("AbandonTest");
     TestManager.ShouldExecute(abandonCommand);
     TestManager.ShouldExecute(resumeCommand);
     Assert.IsFalse(TestManager.AbandonTest, "TestManager.AbandonTest should assert false after ShouldExecute method is run with ResumeTest");
     TestManager.ResetForNewTest();
 }
    public void TestCommandShouldReport()
    {
        Command myCommand = new Command("AnyCommand");
        Assert.IsTrue(myCommand.ShouldReport);

        myCommand = new Command("?AnyCommand");
        Assert.IsFalse(myCommand.ShouldReport);
    }
 public void TestManagerShouldExecuteWorksWithAbandonTest()
 {
     Command abandonCommand = new Command("AbandonTest");
     Command arbitraryCommandWithModifier = new Command("@@OpenBrowser");
     Assert.IsTrue(TestManager.ShouldExecute(abandonCommand), "ShouldExecute should return true for AbandonTest!");
     Assert.IsTrue(TestManager.AbandonTest, "TestManager.AbandonTest should assert true after ShouldExecute method is run with AbandonTest");
     Assert.IsFalse(TestManager.ShouldExecute(arbitraryCommandWithModifier), "TestManager.ShouldExecute() should return false after AbandonTest has been run");
     TestManager.ResetForNewTest();
 }
 public void TestManagerCommandWithInverseModifier()
 {
     TestManager.ResetForNewTest();
     Command inverseCommand = new Command("<>myCommandInverse");
     TestManager.LogCommand(inverseCommand);
     Command nextCommand = new Command("executeMeOnlyIfLastCommandDidNotPassed"); //Command will execute if the previous command was logged correctly.
     TestManager.LogCommand(nextCommand);
     Assert.IsTrue(TestManager.ShouldExecute(nextCommand), "Inverse Moidifier is not working correctly");
     inverseCommand.Passed = false;
     TestManager.LogCommand(inverseCommand);
     TestManager.LogCommand(nextCommand);
     Assert.IsFalse(TestManager.ShouldExecute(nextCommand), "Inverse Moidifier is not working correctly");
     TestManager.ResetForNewTest();
 }
    public void TestManagerShouldExecute()
    {
      SWAT.Fitnesse.Command prevCommand = new Command("myCommand");
      SWAT.Fitnesse.Command objCommand = new Command("myCommand");
      //TestManager TestManager = new TestManager(new SWATFixture());

      prevCommand.Passed = false;
      TestManager.LogCommand(prevCommand);
      Assert.AreEqual(false, TestManager.ShouldExecute(objCommand));

      prevCommand.Passed = true;
      TestManager.LogCommand(prevCommand);
      Assert.AreEqual(false, TestManager.ShouldExecute(objCommand)); //manager is aware we are in a completely failed state and will block everything


      //prevCommand.Passed = true;
      //mngr.LogCommand(prevCommand);
      //Assert.AreEqual(true, objCommand.ShouldExecute(prevCommand));
      //Assert.AreEqual(true, mngr.ShouldExecute);
    }
    public void TestManagerCommandFailedTestBlockIfNot()
    {
      //TestManager TestManager = new TestManager(new SWATFixture());

      Command firstCommand = new Command("??!myCommandBlockIf");
      firstCommand.Passed = true;

      TestManager.LogCommand(firstCommand);


      Command nextCommand = new Command("executeMeOnlyIfLastCommandFailed");

      Assert.AreEqual(false, TestManager.ShouldExecute(nextCommand));

      TestManager.LogCommand(nextCommand);

      Command anotherCommand = new Command("thiscommandshouldnotexecute");

      Assert.AreEqual(false, TestManager.ShouldExecute(anotherCommand));

      TestManager.LogCommand(anotherCommand);

      //let's test when we leave the table.
      TestManager.ResetForNewTable();

      Command oneMoreCommand = new Command("thiscommandshouldexecute");

      Assert.AreEqual(true, TestManager.ShouldExecute(oneMoreCommand));

    }
    public void TestManagerCommandFailedTestSingleIfNot()
    {
      //TestManager mngr = new TestManager(new SWATFixture());

      Command firstCommand = new Command("?!myCommandSingleIf");
      firstCommand.Passed = true;

      //mngr.LogCommand(firstCommand);
        TestManager.LogCommand(firstCommand);

      Command nextCommand = new Command("executeMeOnlyIfLastCommandFailed");

      Assert.AreEqual(false, TestManager.ShouldExecute(nextCommand));

      TestManager.LogCommand(nextCommand);

      Command anotherCommand = new Command("thiscommandshouldexecute");

      Assert.AreEqual(true, TestManager.ShouldExecute(nextCommand));


    }
        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);
            }
        }