public GenerationResult GenerateFeatureFile(string featureFilePath, string targetExtension, string targetNamespace)
        {
            var projectSettings     = _projectScope.GetProjectSettings();
            var specFlowToolsFolder = GetSpecFlowToolsFolderSafe(_projectScope, projectSettings, out var toolsFolderErrorMessage);

            if (specFlowToolsFolder == null)
            {
                return(CreateErrorResult(featureFilePath, $"Unable to use SpecFlow tools folder '{projectSettings.SpecFlowGeneratorFolder}': {toolsFolderErrorMessage}"));
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                var connector = OutProcSpecFlowConnectorFactory.Create(_projectScope);

                var result = connector.RunGenerator(featureFilePath, projectSettings.SpecFlowConfigFilePath,
                                                    targetExtension, targetNamespace, _projectScope.ProjectFolder, specFlowToolsFolder);

                _projectScope.IdeScope.MonitoringService.MonitorSpecFlowGeneration(result.IsFailed, projectSettings);

                if (result.IsFailed)
                {
                    _logger.LogWarning(result.ErrorMessage);
                    SetErrorContent(featureFilePath, result);
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content);
                }
                else
                {
                    _logger.LogInfo($"code-behind file generated for file {featureFilePath} in project {_projectScope.ProjectName}");
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content.Substring(0, Math.Min(450, result.FeatureFileCodeBehind.Content.Length)));
                }

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogException(MonitoringService, ex);
                return(CreateErrorResult(featureFilePath, ex.Message));
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogVerbose($"Generation: {stopwatch.ElapsedMilliseconds} ms");
            }
        }
 public string GetStepDefinitionSkeletonSnippet(UndefinedStepDescriptor undefinedStep, string indent = "    ", string newLine = null)
 {
     try
     {
         var configuration = _projectScope.GetDeveroomConfiguration();
         newLine = newLine ?? Environment.NewLine;
         var result = FallbackStepDefinitionSkeletonProvider.GetStepDefinitionSkeletonSnippetFallback(undefinedStep, indent, newLine, configuration.BindingCulture);
         _logger.LogInfo($"Step definition snippet generated for step '{undefinedStep.StepText}': {Environment.NewLine}{result}");
         return(result);
     }
     catch (Exception e)
     {
         _projectScope.IdeScope.Actions.ShowError("Could not generate step definition snippet.", e);
         return("???");
     }
 }
예제 #3
0
        public GenerationResult GenerateFeatureFile(string featureFilePath, string targetExtension, string targetNamespace)
        {
            var projectSettings     = _projectScope.GetProjectSettings();
            var specFlowToolsFolder = GetSpecFlowToolsFolderSafe(projectSettings);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                var connector = new OutProcSpecFlowConnector(_projectScope.GetDeveroomConfiguration(), _logger, projectSettings.TargetFrameworkMoniker, _projectScope.IdeScope.GetExtensionFolder());

                var result = connector.RunGenerator(featureFilePath, projectSettings.SpecFlowConfigFilePath,
                                                    targetExtension, targetNamespace, _projectScope.ProjectFolder, specFlowToolsFolder);

                _projectScope.IdeScope.MonitoringService.MonitorSpecFlowGeneration(result.IsFailed, projectSettings);

                if (result.IsFailed)
                {
                    _logger.LogWarning(result.ErrorMessage);
                    result.FeatureFileCodeBehind = new FeatureFileCodeBehind()
                    {
                        FeatureFilePath = featureFilePath,
                        Content         = GetErrorContent(result.ErrorMessage)
                    };
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content);
                }
                else
                {
                    _logger.LogInfo($"code-behind file generated for file {featureFilePath} in project {_projectScope.ProjectName}");
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content.Substring(0, Math.Min(450, result.FeatureFileCodeBehind.Content.Length)));
                }

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogException(MonitoringService, ex);
                return(null);
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogVerbose($"Generation: {stopwatch.ElapsedMilliseconds} ms");
            }
        }