コード例 #1
0
        private bool IsHookAttribute(BindingSourceAttribute attribute)
        {
// ReSharper disable AssignNullToNotNullAttribute
            return attribute.AttributeType.FullName.StartsWith(typeof(BeforeScenarioAttribute).Namespace) &&
                TryGetHookType(attribute) != null;
// ReSharper restore AssignNullToNotNullAttribute
        }
コード例 #2
0
 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));
 }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
        }
コード例 #8
0
 private HookType GetHookType(BindingSourceAttribute hookAttribute)
 {
     var hookType = TryGetHookType(hookAttribute);
     if (hookType == null)
         throw new SpecFlowException("Invalid hook attribute: " + hookAttribute);
     return hookType.Value;
 }
コード例 #9
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);
        }
コード例 #10
0
 private static string[] GetTagsDefinedOnBindingAttribute(BindingSourceAttribute hookAttribute)
 {
     return TagsFromConstructor(hookAttribute);            
 }
コード例 #11
0
        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];
        }
コード例 #12
0
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
コード例 #13
0
 public void Setup()
 {
     var ideTracerStub = new Mock<IIdeTracer>();
     this.BindingSourceProcessorUnderTest = new IdeBindingSourceProcessor(ideTracerStub.Object);
     this.bindingSourceAttribute = new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(BindingAttribute)) };
 }
コード例 #14
0
 private int GetHookOrder(BindingSourceAttribute hookAttribute)
 {
     return hookAttribute.TryGetAttributeValue("Order", 10000);
 }
コード例 #15
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);
 }
コード例 #16
0
        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));
        }
コード例 #17
0
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
コード例 #18
0
        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);
        }
コード例 #19
0
 private bool IsStepArgumentTransformationAttribute(BindingSourceAttribute attribute)
 {
     return attribute.AttributeType.TypeEquals(typeof(StepArgumentTransformationAttribute));
 }
コード例 #20
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));
        }
コード例 #21
-1
        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;
        }