public DiscoveryResult RunDiscovery(string testAssemblyPath, string configFilePath)
        {
            var workingDirectory = Path.GetDirectoryName(testAssemblyPath);
            var arguments        = new List <string>();
            var connectorPath    = GetConnectorPath(arguments);

            arguments.Add("discovery");
            arguments.Add(testAssemblyPath);
            arguments.Add(configFilePath);
            if (DebugConnector)
            {
                arguments.Add("--debug");
            }

            if (!File.Exists(connectorPath))
            {
                return new DiscoveryResult
                       {
                           ErrorMessage = $"Error during binding discovery. Unable to find connector: {connectorPath}"
                       }
            }
            ;

            var result = ProcessHelper.RunProcess(workingDirectory, connectorPath, arguments, encoding: Encoding.UTF8);

            if (result.ExitCode != 0)
            {
                var errorMessage = result.HasErrors ? result.StandardError : "Unknown error.";

                return(new DiscoveryResult
                {
                    ErrorMessage = GetDetailedErrorMessage(result, errorMessage, BindingDiscoveryCommandName)
                });
            }

            _logger.LogVerbose(connectorPath);

#if DEBUG
            _logger.LogVerbose(result.StandardOut);
#endif

            var discoveryResult = JsonSerialization.DeserializeObjectWithMarker <DiscoveryResult>(result.StandardOut);
            if (discoveryResult.IsFailed)
            {
                discoveryResult.ErrorMessage = GetDetailedErrorMessage(result, discoveryResult.ErrorMessage, BindingDiscoveryCommandName);
            }

            return(discoveryResult);
        }
Beispiel #2
0
        public GenerationResult RunGenerator(string featureFilePath, string configFilePath, string targetExtension, string targetNamespace, string projectFolder, string specFlowToolsFolder, string projectDefaultNamespace = null, bool saveResultToFile = false)
        {
            var workingDirectory = specFlowToolsFolder;
            var arguments        = new List <string>();
            var connectorPath    = GetConnectorPath(arguments);

            arguments.Add("generate");
            arguments.Add(featureFilePath);
            arguments.Add(configFilePath);
            arguments.Add(targetExtension);
            arguments.Add(targetNamespace);
            arguments.Add(projectFolder);
            arguments.Add(projectDefaultNamespace);
            if (saveResultToFile)
            {
                arguments.Add("--save");
            }
            if (DebugConnector)
            {
                arguments.Add("--debug");
            }
            var result = ProcessHelper.RunProcess(workingDirectory, connectorPath, arguments, encoding: Encoding.UTF8);

            if (result.ExitCode != 0)
            {
                var errorMessage = result.HasErrors ? result.StandardError : "Unknown error.";

                return(new GenerationResult
                {
                    ErrorMessage = GetDetailedErrorMessage(result, errorMessage, GenerationCommandName)
                });
            }

            var generationResult = JsonSerialization.DeserializeObjectWithMarker <GenerationResult>(result.StandardOut);

            if (generationResult.FeatureFileCodeBehind == null && !generationResult.IsFailed)
            {
                generationResult.ErrorMessage = "No code-behind information provided";
            }

            if (generationResult.IsFailed)
            {
                generationResult.ErrorMessage =
                    GetDetailedErrorMessage(result, Environment.NewLine + generationResult.ErrorMessage, GenerationCommandName);
            }

            return(generationResult);
        }