private void SaveAsStepDefinitionClass(IProjectScope projectScope, string combinedSnippet, string className,
                                               string indent, string newLine)
        {
            string targetFolder          = projectScope.ProjectFolder;
            var    projectSettings       = projectScope.GetProjectSettings();
            var    defaultNamespace      = projectSettings.DefaultNamespace ?? projectScope.ProjectName;
            var    fileNamespace         = defaultNamespace;
            var    stepDefinitionsFolder = Path.Combine(targetFolder, "StepDefinitions");

            if (projectScope.IdeScope.FileSystem.Directory.Exists(stepDefinitionsFolder))
            {
                targetFolder  = stepDefinitionsFolder;
                fileNamespace = fileNamespace + ".StepDefinitions";
            }

            var targetFilePath = Path.Combine(targetFolder, className + ".cs");

            var template = $"using System;" + newLine +
                           $"using TechTalk.SpecFlow;" + newLine +
                           newLine +
                           $"namespace {fileNamespace}" + newLine +
                           $"{{" + newLine +
                           $"{indent}[Binding]" + newLine +
                           $"{indent}public class {className}" + newLine +
                           $"{indent}{{" + newLine +
                           combinedSnippet +
                           $"{indent}}}" + newLine +
                           $"}}" + newLine;

            projectScope.AddFile(targetFilePath, template);
            projectScope.IdeScope.Actions.NavigateTo(new SourceLocation(targetFilePath, 9, 1));
        }
        public static SnippetService GetSnippetService(this IProjectScope projectScope)
        {
            if (!projectScope.GetProjectSettings().IsSpecFlowProject)
            {
                return(null);
            }

            return(projectScope.Properties.GetOrCreateSingletonProperty(() =>
                                                                        new SnippetService(projectScope)));
        }
        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 = 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");
            }
        }
Exemplo n.º 5
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");
            }
        }
        private void SaveAsStepDefinitionClass(IProjectScope projectScope, string combinedSnippet, string className,
                                               string indent, string newLine)
        {
            string targetFolder          = projectScope.ProjectFolder;
            var    projectSettings       = projectScope.GetProjectSettings();
            var    defaultNamespace      = projectSettings.DefaultNamespace ?? projectScope.ProjectName;
            var    fileNamespace         = defaultNamespace;
            var    stepDefinitionsFolder = Path.Combine(targetFolder, "StepDefinitions");

            if (IdeScope.FileSystem.Directory.Exists(stepDefinitionsFolder))
            {
                targetFolder  = stepDefinitionsFolder;
                fileNamespace = fileNamespace + ".StepDefinitions";
            }

            var targetFilePath = Path.Combine(targetFolder, className + ".cs");

            if (IdeScope.FileSystem.File.Exists(targetFilePath))
            {
                if (IdeScope.Actions.ShowSyncQuestion("Overwrite file?",
                                                      $"The selected step definition file '{targetFilePath}' already exists. By overwriting the existing file you might loose work. {Environment.NewLine}Do you want to overwrite the file?",
                                                      defaultButton: MessageBoxResult.No) != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            var template = $"using System;" + newLine +
                           $"using TechTalk.SpecFlow;" + newLine +
                           newLine +
                           $"namespace {fileNamespace}" + newLine +
                           $"{{" + newLine +
                           $"{indent}[Binding]" + newLine +
                           $"{indent}public class {className}" + newLine +
                           $"{indent}{{" + newLine +
                           combinedSnippet +
                           $"{indent}}}" + newLine +
                           $"}}" + newLine;

            projectScope.AddFile(targetFilePath, template);
            projectScope.IdeScope.Actions.NavigateTo(new SourceLocation(targetFilePath, 9, 1));
        }
        public static bool CheckSpecFlowToolsFolder(IProjectScope projectScope)
        {
            var toolsFolder = GetSpecFlowToolsFolderSafe(projectScope, projectScope.GetProjectSettings(), out _);

            return(toolsFolder != null);
        }