private void VerifyAgainstString()
        {
            string         value   = this.Arguments["value"];
            TextInteractor txtfile = new TextInteractor(this.Arguments["object"], Logger.GetLog4NetLogger());

            if (value.Contains(Seperator))
            {
                int    lineNumber     = int.Parse(value.Substring(0, value.IndexOf(Seperator)));
                string expectedString = value.Substring(value.IndexOf(Seperator) + 3);
                if (InformationObject.TestCaseData is DatabaseStepData database)
                {
                    expectedString = database.QuerySpecialChars(GetEnvironmentVariable(EnvVar.Environment), expectedString).ToString();
                }

                this.TestStepStatus.RunSuccessful = txtfile.LineExactMatch(expectedString, lineNumber);
                this.TestStepStatus.Actual        = (this.TestStepStatus.RunSuccessful ? "Successfully found" : "Could not find") + $" {expectedString} on line {lineNumber}";
            }
            else
            {
                this.TestStepStatus.RunSuccessful = false;
                this.TestStepStatus.Actual        = "Specified to verify against string. However the value that was passed in did not fit the syntax.";
            }

            txtfile.Close();
        }
        /// <inheritdoc/>
        public ITestStep SetUpTestStep(string testStepFileLocation, bool performAction = true)
        {
            TextInteractor interactor        = new TextInteractor(testStepFileLocation);
            Dictionary <string, string> args = new Dictionary <string, string>();

            interactor.Open();
            while (!interactor.FinishedReading())
            {
                this.FileData.Add(interactor.ReadLine());
            }

            interactor.Close();

            string[] values   = this.FileData[0].Split(';');
            TestStep testStep = ReflectiveGetter.GetEnumerableOfType <TestStep>()
                                .Find(x => x.Name.Equals(values[1]));

            testStep.Name = values[0];

            foreach (string arg in values[2].Split(','))
            {
                string[] value = arg.Split('=');
                args.Add(value[0], value[1]);
            }

            testStep.Arguments = args;

            return(testStep);
        }
        private void FindString()
        {
            string         value   = this.Arguments["value"];
            TextInteractor txtfile = new TextInteractor(this.Arguments["object"], Logger.GetLog4NetLogger());
            string         expectedString;

            if (value.Contains(Seperator))
            {
                expectedString = value.Substring(0, value.IndexOf(Seperator));
                string argument = value.Substring(value.IndexOf(Seperator) + 3);
                if (InformationObject.TestCaseData is DatabaseStepData database)
                {
                    expectedString = database.QuerySpecialChars(GetEnvironmentVariable(EnvVar.Environment), expectedString).ToString();
                }

                int amountOfTimes;
                if (int.TryParse(argument, out amountOfTimes))
                {
                    this.TestStepStatus.RunSuccessful = txtfile.FindAndCount(expectedString) == amountOfTimes;
                }
                else
                {
                    switch (argument.ToLower())
                    {
                    case "exist":
                        this.TestStepStatus.RunSuccessful = txtfile.Find(expectedString);
                        break;

                    case "dne":
                        this.TestStepStatus.RunSuccessful = !txtfile.Find(expectedString);
                        break;

                    default:
                        this.TestStepStatus.RunSuccessful = false;
                        this.TestStepStatus.Actual        = "For the value argument, did not pass Exist, DNE or a number.";
                        break;
                    }
                }
            }
            else
            {
                expectedString = value;
                this.TestStepStatus.RunSuccessful = txtfile.Find(expectedString);
            }

            if (this.TestStepStatus.Actual == string.Empty)
            {
                this.TestStepStatus.Actual = this.TestStepStatus.RunSuccessful ? $"Successfully found {expectedString}." : $"Could not find {expectedString}.";
            }

            txtfile.Close();
        }
        /// <inheritdoc/>
        public override void Execute()
        {
            base.Execute();

            string         txt1     = this.Arguments["object"];
            string         comments = this.Arguments["comment"];
            string         value    = this.Arguments["value"];
            bool           pass     = false;
            TextInteractor txtfile  = new TextInteractor(txt1, Logger.GetLog4NetLogger());

            string seperator   = "];[";
            string toReplace   = value.Substring(0, value.IndexOf(seperator));
            string replaceWith = value.Substring(value.IndexOf(seperator) + 3);

            switch (comments.ToLower())
            {
            case "0":
            case "replaceonce":
                pass = txtfile.ReplaceOccurances(toReplace, replaceWith, numberOfTimes: 1);
                break;

            case "1":
            case "replaceall":
                pass = txtfile.ReplaceOccurances(toReplace, replaceWith);
                break;

            case "2":
            case "replaceline":
                string[] stringLines = toReplace.Split(';');
                int[]    lines       = Array.ConvertAll(stringLines, x => int.Parse(x));
                pass = txtfile.ReplaceLine(lines, replaceWith);
                break;

            default:
                Logger.Warn($"{comments} is not a valid option");
                this.TestStepStatus.Actual = $"{comments} is not a valid option";
                break;
            }

            this.TestStepStatus.RunSuccessful = pass;
            this.TestStepStatus.Actual        = pass ? "File successfully modified." : "File was not successfully modified.";
        }
        /// <inheritdoc/>
        public ITestCase SetUpTestCase(string txtFile, bool performAction = true)
        {
            TextInteractor interactor = new TextInteractor(txtFile);

            interactor.Open();
            while (!interactor.FinishedReading())
            {
                this.FileData.Add(interactor.ReadLine());
            }

            interactor.Close();

            this.FileIndex = 0;

            ITestCase testCase = new TestCase()
            {
                Name = txtFile,
                ShouldExecuteVariable = performAction,
            };

            return(testCase);
        }
        private void VerifyAgainstTextFile()
        {
            TextInteractor txtfile = new TextInteractor(this.Arguments["object"], Logger.GetLog4NetLogger());

            // value can be either file.
            string         fileName        = this.Arguments["value"];
            string         resultFileName  = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + DateTime.Now.ToString("Run_dd-MM-yyyy_HH-mm-ss") + ".log";
            TextInteractor expectedTxtFile = new TextInteractor(fileName, Logger.GetLog4NetLogger());

            this.TestStepStatus.RunSuccessful = expectedTxtFile.Compare(txtfile, resultFileName, ignoreWhitespace: true, caseInsensitive: true);
            expectedTxtFile.Close();

            // CR: Attach files that were compared. Attach resulting file if there were differences.
            InformationObject.TestSetData.AddAttachment(fileName);
            InformationObject.TestSetData.AddAttachment(this.Arguments["object"]);
            if (!this.TestStepStatus.RunSuccessful)
            {
                InformationObject.TestSetData.AddAttachment(resultFileName);
            }

            txtfile.Close();
        }