private void AddStepsToRegsitry(string fileName, IEnumerable <MethodDeclarationSyntax> stepMethods) { foreach (var stepMethod in stepMethods) { var attributeListSyntax = stepMethod.AttributeLists.WithStepAttribute(); var attributeSyntax = attributeListSyntax.Attributes.GetStepAttribute(); var stepTextsSyntax = attributeSyntax.ArgumentList.Arguments.ToList(); var stepTexts = stepTextsSyntax.Select(s => s.ToString().Trim('"')); var hasAlias = stepTexts.Count() > 1; foreach (var stepText in stepTexts) { var stepValue = Regex.Replace(stepText, @"(<.*?>)", @"{}"); var classDef = stepMethod.Parent as ClassDeclarationSyntax; var entry = new GaugeMethod { Name = stepMethod.Identifier.ValueText, ParameterCount = stepMethod.ParameterList.Parameters.Count, StepText = stepText, HasAlias = hasAlias, Aliases = stepTexts, StepValue = stepValue, Span = stepMethod.GetLocation().GetLineSpan(), ClassName = classDef.Identifier.ValueText, FileName = fileName }; _stepRegistry.AddStep(stepValue, entry); } } }
public IStepRegistry GetStepRegistry() { Logger.Debug("Building StepRegistry..."); var infos = GetMethods(LibType.Step); Logger.Debug($"{infos.Count()} Step implementations found. Adding to registry..."); foreach (var info in infos) { var stepTexts = info.GetCustomAttributes().Where(x => x.GetType().FullName == LibType.Step.FullName()) .SelectMany(x => x.GetType().GetProperty("Names").GetValue(x, null) as string[]); foreach (var stepText in stepTexts) { var stepValue = GetStepValue(stepText); if (_registry.ContainsStep(stepValue)) { Logger.Debug($"'{stepValue}': implementation found in StepRegistry, setting reflected methodInfo"); _registry.MethodFor(stepValue).MethodInfo = info; _registry.MethodFor(stepValue).ContinueOnFailure = info.IsRecoverableStep(this); } else { Logger.Debug($"'{stepValue}': no implementation in StepRegistry, adding via reflection"); var hasAlias = stepTexts.Count() > 1; var stepMethod = new GaugeMethod { Name = info.FullyQuallifiedName(), ParameterCount = info.GetParameters().Length, StepText = stepText, HasAlias = hasAlias, Aliases = stepTexts, MethodInfo = info, ContinueOnFailure = info.IsRecoverableStep(this), StepValue = stepValue, IsExternal = true, }; _registry.AddStep(stepValue, stepMethod); } } } return(_registry); }
public IStepRegistry GetStepRegistry() { var infos = GetMethods(LibType.Step); foreach (var info in infos) { var stepTexts = info.GetCustomAttributes(GetLibType(LibType.Step)) .SelectMany(x => x.GetType().GetProperty("Names").GetValue(x, null) as string[]); foreach (var stepText in stepTexts) { var stepValue = GetStepValue(stepText); if (_registry.ContainsStep(stepValue)) { _registry.MethodFor(stepValue).MethodInfo = info; _registry.MethodFor(stepValue).ContinueOnFailure = info.IsRecoverableStep(this); } else { var hasAlias = stepTexts.Count() > 1; var stepMethod = new GaugeMethod { Name = info.FullyQuallifiedName(), ParameterCount = info.GetParameters().Length, StepText = stepText, HasAlias = hasAlias, Aliases = stepTexts, MethodInfo = info, ContinueOnFailure = info.IsRecoverableStep(this), StepValue = stepValue, IsExternal = true, }; _registry.AddStep(stepValue, stepMethod); } } } return(_registry); }