Example #1
0
        public Result Execute(CommonParameters commonParameters, bool transferViaFile)
        {
            var exchangePath = String.IsNullOrWhiteSpace(_integrationOptions.CodeBehindFileGeneratorExchangePath)
                ? Path.GetTempPath()
                : _integrationOptions.CodeBehindFileGeneratorExchangePath;

            commonParameters.OutputDirectory = Path.GetDirectoryName(_fileSystem.AppendDirectorySeparatorIfNotPresent(exchangePath));


            string commandLineParameters = CommandLine.Parser.Default.FormatCommandLine(commonParameters);

            var processHelper = new ProcessHelper();

            if (!File.Exists(_fullPathToExe))
            {
                return(new Result(1, string.Format("Could not find CodeBehindGenerator binary at location {0}." + Environment.NewLine + "Please open an issue at https://github.com/techtalk/SpecFlow/issues/", _fullPathToExe)));
            }

            int exitCode = processHelper.RunProcess(_info.GeneratorFolder, _fullPathToExe, commandLineParameters);

            var outputFileContent = processHelper.ConsoleOutput;

            outputFileContent = FilterConfigDebugOutput(outputFileContent);


            if (transferViaFile)
            {
                var firstLine = outputFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

                if (firstLine != null)
                {
                    if (File.Exists(firstLine))
                    {
                        outputFileContent = File.ReadAllText(firstLine, Encoding.UTF8);
                        try
                        {
                            File.Delete(firstLine);
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    else
                    {
                        return(new Result(1, "We could not find a data exchange file at the path " + firstLine + "" + Environment.NewLine +
                                          Environment.NewLine + "Please open an issue at https://github.com/techtalk/SpecFlow/issues/" + Environment.NewLine +
                                          "Complete output: " + Environment.NewLine +
                                          outputFileContent + Environment.NewLine +
                                          Environment.NewLine +
                                          "Command: " + _fullPathToExe + Environment.NewLine +
                                          "Parameters: " + commandLineParameters + Environment.NewLine +
                                          "Working Directory: " + _info.GeneratorFolder));
                    }
                }
                else
                {
                    return(new Result(1, "Data Exchange via file did not worked, because we didn't receive a file path to read. " + Environment.NewLine +
                                      Environment.NewLine + "Please open an issue at https://github.com/techtalk/SpecFlow/issues/" + Environment.NewLine +
                                      "Complete output: " + Environment.NewLine +
                                      outputFileContent + Environment.NewLine +
                                      Environment.NewLine +
                                      "Command: " + _fullPathToExe + Environment.NewLine +
                                      "Parameters: " + commandLineParameters + Environment.NewLine +
                                      "Working Directory: " + _info.GeneratorFolder));
                }
            }


            return(new Result(exitCode, outputFileContent));
        }