Exemple #1
0
        private IEnumerable <StepDefinitionType> GetStepDefinitionTypes(BindingSourceAttribute stepDefinitionAttribute)
        {
            if (typeof(GivenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Given }
            }
            ;
            if (typeof(WhenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.When }
            }
            ;
            if (typeof(ThenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Then }
            }
            ;
            if (typeof(StepDefinitionAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Given, StepDefinitionType.When, StepDefinitionType.Then }
            }
            ;

            return(new StepDefinitionType[0]);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        private bool IsHookAttribute(BindingSourceAttribute attribute)
        {
// ReSharper disable AssignNullToNotNullAttribute
            return(attribute.AttributeType.FullName.StartsWith(typeof(BeforeScenarioAttribute).Namespace) &&
                   TryGetHookType(attribute) != null);
// ReSharper restore AssignNullToNotNullAttribute
        }
        private IEnumerable <StepDefinitionType> GetStepDefinitionTypes(BindingSourceAttribute stepDefinitionAttribute)
        {
            //Note: the Visual Studio Extension resolves the BindingSourceAttribute from the step definition source code without the Types property.
            //The Types property is only available at runtime when a StepDefinitionBaseAttribute can be reflected.
            //Please do not remove the checks for the sub-classes.
            if (typeof(GivenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Given }
            }
            ;
            if (typeof(WhenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.When }
            }
            ;
            if (typeof(ThenAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Then }
            }
            ;
            if (typeof(StepDefinitionAttribute).IsAssignableFrom(stepDefinitionAttribute.AttributeType))
            {
                return new[] { StepDefinitionType.Given, StepDefinitionType.When, StepDefinitionType.Then }
            }
            ;

            return(stepDefinitionAttribute.NamedAttributeValues["Types"].GetValue <IEnumerable <StepDefinitionType> >());
        }
 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)));
 }
Exemple #6
0
 private bool IsStepDefinitionAttribute(BindingSourceAttribute attribute)
 {
     return
         (typeof(GivenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(WhenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(ThenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(StepDefinitionAttribute).IsAssignableFrom(attribute.AttributeType));
 }
Exemple #7
0
        private HookType GetHookType(BindingSourceAttribute hookAttribute)
        {
            var hookType = TryGetHookType(hookAttribute);

            if (hookType == null)
            {
                throw new SpecFlowException("Invalid hook attribute: " + hookAttribute);
            }
            return(hookType.Value);
        }
 private bool IsStepDefinitionAttribute(BindingSourceAttribute attribute)
 {
     //NOTE: the IsAssignableFrom calls below are not the built-in ones from the Type system but custom extension methods.
     //The IBindingType based IsAssignableFrom does not support polymorphism if the IBindingType is not IPolymorphicBindingType (e.g. RuntimeBindingType)
     //The Visual Studio Extension uses a source code based IBindingType that cannot support IPolymorphicBindingType.
     //Please do not remove the checks for the sub-classes.
     return
         (typeof(GivenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(WhenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(ThenAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(StepDefinitionAttribute).IsAssignableFrom(attribute.AttributeType) ||
          typeof(StepDefinitionBaseAttribute).IsAssignableFrom(attribute.AttributeType));
 }
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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));
        }
Exemple #13
0
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
        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));
        }
Exemple #15
0
        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);
            }
        }
Exemple #16
0
        protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Exemple #17
0
        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));
        }
Exemple #18
0
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Exemple #19
0
 private static string[] GetTagsDefinedOnBindingAttribute(BindingSourceAttribute hookAttribute)
 {
     return(TagsFromConstructor(hookAttribute));
 }
Exemple #20
0
 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));
 }
Exemple #21
0
 private int GetHookOrder(BindingSourceAttribute hookAttribute)
 {
     return(hookAttribute.TryGetAttributeValue("Order", 10000));
 }
Exemple #22
0
 private bool IsStepArgumentTransformationAttribute(BindingSourceAttribute attribute)
 {
     return(attribute.AttributeType.TypeEquals(typeof(StepArgumentTransformationAttribute)));
 }
 private IEnumerable <StepDefinitionType> GetStepDefinitionTypes(BindingSourceAttribute stepDefinitionAttribute)
 {
     return(stepDefinitionAttribute.NamedAttributeValues["Types"].GetValue <IEnumerable <StepDefinitionType> >());
 }