Esempio n. 1
0
        public void GetMetadata_ForSealedBusinessObject_WithExistingMixin()
        {
            var mixinTargetType    = typeof(ManualBusinessObject);
            var businessObjectType = typeof(SealedBindableObject);

            Assertion.IsTrue(mixinTargetType.IsAssignableFrom(businessObjectType));

            using (MixinConfiguration.BuildNew()
                   .AddMixinToClass(
                       MixinKind.Extending,
                       mixinTargetType,
                       typeof(MixinStub),
                       MemberVisibility.Public,
                       Enumerable.Empty <Type>(),
                       Enumerable.Empty <Type>())
                   .EnterScope())
            {
                IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SealedBindableObject>), "Scalar");

                PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

                var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata();
                Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing);
            }
        }
Esempio n. 2
0
        private IBusinessObjectProperty GetMetadataFromPropertyReflector(string propertyName)
        {
            IPropertyInformation propertyInfo      = GetPropertyInfo(typeof(ClassWithAllDataTypes), propertyName);
            PropertyReflector    propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            return(propertyReflector.GetMetadata());
        }
        private IPropertyInformation EnsurePropertyDefinitionExisitsOnClassDefinition(
            ClassDefinition classDefinition,
            Type declaringType,
            string propertyName)
        {
            var propertyInfo =
                PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
            var propertyReflector = new PropertyReflector(
                classDefinition,
                propertyInfo,
                new ReflectionBasedMemberInformationNameResolver(),
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);
            var propertyDefinition = propertyReflector.GetMetadata();

            if (!classDefinition.MyPropertyDefinitions.Contains(propertyDefinition.PropertyName))
            {
                var propertyDefinitions = new PropertyDefinitionCollection(classDefinition.MyPropertyDefinitions, false);
                propertyDefinitions.Add(propertyDefinition);
                PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", propertyDefinitions);
                var endPoints = new RelationEndPointDefinitionCollection(classDefinition.MyRelationEndPointDefinitions, false);
                endPoints.Add(MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo));
                PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", endPoints);
            }

            return(propertyInfo);
        }
Esempio n. 4
0
        protected IEnumerable <PropertyBase> GetProperties()
        {
            IPropertyFinder propertyFinder = _metadataFactory.CreatePropertyFinder(_concreteType);

            Dictionary <string, PropertyBase> propertiesByName = new Dictionary <string, PropertyBase>();

            foreach (IPropertyInformation propertyInfo in propertyFinder.GetPropertyInfos())
            {
                PropertyReflector propertyReflector = _metadataFactory.CreatePropertyReflector(_concreteType, propertyInfo, _businessObjectProvider);
                PropertyBase      property          = propertyReflector.GetMetadata();
                if (propertiesByName.ContainsKey(property.Identifier))
                {
                    string message = string.Format(
                        "Type '{0}' has two properties called '{1}', this is currently not supported.",
                        TargetType.FullName,
                        property.Identifier);
                    throw new NotSupportedException(message);
                }
                else
                {
                    propertiesByName.Add(property.Identifier, property);
                }
            }

            return(propertiesByName.Values);
        }
Esempio n. 5
0
        public void GetMetadata_ForValueType()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <ValueTypeBindableObject>), "Scalar");

            PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata();

            Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing);
        }
Esempio n. 6
0
        public void GetMetadata_WithEnumBase()
        {
            IPropertyInformation IPropertyInformation = GetPropertyInfo(typeof(ClassWithReferenceType <Enum>), "Scalar");
            PropertyReflector    propertyReflector    = PropertyReflector.Create(IPropertyInformation, _businessObjectProvider);

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.TypeOf(typeof(NotSupportedProperty)));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("Scalar"));
        }
Esempio n. 7
0
        public void GetMetadata_WithEnumProperty()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithAllDataTypes> ("EnumProperty", DomainModelConstraintProviderStub);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ClassWithAllDataTypes.EnumProperty"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(ClassWithAllDataTypes.EnumType)));
            Assert.That(actual.IsNullable, Is.False);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(ClassWithAllDataTypes.EnumType.Value0));
        }
Esempio n. 8
0
        public void GetMetadata_WithNotNullableFromAttribute()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithRealRelationEndPoints> ("NotNullable", DomainModelConstraintProviderStub);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithRealRelationEndPoints.NotNullable"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(ObjectID)));
            Assert.That(actual.IsNullable, Is.True);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(null));
        }
Esempio n. 9
0
        public void GetMetadata_ForSingleProperty()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithAllDataTypes> ("BooleanProperty", DomainModelConstraintProviderStub);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            actual.SetStorageProperty(SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty());

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ClassWithAllDataTypes.BooleanProperty"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(bool)));
        }
