private bool IsHookAttribute(BindingSourceAttribute attribute) { // ReSharper disable AssignNullToNotNullAttribute return attribute.AttributeType.FullName.StartsWith(typeof(BeforeScenarioAttribute).Namespace) && TryGetHookType(attribute) != null; // ReSharper restore AssignNullToNotNullAttribute }
private bool IsStepDefinitionAttribute(BindingSourceAttribute attribute) { return attribute.AttributeType.TypeEquals(typeof(GivenAttribute)) || attribute.AttributeType.TypeEquals(typeof(WhenAttribute)) || attribute.AttributeType.TypeEquals(typeof(ThenAttribute)) || attribute.AttributeType.TypeEquals(typeof(StepDefinitionAttribute)); }
protected override bool ValidateHook(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute hookAttribute, HookType hookType) { //TODO: this call will be refactored when binding error detecttion will be improved in v2 - currently implemented here for backwards compatibility if (!IsScenarioSpecificHook(hookType) && !bindingSourceMethod.IsStatic) throw errorProvider.GetNonStaticEventError(bindingSourceMethod.BindingMethod); return base.ValidateHook(bindingSourceMethod, hookAttribute, hookType); }
public static BindingSourceAttribute WithValue(this BindingSourceAttribute a, string val) { var values = a.AttributeValues == null ? new List <IBindingSourceAttributeValueProvider>() : a.AttributeValues.ToList(); values.Add(new BindingSourceAttributeValueProvider(val)); a.AttributeValues = values.ToArray(); return(a); }
protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute) { if (!ValidateMethod(bindingSourceMethod)) return false; return true; }
private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute, BindingScope scope) { var stepDefinitionTypes = GetStepDefinitionTypes(stepDefinitionAttribute); string regex = stepDefinitionAttribute.TryGetAttributeValue<string>(0); if (!ValidateStepDefinition(bindingSourceMethod, stepDefinitionAttribute)) return; foreach (var stepDefinitionType in stepDefinitionTypes) { var stepDefinitionBinding = bindingFactory.CreateStepBinding(stepDefinitionType, regex, bindingSourceMethod.BindingMethod, scope); ProcessStepDefinitionBinding(stepDefinitionBinding); } }
private HookType? TryGetHookType(BindingSourceAttribute hookAttribute) { string typeName = hookAttribute.AttributeType.Name; if (typeName == typeof(BeforeAttribute).Name) return HookType.BeforeScenario; if (typeName == typeof(AfterAttribute).Name) return HookType.AfterScenario; const string attributePostfix = "Attribute"; if (!typeName.EndsWith(attributePostfix)) return null; string name = typeName.Substring(0, typeName.Length - attributePostfix.Length); if (!hookNames.Contains(name)) return null; return (HookType)Enum.Parse(typeof(HookType), name, false); }
private HookType GetHookType(BindingSourceAttribute hookAttribute) { var hookType = TryGetHookType(hookAttribute); if (hookType == null) throw new SpecFlowException("Invalid hook attribute: " + hookAttribute); return hookType.Value; }
private void ProcessStepArgumentTransformationAttribute(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute) { string regex = stepArgumentTransformationAttribute.TryGetAttributeValue<string>(0) ?? stepArgumentTransformationAttribute.TryGetAttributeValue<string>("Regex"); if (!ValidateStepArgumentTransformation(bindingSourceMethod, stepArgumentTransformationAttribute)) return; var stepArgumentTransformationBinding = bindingFactory.CreateStepArgumentTransformation(regex, bindingSourceMethod.BindingMethod); ProcessStepArgumentTransformationBinding(stepArgumentTransformationBinding); }
private static string[] GetTagsDefinedOnBindingAttribute(BindingSourceAttribute hookAttribute) { return TagsFromConstructor(hookAttribute); }
private IEnumerable<StepDefinitionType> GetStepDefinitionTypes(BindingSourceAttribute stepDefinitionAttribute) { if (stepDefinitionAttribute.AttributeType.TypeEquals(typeof(GivenAttribute))) return new[] { StepDefinitionType.Given }; if (stepDefinitionAttribute.AttributeType.TypeEquals(typeof(WhenAttribute))) return new[] { StepDefinitionType.When }; if (stepDefinitionAttribute.AttributeType.TypeEquals(typeof(ThenAttribute))) return new[] { StepDefinitionType.Then }; if (stepDefinitionAttribute.AttributeType.TypeEquals(typeof(StepDefinitionAttribute))) return new[] { StepDefinitionType.Given, StepDefinitionType.When, StepDefinitionType.Then }; return new StepDefinitionType[0]; }
private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute) { ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope)); }
public void Setup() { var ideTracerStub = new Mock<IIdeTracer>(); this.BindingSourceProcessorUnderTest = new IdeBindingSourceProcessor(ideTracerStub.Object); this.bindingSourceAttribute = new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(BindingAttribute)) }; }
private int GetHookOrder(BindingSourceAttribute hookAttribute) { return hookAttribute.TryGetAttributeValue("Order", 10000); }
private static string[] TagsFromConstructor(BindingSourceAttribute hookAttribute) { // HACK: Currently on mono to compile we have to pass the optional parameter to TryGetParamsAttributeValue return hookAttribute.TryGetParamsAttributeValue<string>(0, null); }
private void ProcessHookAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute hookAttribute) { var scopes = methodScopes.AsEnumerable(); // HACK: Currently on mono to compile we have to pass the optional parameter to TryGetParamsAttributeValue string[] tags = hookAttribute.TryGetParamsAttributeValue<string>(0, null); if (tags != null) scopes = scopes.Concat(tags.Select(t => new BindingScope(t, null, null))); ApplyForScope(scopes.ToArray(), scope => ProcessHookAttribute(bindingSourceMethod, hookAttribute, scope)); }
protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute) { if (!ValidateMethod(bindingSourceMethod)) return false; return true; }
private void ProcessHookAttribute(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute hookAttribute, BindingScope scope) { HookType hookType = GetHookType(hookAttribute); if (!ValidateHook(bindingSourceMethod, hookAttribute, hookType)) return; var hookBinding = bindingFactory.CreateHookBinding(bindingSourceMethod.BindingMethod, hookType, scope); ProcessHookBinding(hookBinding); }
private bool IsStepArgumentTransformationAttribute(BindingSourceAttribute attribute) { return attribute.AttributeType.TypeEquals(typeof(StepArgumentTransformationAttribute)); }
private void ProcessHookAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute hookAttribute) { var scopes = methodScopes.AsEnumerable(); string[] tags = GetTagsDefinedOnBindingAttribute(hookAttribute); if (tags != null) scopes = scopes.Concat(tags.Select(t => new BindingScope(t, null, null))); ApplyForScope(scopes.ToArray(), scope => ProcessHookAttribute(bindingSourceMethod, hookAttribute, scope)); }
protected virtual bool ValidateHook(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute hookAttribute, HookType hookType) { if (!ValidateMethod(bindingSourceMethod)) return false; if (!IsScenarioSpecificHook(hookType) && !bindingSourceMethod.IsStatic && OnValidationError("The binding methods for before/after feature and before/after test run events must be static! {0}", bindingSourceMethod)) return false; return true; }