Example #1
0
        public void ThenTheSourceFileOfTheStepDefinitionIsOpened(string stepRegex, ScenarioBlock stepType)
        {
            _stepDefinitionBinding = _discoveryService.GetBindingRegistry().StepDefinitions.FirstOrDefault(b => b.StepDefinitionType == stepType && b.Regex.ToString().Contains(stepRegex));
            _stepDefinitionBinding.Should().NotBeNull($"there has to be a {stepType} stepdef with regex '{stepRegex}'");

            ActionsMock.LastNavigateToSourceLocation.Should().NotBeNull();
            ActionsMock.LastNavigateToSourceLocation.SourceFile.Should().Be(_stepDefinitionBinding.Implementation.SourceLocation.SourceFile);
        }
Example #2
0
        private string GetPlaceHolderText(ProjectStepDefinitionBinding stepDefinitionBinding, int groupIndex)
        {
            if (stepDefinitionBinding.Implementation?.ParameterTypes == null ||
                groupIndex >= stepDefinitionBinding.Implementation.ParameterTypes.Length)
            {
                return("???");
            }

            var typeName = stepDefinitionBinding.Implementation.ParameterTypes[groupIndex];

            switch (typeName)
            {
            case TypeShortcuts.Int32Type:
                return("int");

            case TypeShortcuts.StringType:
                return("string");
            }
            return(typeName.Split('.').Last());
        }
Example #3
0
        public string GetStepDefinitionSample(ProjectStepDefinitionBinding stepDefinitionBinding)
        {
            var regexTextCore = stepDefinitionBinding.Regex.ToString().TrimStart('^').TrimEnd('$');

            if (!SplitRegexByGroups(regexTextCore, out var regexParts))
            {
                return(regexTextCore);
            }
            var completionTextBuilder = new StringBuilder();

            for (int i = 0; i < regexParts.Length; i++)
            {
                completionTextBuilder.Append(regexParts[i]);
                if (i < regexParts.Length - 1)
                {
                    completionTextBuilder.Append("[");
                    completionTextBuilder.Append(GetPlaceHolderText(stepDefinitionBinding, i));
                    completionTextBuilder.Append("]");
                }
            }

            return(completionTextBuilder.ToString());
        }
        private bool IsTriggerPointInStepDefinition(ProjectStepDefinitionBinding stepDefinition, SnapshotPoint triggerPoint)
        {
            var sourceLocation = stepDefinition.Implementation.SourceLocation;
            var span           = sourceLocation.SourceLocationSpan?.Span;

            if (span != null)
            {
                return(IsTriggerPointInStepDefinition(span, triggerPoint));
            }

            //backup solution: we accept it 3 lines before the start line and 3 lines after
            // the start line if there is no end line, otherwise until the end line
            var triggerPointLine = triggerPoint.GetContainingLine().LineNumber + 1;

            if (triggerPointLine < sourceLocation.SourceFileLine - 3)
            {
                return(false);
            }
            if (sourceLocation.HasEndPosition)
            {
                return(triggerPointLine <= sourceLocation.SourceFileEndLine);
            }
            return(triggerPointLine <= sourceLocation.SourceFileLine + 3);
        }