Ejemplo n.º 1
0
 private void ProcessCodeFunctions(CodeClass codeClass, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     foreach (var codeFunction in codeClass.Children.OfType<CodeFunction>())
     {
         var bindingSourceMethod = CreateBindingSourceMethod(codeFunction, bindingSourceType, bindingSourceProcessor);
         if (bindingSourceMethod != null)
             bindingSourceProcessor.ProcessMethod(bindingSourceMethod);
     }
 }
Ejemplo n.º 2
0
 private BindingSourceMethod CreateBindingSourceMethod(MethodDefinition methodDefinition, BindingSourceType bindingSourceType, IBindingSourceProcessor bindingSourceProcessor)
 {
     return new BindingSourceMethod
                {
                    BindingMethod = new BindingMethod(bindingSourceType.BindingType, methodDefinition.Name, GetParameters(methodDefinition), GetReturnType(methodDefinition)), 
                    IsPublic = methodDefinition.IsPublic,
                    IsStatic = methodDefinition.IsStatic,
                    Attributes = GetAttributes(methodDefinition.CustomAttributes.Where(attr => bindingSourceProcessor.CanProcessTypeAttribute(attr.AttributeType.FullName)))
                };
 }
Ejemplo n.º 3
0
        public void Non_class_should__not_be_valid()
        {
            var stubType = new BindingSourceType
            {
                IsClass = false,
                Attributes = new[] { this.bindingSourceAttribute, }
            };

            var result = this.BindingSourceProcessorUnderTest.ProcessType(stubType);
            Assert.IsFalse(result, "Non-class should be not a valid type");
        }
Ejemplo n.º 4
0
        public void Class_should_be_valid()
        {
            var stubType = new BindingSourceType
                {
                    IsClass = true,
                    Attributes = new [] { this.bindingSourceAttribute }
                };

            var result = this.BindingSourceProcessorUnderTest.ProcessType(stubType);
            Assert.IsTrue(result, "Class should be a valid type");
        }
Ejemplo n.º 5
0
        public void Non_generic_type_Definition_should_not_be_valid()
        {
            var stubType = new BindingSourceType
            {
                IsClass = true,
                IsGenericTypeDefinition = false,
                Attributes = new[] { this.bindingSourceAttribute, }
            };

            var result = this.BindingSourceProcessorUnderTest.ProcessType(stubType);
            Assert.IsTrue(result, "Non generic type definition should be a valid type");
        }
Ejemplo n.º 6
0
 private BindingSourceMethod CreateBindingSourceMethod(CodeFunction codeFunction, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     try
     {
         var filteredAttributes = codeFunction.Attributes.Cast<CodeAttribute2>().Where(attr => bindingSourceProcessor.CanProcessTypeAttribute(attr.FullName)).ToArray();
         return bindingReflectionFactory.CreateBindingSourceMethod(codeFunction, bindingSourceType, filteredAttributes);
     }
     catch (Exception ex)
     {
         tracer.Trace("CreateBindingSourceMethod error: {0}", this, ex);
         return null;
     }
 }
Ejemplo n.º 7
0
        public bool ProcessType(BindingSourceType bindingSourceType)
        {
            typeScopes = null;

            if (!IsBindingType(bindingSourceType))
                return false;

            if (!ValidateType(bindingSourceType))
                return false;

            currentBindingSourceType = bindingSourceType;
            typeScopes = GetScopes(bindingSourceType.Attributes).ToArray();
            return true;
        }
Ejemplo n.º 8
0
        protected virtual bool ValidateType(BindingSourceType bindingSourceType)
        {
            if (!bindingSourceType.IsClass &&
                OnValidationError("Binding types must be classes: {0}", bindingSourceType))
            {
                return(false);
            }

            if (bindingSourceType.IsGenericTypeDefinition &&
                OnValidationError("Binding types cannot be generic: {0}", bindingSourceType))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
        public bool ProcessType(BindingSourceType bindingSourceType)
        {
            typeScopes = null;

            if (!IsBindingType(bindingSourceType))
            {
                return(false);
            }

            if (!ValidateType(bindingSourceType))
            {
                return(false);
            }

            currentBindingSourceType = bindingSourceType;
            typeScopes = GetScopes(bindingSourceType.Attributes).ToArray();
            return(true);
        }
Ejemplo n.º 10
0
 private bool IsBindingType(BindingSourceType bindingSourceType)
 {
     return(bindingSourceType.Attributes.Any(attr => attr.AttributeType.TypeEquals(typeof(BindingAttribute))));
 }
Ejemplo n.º 11
0
 public void ProcessTypeDone()
 {
     currentBindingSourceType = null;
     typeScopes = null;
 }
Ejemplo n.º 12
0
 private bool IsBindingType(BindingSourceType bindingSourceType)
 {
     return bindingSourceType.Attributes.Any(attr => attr.AttributeType.TypeEquals(typeof(BindingAttribute)));
 }
Ejemplo n.º 13
0
 public void ProcessTypeDone()
 {
     currentBindingSourceType = null;
     typeScopes = null;
 }
Ejemplo n.º 14
0
        protected virtual bool ValidateType(BindingSourceType bindingSourceType)
        {
            if (!bindingSourceType.IsClass && 
                OnValidationError("Binding types must be classes: {0}", bindingSourceType))
                    return false;

            if (bindingSourceType.IsGenericTypeDefinition && 
                OnValidationError("Binding types cannot be generic: {0}", bindingSourceType))
                    return false;

            return true;
        }
Ejemplo n.º 15
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");
        }
Ejemplo n.º 16
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");
        }
Ejemplo n.º 17
0
 private BindingSourceMethod CreateBindingSourceMethod(CodeFunction codeFunction, BindingSourceType bindingSourceType, IdeBindingSourceProcessor bindingSourceProcessor)
 {
     var filteredAttributes = codeFunction.Attributes.Cast<CodeAttribute2>().Where(attr => bindingSourceProcessor.CanProcessTypeAttribute(attr.FullName)).ToArray();
     return bindingReflectionFactory.CreateBindingSourceMethod(codeFunction, bindingSourceType, filteredAttributes);
 }