Beispiel #1
0
 protected virtual void ProcessStepDefinitions(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepDefinitionAttribute in bindingSourceMethod.Attributes.Where(IsStepDefinitionAttribute))
     {
         ProcessStepDefinitionAttribute(bindingSourceMethod, methodScopes, stepDefinitionAttribute);
     }
 }
Beispiel #2
0
 protected virtual void ProcessHooks(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var hookAttribute in bindingSourceMethod.Attributes.Where(IsHookAttribute))
     {
         ProcessHookAttribute(bindingSourceMethod, methodScopes, hookAttribute);
     }
 }
Beispiel #3
0
 protected virtual void ProcessStepArgumentTransformations(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepArgumentTransformationAttribute in bindingSourceMethod.Attributes.Where(IsStepArgumentTransformationAttribute))
     {
         ProcessStepArgumentTransformationAttribute(bindingSourceMethod, stepArgumentTransformationAttribute);
     }
 }
        public void ProcessMethod(BindingSourceMethod bindingSourceMethod)
        {
            var methodScopes = typeScopes.Concat(GetScopes(bindingSourceMethod.Attributes)).ToArray();

            ProcessStepDefinitions(bindingSourceMethod, methodScopes);
            ProcessHooks(bindingSourceMethod, methodScopes);
            ProcessStepArgumentTransformations(bindingSourceMethod, methodScopes);
        }
Beispiel #5
0
        public void ProcessMethod(BindingSourceMethod bindingSourceMethod)
        {
            var methodScopes = typeScopes.Concat(GetScopes(bindingSourceMethod.Attributes)).ToArray();

            ProcessStepDefinitions(bindingSourceMethod, methodScopes);
            ProcessHooks(bindingSourceMethod, methodScopes);
            ProcessStepArgumentTransformations(bindingSourceMethod, methodScopes);
        }
        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);
        }
Beispiel #7
0
        protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Beispiel #8
0
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Beispiel #9
0
        protected virtual bool ValidateMethod(BindingSourceMethod bindingSourceMethod)
        {
            if (currentBindingSourceType.IsAbstract && !bindingSourceMethod.IsStatic &&
                OnValidationError("Abstract binding types can have only static binding methods: {0}", bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Beispiel #10
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));
        }
Beispiel #11
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));
        }
        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));
        }
Beispiel #13
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);
        }
        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);
        }
Beispiel #15
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);
        }
Beispiel #16
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);
            }
        }
        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);
        }
 protected virtual void ProcessHooks(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var hookAttribute in bindingSourceMethod.Attributes.Where(IsHookAttribute))
     {
         ProcessHookAttribute(bindingSourceMethod, methodScopes, hookAttribute);
     }
 }
Beispiel #19
0
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
 protected virtual void ProcessStepArgumentTransformations(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepArgumentTransformationAttribute in bindingSourceMethod.Attributes.Where(IsStepArgumentTransformationAttribute))
     {
         ProcessStepArgumentTransformationAttribute(bindingSourceMethod, stepArgumentTransformationAttribute);
     }
 }
        public void Non_static_method_with_non_scenario_specific_hook_should_not_be_valid()
        {
            var stubType = new BindingSourceType
            {
                IsGenericTypeDefinition = false,
                IsClass = true,
                IsAbstract = false,
                Attributes = new[] { bindingSourceAttribute, }
            };

            var stubMethod = new BindingSourceMethod
            {
                IsPublic = true,
                IsStatic = false,
                BindingMethod = new BindingMethod(new BindingType("Test", "Test"), "TestMethod", Enumerable.Empty<IBindingParameter>(), new BindingType("Test", "Test")),
                Attributes = new[]
                        {
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(BeforeTestRunAttribute)), NamedAttributeValues = new Dictionary<string, IBindingSourceAttributeValueProvider>(), AttributeValues = new IBindingSourceAttributeValueProvider[] { } },
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(MethodBinding)) },
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(StepDefinitionAttribute)), NamedAttributeValues = new Dictionary<string, IBindingSourceAttributeValueProvider>(), AttributeValues = new IBindingSourceAttributeValueProvider[] { } },
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(ScopeAttribute)), NamedAttributeValues = new Dictionary<string, IBindingSourceAttributeValueProvider>(), AttributeValues = new IBindingSourceAttributeValueProvider[] { } },
                        }
            };

            var bspStub = new BindingSourceProcessorStub();

            // Process type must be called first to ensure the binding source processer is in the correct state
            bspStub.ProcessType(stubType);
            bspStub.ProcessMethod(stubMethod);

            Assert.AreEqual(0, bspStub.HookBindings.Count, "A non static method with a non scenario specific hook should not be valid");
        }
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
 protected override void ProcessHooks(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     //nop - not needed for IDE integration
 }
        public void Non_static_method_in_non_abstract_class_should_be_valid()
        {
            var stubType = new BindingSourceType
            {
                IsGenericTypeDefinition = false,
                IsClass = true,
                Attributes = new[] { this.bindingSourceAttribute, }
            };

            var stubMethod = new BindingSourceMethod
                {
                    IsPublic = true,
                    IsStatic = false,
                    BindingMethod = new BindingMethod(new BindingType("Test", "Test"), "TestMethod", Enumerable.Empty<IBindingParameter>(), new BindingType("Test", "Test")),
                    Attributes = new[]
                        {
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(MethodBinding)) },
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(StepDefinitionAttribute)), NamedAttributeValues = new Dictionary<string, IBindingSourceAttributeValueProvider>(), AttributeValues = new IBindingSourceAttributeValueProvider[] {} },
                            new BindingSourceAttribute { AttributeType = new RuntimeBindingType(typeof(ScopeAttribute)), NamedAttributeValues = new Dictionary<string, IBindingSourceAttributeValueProvider>(), AttributeValues = new IBindingSourceAttributeValueProvider[] {}},
                        }
                };

            var bspStub = new BindingSourceProcessorStub();

            // Process type must be called first to ensure the binding source processer is in the correct state
            bspStub.ProcessType(stubType);
            bspStub.ProcessMethod(stubMethod);

            Assert.True(bspStub.StepDefinitionBindings.Count > 0, "A non static method in a non-abstract class should be valid");
        }
 protected virtual void ProcessStepDefinitions(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepDefinitionAttribute in bindingSourceMethod.Attributes.Where(IsStepDefinitionAttribute))
     {
         ProcessStepDefinitionAttribute(bindingSourceMethod, methodScopes, stepDefinitionAttribute);
     }
 }
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
        protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
        protected virtual bool ValidateMethod(BindingSourceMethod bindingSourceMethod)
        {
            if (currentBindingSourceType.IsAbstract && !bindingSourceMethod.IsStatic && 
                OnValidationError("Abstract binding types can have only static binding methods: {0}", bindingSourceMethod))
                    return false;

            return true;
        }
 protected override void ProcessStepArgumentTransformations(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     //nop - not needed for IDE integration
 }
        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 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));
        }
        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 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;
        }