Esempio n. 10
0
        public void GetPropertyDefinition()
        {
            PropertyReflector propertyReflector =
                PropertyReflector.Create(GetPropertyInfo(typeof(SimpleBusinessObjectClass), "String"), _bindableObjectProvider);
            var classReflector = new ClassReflector(
                typeof(ClassWithAllDataTypes),
                _bindableObjectProvider,
                BindableObjectMetadataFactory.Create(),
                _bindableObjectGlobalizationService);
            BindableObjectClass bindableObjectClass = classReflector.GetMetadata();

            CheckPropertyBase(propertyReflector.GetMetadata(), bindableObjectClass.GetPropertyDefinition("String"));
        }
Esempio n. 11
0
        public void GetMetadata_WithOptionalRelationProperty()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithGuidKey> (
                "ClassWithValidRelationsOptional", DomainModelConstraintProviderStub);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ClassWithGuidKey.ClassWithValidRelationsOptional"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(ObjectID)));
            Assert.That(actual.IsNullable, Is.True);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(null));
        }
Esempio n. 12
0
        public void GetMetadata_DefaultsToBaseImplementation()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithValueType <SimpleValueType>), "Scalar");

            using (MixinConfiguration.BuildNew().ForClass(typeof(PropertyReflector)).AddMixin <SimpleReferenceTypePropertyReflectorMixin> ().EnterScope())
            {
                PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

                IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

                Assert.That(businessObjectProperty, Is.TypeOf(typeof(NotSupportedProperty)));
                Assert.That(businessObjectProperty.Identifier, Is.EqualTo("Scalar"));
            }
        }
Esempio n. 13
0
        public PropertyDefinition CreatePropertyDefinition(ClassDefinition classDefinition, IPropertyInformation propertyInfo)
        {
            ArgumentUtility.CheckNotNull("classDefinition", classDefinition);
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            var propertyReflector = new PropertyReflector(
                classDefinition,
                propertyInfo,
                _nameResolver,
                _propertyMetadataProvider,
                _domainModelConstraintProvider);

            return(propertyReflector.GetMetadata());
        }
Esempio n. 14
0
        public void GetMetadata_SupportsPredifinedPropertyTypes()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithAllDataTypes), "Int32");

            using (MixinConfiguration.BuildNew().ForClass(typeof(PropertyReflector)).AddMixin <SimpleReferenceTypePropertyReflectorMixin> ().EnterScope())
            {
                PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

                IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

                Assert.That(businessObjectProperty, Is.TypeOf(typeof(Int32Property)));
                Assert.That(businessObjectProperty.Identifier, Is.EqualTo("Int32"));
            }
        }
Esempio n. 15
0
        private RdbmsRelationEndPointReflector CreateRelationEndPointReflector(string propertyName)
        {
            PropertyReflector  propertyReflector  = CreatePropertyReflector(propertyName);
            PropertyDefinition propertyDefinition = propertyReflector.GetMetadata();

            _classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true));

            return(new RdbmsRelationEndPointReflector(
                       _classDefinition,
                       propertyReflector.PropertyInfo,
                       Configuration.NameResolver,
                       PropertyMetadataProvider,
                       DomainModelConstraintProviderStub));
        }
Esempio n. 16
0
        public void GetPropertyDefinition_ForMixedProperty()
        {
            PropertyReflector propertyReflector = PropertyReflector.Create(
                GetPropertyInfo(
                    MixinTypeUtility.GetConcreteMixedType(typeof(ClassWithMixedProperty)),
                    typeof(IMixinAddingProperty).FullName + ".MixedProperty"),
                _bindableObjectProvider);
            var classReflector = new ClassReflector(
                typeof(ClassWithMixedProperty),
                _bindableObjectProvider,
                BindableObjectMetadataFactory.Create(),
                _bindableObjectGlobalizationService);
            BindableObjectClass bindableObjectClass = classReflector.GetMetadata();

            CheckPropertyBase(propertyReflector.GetMetadata(), bindableObjectClass.GetPropertyDefinition("MixedProperty"));
        }
Esempio n. 17
0
        public void GetMetadata_WithNullableFalse()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithStringProperties> ("NoAttribute", DomainModelConstraintProviderStub);

            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(propertyReflector.PropertyInfo))
            .Return(false);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithStringProperties.NoAttribute"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(string)));
            Assert.That(actual.IsNullable, Is.False);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(string.Empty));
        }
Esempio n. 18
0
        public void GetMetadata_WithReadOnlyAttributeScalar()
        {
            IPropertyInformation propertyInfo      = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ReadOnlyAttributeScalar");
            PropertyReflector    propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(SimpleReferenceType)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(propertyInfo));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("ReadOnlyAttributeScalar"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(SimpleReferenceType)));
            Assert.That(businessObjectProperty.IsList, Is.False);
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.True);
        }
