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

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

            return(true);
        }
Exemplo n.º 8
0
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
 protected virtual void ProcessHooks(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var hookAttribute in bindingSourceMethod.Attributes.Where(IsHookAttribute))
     {
         ProcessHookAttribute(bindingSourceMethod, methodScopes, hookAttribute);
     }
 }
Exemplo n.º 19
0
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
Exemplo n.º 20
0
 protected virtual void ProcessStepArgumentTransformations(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepArgumentTransformationAttribute in bindingSourceMethod.Attributes.Where(IsStepArgumentTransformationAttribute))
     {
         ProcessStepArgumentTransformationAttribute(bindingSourceMethod, stepArgumentTransformationAttribute);
     }
 }
Exemplo n.º 21
0
        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");
        }
Exemplo n.º 22
0
 private void ProcessStepDefinitionAttribute(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes, BindingSourceAttribute stepDefinitionAttribute)
 {
     ApplyForScope(methodScopes, scope => ProcessStepDefinitionAttribute(bindingSourceMethod, stepDefinitionAttribute, scope));
 }
Exemplo n.º 23
0
 protected override void ProcessHooks(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     //nop - not needed for IDE integration
 }
Exemplo n.º 24
0
        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");
        }
Exemplo n.º 25
0
 protected virtual void ProcessStepDefinitions(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     foreach (var stepDefinitionAttribute in bindingSourceMethod.Attributes.Where(IsStepDefinitionAttribute))
     {
         ProcessStepDefinitionAttribute(bindingSourceMethod, methodScopes, stepDefinitionAttribute);
     }
 }
Exemplo n.º 26
0
        protected virtual bool ValidateStepArgumentTransformation(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepArgumentTransformationAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
Exemplo n.º 27
0
        protected virtual bool ValidateStepDefinition(BindingSourceMethod bindingSourceMethod, BindingSourceAttribute stepDefinitionAttribute)
        {
            if (!ValidateMethod(bindingSourceMethod))
                return false;

            return true;
        }
Exemplo n.º 28
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;
        }
Exemplo n.º 29
0
 protected override void ProcessStepArgumentTransformations(BindingSourceMethod bindingSourceMethod, BindingScope[] methodScopes)
 {
     //nop - not needed for IDE integration
 }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
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));
        }
Exemplo n.º 32
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);
            }
        }
Exemplo n.º 33
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));
        }
Exemplo n.º 34
-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;
        }