public static OutProcSpecFlowConnector Create(IProjectScope projectScope)
        {
            var ideScope              = projectScope.IdeScope;
            var projectSettings       = projectScope.GetProjectSettings();
            var deveroomConfiguration = projectScope.GetDeveroomConfiguration();
            var processorArchitecture = GetProcessorArchitecture(deveroomConfiguration, projectSettings);

            return(new OutProcSpecFlowConnector(
                       deveroomConfiguration,
                       ideScope.Logger,
                       projectSettings.TargetFrameworkMoniker,
                       projectScope.IdeScope.GetExtensionFolder(),
                       processorArchitecture));
        }
        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 = 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);
                    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("???");
     }
 }
        private SpecFlowSettings UpdateSpecFlowSettingsFromConfig(SpecFlowSettings specFlowSettings)
        {
            var configuration = _projectScope.GetDeveroomConfiguration();

            if (configuration.SpecFlow.IsSpecFlowProject == null)
            {
                return(specFlowSettings);
            }

            if (!configuration.SpecFlow.IsSpecFlowProject.Value)
            {
                return(null);
            }

            specFlowSettings = specFlowSettings ?? new SpecFlowSettings();

            if (configuration.SpecFlow.Traits.Length > 0)
            {
                foreach (var specFlowTrait in configuration.SpecFlow.Traits)
                {
                    specFlowSettings.Traits |= specFlowTrait;
                }
            }

            if (configuration.SpecFlow.Version != null)
            {
                specFlowSettings.Version = new NuGetVersion(configuration.SpecFlow.Version);
            }

            if (configuration.SpecFlow.GeneratorFolder != null)
            {
                specFlowSettings.GeneratorFolder = configuration.SpecFlow.GeneratorFolder;
                specFlowSettings.Traits         |= SpecFlowProjectTraits.DesignTimeFeatureFileGeneration;
            }

            if (configuration.SpecFlow.ConfigFilePath != null)
            {
                specFlowSettings.ConfigFilePath = configuration.SpecFlow.ConfigFilePath;
            }
            else if (specFlowSettings.ConfigFilePath == null)
            {
                specFlowSettings.ConfigFilePath = GetSpecFlowConfigFilePath(_projectScope);
            }

            return(specFlowSettings);
        }
Ejemplo n.º 5
0
        private Uri GetUrl(Tag tag)
        {
            if (_projectScope == null)
            {
                return(null); // TODO: support global config?
            }
            var configuration = _projectScope.GetDeveroomConfiguration();

            if (!configuration.Traceability.TagLinks.Any())
            {
                return(null);
            }

            foreach (var tagLinkConfiguration in configuration.Traceability.TagLinks)
            {
                if (tagLinkConfiguration.ResolvedTagPattern == null)
                {
                    continue;
                }
                var match = tagLinkConfiguration.ResolvedTagPattern.Match(tag.Name.TrimStart('@'));
                if (!match.Success)
                {
                    continue;
                }

                try
                {
                    var url = Regex.Replace(tagLinkConfiguration.UrlTemplate, @"\{(?<paramName>[a-zA-Z_\d]+)\}",
                                            paramMatch => match.Groups[paramMatch.Groups["paramName"].Value].Value);
                    return(new Uri(url));
                }
                catch (Exception ex)
                {
                    _ideScope.Logger.LogDebugException(ex);
                }
            }

            return(null);
        }
 private OutProcSpecFlowConnector GetConnector(ProjectSettings projectSettings)
 {
     return(new OutProcSpecFlowConnector(_projectScope.GetDeveroomConfiguration(), Logger, projectSettings.TargetFrameworkMoniker, _projectScope.IdeScope.GetExtensionFolder()));
 }