コード例 #1
0
        public ProjectStepDefinitionBinding ImportStepDefinition(StepDefinition stepDefinition)
        {
            try
            {
                var stepDefinitionType = (ScenarioBlock)Enum.Parse(typeof(ScenarioBlock), stepDefinition.Type);
                var regex          = new Regex(stepDefinition.Regex, RegexOptions.CultureInvariant);
                var sourceLocation = ParseSourceLocation(stepDefinition.SourceLocation);
                var scope          = ParseScope(stepDefinition.Scope);
                var parameterTypes = ParseParameterTypes(stepDefinition.ParamTypes);

                if (!_implementations.TryGetValue(stepDefinition.Method, out var implementation))
                {
                    implementation = new ProjectStepDefinitionImplementation(stepDefinition.Method, parameterTypes, sourceLocation);
                    _implementations.Add(stepDefinition.Method, implementation);
                }


                return(new ProjectStepDefinitionBinding(stepDefinitionType, regex, scope, implementation));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Invalid binding: {ex.Message}");
                return(null);
            }
        }
コード例 #2
0
        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");
            }
        }
コード例 #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");
            }
        }