Example #1
0
        public void FindsPropertiesFromExplicitInterfaceImplementations()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(TestTypeWithInterfaces));
            var properties = finder.GetPropertyInfos();

            Assert.That(properties.Where(p => p.Name == "Remotion.ObjectBinding.UnitTests.BindableObject.ReflectionBasedPropertyFinderTestDomain.IExplicitTestInterface.InterfaceProperty").Count(), Is.EqualTo(1));
        }
Example #2
0
        public void IgnoresIndexedProperties()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(ClassWithReferenceType <object>));
            var properties = finder.GetPropertyInfos();

            Assert.That(properties.Where(p => p.Name == "Item").Count(), Is.EqualTo(0));
        }
Example #3
0
        public void FindsPropertiesFromImplicitInterfaceImplementations()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(TestTypeWithInterfaces));
            var properties = finder.GetPropertyInfos();

            Assert.That(properties.Where(p => p.Name == "InterfaceProperty").Count(), Is.EqualTo(1));
        }
Example #4
0
        public void IgnoresPropertiesWithOjectBindingVisibleFalseAttribute()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(ClassWithReferenceType <object>));
            var properties = finder.GetPropertyInfos();

            Assert.That(properties.Where(p => p.Name == "NotVisibleAttributeScalar").Count(), Is.EqualTo(0));
        }
Example #5
0
        public void InterfaceProperties_PropertyWithoutGetter()
        {
            var propertyInfos     = new ReflectionBasedPropertyFinder(typeof(TestTypeWithInterfaces)).GetPropertyInfos().ToArray();
            var interfaceProperty = (InterfaceImplementationPropertyInformation)(from p in propertyInfos
                                                                                 where p.Name == "NonGetterInterfaceProperty"
                                                                                 select p).SingleOrDefault();

            Assert.That(interfaceProperty, Is.Null);
        }
Example #6
0
        public void GetPropertyInfos_MixedProperties()
        {
            var concreteType         = TypeFactory.GetConcreteType(typeof(ClassWithMixedProperty));
            var propertyFinder       = new ReflectionBasedPropertyFinder(concreteType);
            var propertyInformations = propertyFinder.GetPropertyInfos().OrderBy(pi => pi.Name).ToArray();

            Assert.That(propertyInformations.Length, Is.EqualTo(10));

            var propertyInformation_0 = propertyInformations[0];

            Assert.That(propertyInformation_0, Is.TypeOf(typeof(InterfaceImplementationPropertyInformation)));
            Assert.That(propertyInformation_0.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(ClassWithMixedProperty))));
            Assert.That(propertyInformation_0.Name, Is.EqualTo("InterfaceProperty"));

            var propertyInformation_1 = propertyInformations[1];

            Assert.That(propertyInformation_1, Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformation_1.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(MixinAddingProperty))));
            Assert.That(propertyInformation_1.Name, Is.EqualTo("MixedProperty"));

            var propertyInformation_2 = propertyInformations[4];

            Assert.That(propertyInformation_2, Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformation_2.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(MixinAddingProperty))));
            Assert.That(propertyInformation_2.Name, Is.EqualTo("MixedReadOnlyProperty"));

            var propertyInformation_3 = propertyInformations[5];

            Assert.That(propertyInformation_3, Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformation_3.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(MixinAddingProperty))));
            Assert.That(propertyInformation_3.Name, Is.EqualTo("MixedReadOnlyPropertyHavingSetterOnMixin"));

            var propertyInformation_4 = propertyInformations[6];

            Assert.That(propertyInformation_4, Is.TypeOf(typeof(PropertyInfoAdapter)));
            Assert.That(propertyInformation_4.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(ClassWithMixedProperty))));
            Assert.That(propertyInformation_4.Name, Is.EqualTo("PublicExistingProperty"));

            var propertyInformation_5 = propertyInformations[7];

            Assert.That(propertyInformation_5, Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformation_5.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(BaseOfMixinAddingProperty))));
            Assert.That(
                propertyInformation_5.Name,
                Is.EqualTo("Remotion.ObjectBinding.UnitTests.TestDomain.IBaseOfMixinAddingProperty.ExplicitMixedPropertyBase"));

            var propertyInformation_6 = propertyInformations[8];

            Assert.That(propertyInformation_6, Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformation_6.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(MixinAddingProperty))));
            Assert.That(
                propertyInformation_6.Name,
                Is.EqualTo("Remotion.ObjectBinding.UnitTests.TestDomain.IMixinAddingProperty.ExplicitMixedProperty"));
        }
Example #7
0
        public void ImplicitInterfaceProperties_GetInterfaceBasedPropertyInfo()
        {
            var propertyInfos         = new ReflectionBasedPropertyFinder(typeof(TestTypeWithInterfaces)).GetPropertyInfos().ToArray();
            var interfaceImplProperty = (from p in propertyInfos
                                         where p.Name == "InterfaceProperty"
                                         select p).Single();

            Assert.That(interfaceImplProperty, Is.TypeOf(typeof(InterfaceImplementationPropertyInformation)));
            Assert.That(interfaceImplProperty.DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(TestTypeWithInterfaces))));
            Assert.That(interfaceImplProperty.FindInterfaceDeclarations().Single().DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(ITestInterface))));
        }
Example #8
0
        public void IgnoresBasePropertiesWithSameName()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(TestTypeHidingProperties));
            var properties = new List <PropertyInfo> (UnwrapCollection(finder.GetPropertyInfos()));

            Assert.That(
                properties,
                Is.EquivalentTo(
                    new object[]
            {
                typeof(TestTypeHidingProperties).GetProperty("PublicInstanceProperty"),
                typeof(TestTypeHidingProperties).GetProperty("BasePublicInstanceProperty")
            }));
        }
Example #9
0
        public void ReturnsPublicInstancePropertiesFromThisAndBase()
        {
            var finder     = new ReflectionBasedPropertyFinder(typeof(TestType));
            var properties = new List <PropertyInfo> (UnwrapCollection(finder.GetPropertyInfos()));

            Assert.That(
                properties,
                Is.EquivalentTo(
                    new object[]
            {
                typeof(TestType).GetProperty("PublicInstanceProperty"),
                typeof(BaseTestType).GetProperty("BasePublicInstanceProperty")
            }));
        }
Example #10
0
        public void GetPropertyInfos_MixedProperties_DuplicatesNotRemoved()
        {
            var concreteType         = TypeFactory.GetConcreteType(typeof(ClassWithMixedPropertyOfSameName));
            var propertyFinder       = new ReflectionBasedPropertyFinder(concreteType);
            var propertyInformations = propertyFinder.GetPropertyInfos().OrderBy(pi => pi.Name).ThenBy(pi => pi.DeclaringType.FullName).ToArray();

            Assert.That(propertyInformations[0], Is.TypeOf(typeof(PropertyInfoAdapter)));
            Assert.That(propertyInformations[0].DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(ClassWithMixedPropertyOfSameName))));
            Assert.That(propertyInformations[0].Name, Is.EqualTo("MixedProperty"));

            Assert.That(propertyInformations[1], Is.TypeOf(typeof(MixinIntroducedPropertyInformation)));
            Assert.That(propertyInformations[1].DeclaringType, Is.SameAs(TypeAdapter.Create(typeof(MixinAddingProperty))));
            Assert.That(propertyInformations[1].Name, Is.EqualTo("MixedProperty"));
        }