Esempio n. 19
0
        public void GetMetadata_WithUndefinedEnum()
        {
            IPropertyInformation IPropertyInformation = GetPropertyInfo(typeof(ClassWithUndefinedEnumValue), "Scalar");
            PropertyReflector    propertyReflector    = PropertyReflector.Create(IPropertyInformation, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(EnumWithUndefinedValue)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(EnumerationProperty)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(IPropertyInformation));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("Scalar"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(EnumWithUndefinedValue)));
            Assert.That(businessObjectProperty.IsList, Is.False);
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.False);
        }
Esempio n. 20
0
        public void GetMetadata_WithNullableArray()
        {
            IPropertyInformation IPropertyInformation = GetPropertyInfo(typeof(ClassWithValueType <SimpleValueType>), "NullableArray");
            PropertyReflector    propertyReflector    = PropertyReflector.Create(IPropertyInformation, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(SimpleValueType)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(IPropertyInformation));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("NullableArray"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(SimpleValueType?[])));
            Assert.That(businessObjectProperty.IsList, Is.True);
            Assert.That(businessObjectProperty.ListInfo, Is.Not.Null);
            Assert.That(businessObjectProperty.ListInfo.ItemType, Is.SameAs(typeof(SimpleValueType?)));
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.False);
        }
Esempio n. 21
0
        public void GetMetadata_WithListOfT()
        {
            IPropertyInformation IPropertyInformation = GetPropertyInfo(typeof(ClassWithListProperties), "ListOfT");
            PropertyReflector    propertyReflector    = PropertyReflector.Create(IPropertyInformation, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(SimpleReferenceType)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(NotSupportedProperty)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(IPropertyInformation));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("ListOfT"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(List <SimpleReferenceType>)));
            Assert.That(businessObjectProperty.IsList, Is.True);
            Assert.That(businessObjectProperty.ListInfo, Is.Not.Null);
            Assert.That(businessObjectProperty.ListInfo.ItemType, Is.SameAs(typeof(SimpleReferenceType)));
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.False);
        }
        public void GetMetadata_WithMaximumLength()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithBinaryProperties> ("MaximumLength", DomainModelConstraintProviderStub);

            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(propertyReflector.PropertyInfo))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.GetMaxLength(propertyReflector.PropertyInfo))
            .Return(100);

            PropertyDefinition actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithBinaryProperties.MaximumLength"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(byte[])));
            Assert.That(actual.IsNullable, Is.True);
            Assert.That(actual.MaxLength, Is.EqualTo(100));
            Assert.That(actual.DefaultValue, Is.EqualTo(null));
        }
        private RelationReflector CreateRelationReflectorForProperty(
            ClassDefinition classDefinition, Type declaringType, string propertyName)
        {
            var propertyInfo =
                PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
            var propertyReflector = new PropertyReflector(
                classDefinition,
                propertyInfo,
                new ReflectionBasedMemberInformationNameResolver(),
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);
            var propertyDefinition = propertyReflector.GetMetadata();
            var properties         = new List <PropertyDefinition>();

            properties.Add(propertyDefinition);
            var propertyDefinitionsOfClass = (PropertyDefinitionCollection)PrivateInvoke.GetNonPublicField(classDefinition, "_propertyDefinitions");

            PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", null);
            if (propertyDefinitionsOfClass != null)
            {
                properties.AddRange(propertyDefinitionsOfClass);
            }
            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(properties, true));

            var endPoint  = MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo);
            var endPoints = new List <IRelationEndPointDefinition>();

            endPoints.Add(endPoint);
            var endPointDefinitionsOfClass = (RelationEndPointDefinitionCollection)PrivateInvoke.GetNonPublicField(classDefinition, "_relationEndPoints");

            PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", null);
            if (endPointDefinitionsOfClass != null)
            {
                endPoints.AddRange(endPointDefinitionsOfClass);
            }
            classDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection(endPoints, true));

            return(new RelationReflector(classDefinition, propertyInfo, new ReflectionBasedMemberInformationNameResolver(), PropertyMetadataProvider));
        }
Esempio n. 24
0
        public void GetMetadata_WithReadOnlyMixedPropertyHavingSetterOnMixin()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(
                MixinTypeUtility.GetConcreteMixedType(typeof(ClassWithMixedProperty)),
                typeof(IMixinAddingProperty),
                "MixedReadOnlyPropertyHavingSetterOnMixin");

            Assertion.IsTrue(propertyInfo is MixinIntroducedPropertyInformation);

            PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(string)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(propertyInfo));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("MixedReadOnlyPropertyHavingSetterOnMixin"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(string)));
            Assert.That(businessObjectProperty.IsList, Is.False);
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.True);
        }
Esempio n. 25
0
        private PropertyBase CreateProperty(Type type, string propertyName)
        {
            PropertyReflector propertyReflector = PropertyReflector.Create(GetPropertyInfo(type, propertyName), _bindableObjectProvider);

            return(propertyReflector.GetMetadata());
        }