Exemplo n.º 1
0
        public void GetOriginalDeclaration_WithPropertyIsOverriddenDeclaration()
        {
            var propertyInfo = typeof(DerivedClassWithReferenceType <object>).GetProperty("PropertyWithPrivateSetter");
            var adapter      = PropertyInfoAdapter.Create(propertyInfo);

            var result = adapter.GetOriginalDeclaration();

            Assert.That(result, Is.Not.Null);

            var expectedPropertyInfo = typeof(ClassWithReferenceType <object>).GetProperty("PropertyWithPrivateSetter");

            CheckPropertyInfo(expectedPropertyInfo, (PropertyInfoAdapter)result);
        }
Exemplo n.º 2
0
        public void GetAccessors_Setter()
        {
            var propertyInfo = typeof(ClassWithReferenceType <object>).GetProperty("ImplicitInterfaceWriteOnlyScalar");
            var adapter      = PropertyInfoAdapter.Create(propertyInfo);

            var result = adapter.GetAccessors(false);

            Assert.That(result.Length, Is.EqualTo(1));

            var expectedMethodInfo = typeof(ClassWithReferenceType <object>).GetMethod("set_ImplicitInterfaceWriteOnlyScalar");

            CheckMethodInfo(expectedMethodInfo, (MethodInfoAdapter)result[0]);
        }
Exemplo n.º 3
0
        public void IsVirtualRelationEndPoint_UnidirectionalRelation()
        {
            var type         = typeof(ClassWithRealRelationEndPoints);
            var propertyInfo = PropertyInfoAdapter.Create(type.GetProperty("Unidirectional"));
            var relationEndPointReflector = new RdbmsRelationEndPointReflector(
                ClassDefinitionObjectMother.CreateClassDefinition(classType: type),
                propertyInfo,
                Configuration.NameResolver,
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);

            Assert.That(relationEndPointReflector.IsVirtualEndRelationEndpoint(), Is.False);
        }
Exemplo n.º 4
0
        public void GetAccessors_NonPublicSetter_NonPublicFalse()
        {
            var propertyInfo = typeof(ClassWithReferenceType <object>).GetProperty("PropertyWithPrivateSetter");
            var adapter      = PropertyInfoAdapter.Create(propertyInfo);

            var result = adapter.GetAccessors(false);

            Assert.That(result.Length, Is.EqualTo(1));

            var expectedMethodInfo = typeof(ClassWithReferenceType <object>).GetMethod("get_PropertyWithPrivateSetter");

            CheckMethodInfo(expectedMethodInfo, (MethodInfoAdapter)result[0]);
        }
Exemplo n.º 5
0
        private PropertyReflector CreatePropertyReflector(string property)
        {
            Type type         = typeof(ClosedGenericClassWithRealRelationEndPoints);
            var  propertyInfo =
                PropertyInfoAdapter.Create(type.GetProperty(property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));

            return(new PropertyReflector(
                       _classDefinition,
                       propertyInfo,
                       Configuration.NameResolver,
                       PropertyMetadataProvider,
                       DomainModelConstraintProviderStub));
        }
Exemplo n.º 6
0
        public void IsVirtualEndRelationEndpoint_WithCollectionPropertyAndWithoutAttribute()
        {
            var type         = typeof(ClassWithInvalidUnidirectionalRelation);
            var propertyInfo = PropertyInfoAdapter.Create(type.GetProperty("LeftSide"));
            var relationEndPointReflector = RelationEndPointReflector.CreateRelationEndPointReflector(
                ClassDefinitionObjectMother.CreateClassDefinition(classType: type),
                propertyInfo,
                Configuration.NameResolver,
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);

            Assert.That(relationEndPointReflector.IsVirtualEndRelationEndpoint(), Is.False);
        }
Exemplo n.º 7
0
        public void CreateRelationEndPointReflector()
        {
            var type         = typeof(ClassWithVirtualRelationEndPoints);
            var propertyInfo = PropertyInfoAdapter.Create(type.GetProperty("NoAttribute"));

            Assert.IsInstanceOf(
                typeof(RdbmsRelationEndPointReflector),
                RelationEndPointReflector.CreateRelationEndPointReflector(
                    ClassDefinitionObjectMother.CreateClassDefinition(classType: type),
                    propertyInfo,
                    Configuration.NameResolver,
                    PropertyMetadataProvider,
                    DomainModelConstraintProviderStub));
        }
        public void CanRead_WithSecurableObject_WithoutSetter_UsesNullMethodInfo_ReturnsResult()
        {
            var expectedResult = BooleanObjectMother.GetRandomBoolean();

            ExpectHasAccessOnObjectSecurityStrategy(expectedResult, GeneralAccessTypes.Read);

            var bindableProperty = new StubPropertyBase(
                GetPropertyParameters(PropertyInfoAdapter.Create(typeof(ClassWithReferenceType <string>).GetProperty("PropertyWithNoGetter"))));

            var actualResult = _strategy.CanRead(_securableObject, bindableProperty);

            Assert.That(actualResult, Is.EqualTo(expectedResult));
            _objectSecurityStrategyMock.VerifyAllExpectations();
        }
Exemplo n.º 9
0
        private static PropertyInfoAdapter GetMemberAsProperty(SqlEntityExpression originatingEntity, MemberInfo memberInfo)
        {
            var property = memberInfo as PropertyInfo;

            if (property == null)
            {
                throw new UnmappedItemException(
                          string.Format(
                              "Field '{0}.{1}' cannot be used in a query because it is not a mapped member.",
                              originatingEntity.Type.Name,
                              memberInfo.Name));
            }
            return(PropertyInfoAdapter.Create(property));
        }
Exemplo n.º 10
0
        public void GetMetadata_ForMandatory()
        {
            var propertyInfo = PropertyInfoAdapter.Create(_classType.GetProperty("NotNullable"));
            var relationEndPointReflector = CreateRelationEndPointReflector(propertyInfo);

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

            IRelationEndPointDefinition actual = relationEndPointReflector.GetMetadata();

            Assert.IsInstanceOf(typeof(VirtualRelationEndPointDefinition), actual);
            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithVirtualRelationEndPoints.NotNullable"));
            Assert.That(actual.IsMandatory, Is.True);
            DomainModelConstraintProviderStub.VerifyAllExpectations();
        }
Exemplo n.º 11
0
        public void FindInterfaceDeclarations_ImplicitInterfaceImplementation()
        {
            var adapter = PropertyInfoAdapter.Create(typeof(ClassWithReferenceType <object>).GetProperty("ImplicitInterfaceScalar"));

            var result = adapter.FindInterfaceDeclarations();

            var expectedPropertyInfos =
                new[]
            {
                MemberInfoFromExpressionUtility.GetProperty((IInterfaceWithReferenceType <object> obj) => obj.ImplicitInterfaceScalar)
            };

            CheckUnorderedPropertyInfos(expectedPropertyInfos, result.Cast <PropertyInfoAdapter>());
        }
Exemplo n.º 12
0
        public void Initialize_IndexedProperty()
        {
            IPropertyInformation propertyInfo =
                PropertyInfoAdapter.Create(typeof(ClassWithReferenceType <SimpleReferenceType>).GetProperty("Item", new[] { typeof(int) }));

            new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    isRequired: true,
                    isReadOnly: true));
        }
        public void SetUp()
        {
            _addingComponentPropertyRuleMock = MockRepository.GenerateStrictMock <IAddingComponentPropertyRule>();
            _addingComponentPropertyRuleMock.Stub(stub => stub.Property).Return(PropertyInfoAdapter.Create(typeof(Customer).GetProperty("UserName")));

            _addingComponentPropertyMetaValidationRuleMock = MockRepository.GenerateStrictMock <IAddingComponentPropertyMetaValidationRule>();
            _addingComponentPropertyRuleMock.Stub(stub => stub.Property).Return(PropertyInfoAdapter.Create(typeof(Customer).GetProperty("UserName")));

            _addingComponentBuilder = new AddingComponentRuleBuilder <Customer, string> (
                _addingComponentPropertyRuleMock,
                _addingComponentPropertyMetaValidationRuleMock);

            _propertyValidatorStub = MockRepository.GenerateStub <IPropertyValidator>();
        }
        public void ResolveDefinition_ClassWithSameInterfaceAsMixin_BothStorageClassPersistent()
        {
            var property = PropertyInfoAdapter.Create(typeof(IInterfaceWithProperty).GetProperty("Property"));

            var classDefinition = GetTypeDefinition(typeof(ClassWithSameInterfaceAsMixinWithStorageClassPersistent));

            Assert.That(() => ReflectionBasedPropertyResolver.ResolveDefinition(
                            property, classDefinition, classDefinition.GetPropertyDefinition),
                        Throws.TypeOf <InvalidOperationException> ().With.Message.EqualTo(
                            "The property 'Property' is ambiguous, it is implemented by the following types valid in the context of class "
                            + "'ClassWithSameInterfaceAsMixinWithStorageClassPersistent': "
                            + "'Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.ReflectionBasedPropertyResolver.ClassWithSameInterfaceAsMixinWithStorageClassPersistent', "
                            + "'Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.ReflectionBasedPropertyResolver.MixinWithPersistentProperty'."));
        }
Exemplo n.º 15
0
        public void SetUp()
        {
            _property = PropertyInfoAdapter.Create(typeof(Customer).GetProperty("UserName"));

            _userNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.UserName);
            _lastNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName);

            _stubPropertyValidator1 = new StubPropertyValidator();
            _stubPropertyValidator2 = new NotEmptyValidator(null);
            _stubPropertyValidator3 = new NotEqualValidator("gfsf");

            _propertyValidatorExtractorMock = MockRepository.GenerateStrictMock <IPropertyValidatorExtractor>();

            _addingComponentPropertyRule = AddingComponentPropertyRule.Create(_userNameExpression, typeof(CustomerValidationCollector1));
        }
Exemplo n.º 16
0
        public void SetValue_WithIndexerProperty_WithOneParameter()
        {
            var scalar       = new SimpleReferenceType();
            var instanceMock = MockRepository.GenerateMock <IInterfaceWithReferenceType <SimpleReferenceType> >();

            instanceMock.Expect(mock => mock[10] = scalar);
            instanceMock.Replay();

            var interfaceDeclarationProperty = typeof(IInterfaceWithReferenceType <SimpleReferenceType>).GetProperty("Item", new[] { typeof(int) });

            _implicitInterfaceAdapter = PropertyInfoAdapter.Create(interfaceDeclarationProperty);

            _implicitInterfaceAdapter.SetValue(instanceMock, scalar, new object[] { 10 });
            instanceMock.VerifyAllExpectations();
        }
Exemplo n.º 17
0
        public void BidirectionalRelation_PropertyTypeDomainObject()
        {
            var endPointDefinition = new VirtualRelationEndPointDefinition(
                _classDefinition,
                "DomainObjectPropertyWithBidirectionalAttribute",
                false,
                CardinalityType.One,
                null,
                PropertyInfoAdapter.Create(typeof(RelationEndPointPropertyClass).GetProperty("DomainObjectPropertyWithBidirectionalAttribute")));
            var relationDefinition = new RelationDefinition("Test", endPointDefinition, endPointDefinition);

            var validationResult = _validationRule.Validate(relationDefinition);

            AssertMappingValidationResult(validationResult, true, null);
        }
Exemplo n.º 18
0
        public void PropertyWithNoDBBidirectionalRelationAttribute()
        {
            var endPointDefinition = new VirtualRelationEndPointDefinition(
                _classDefinition,
                "PropertyWithNoDbBidirectionalRelationAttribute",
                false,
                CardinalityType.One,
                null,
                PropertyInfoAdapter.Create(typeof(ForeignKeyIsSupportedClass).GetProperty("PropertyWithNoDbBidirectionalRelationAttribute")));
            var relationDefinition = new RelationDefinition("Test", endPointDefinition, endPointDefinition);

            var validationResult = _validationRule.Validate(relationDefinition);

            AssertMappingValidationResult(validationResult, true, null);
        }
        public void Equals_ChecksPropertyInfo()
        {
            Assert.That(_mixinIntroducedPropertyInformation.Equals(null), Is.False);
            Assert.That(_mixinIntroducedPropertyInformation.Equals("Test"), Is.False);
            Assert.That(
                _mixinIntroducedPropertyInformation.Equals(
                    new MixinIntroducedPropertyInformation(
                        new InterfaceImplementationPropertyInformation(
                            PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")),
                            PropertyInfoAdapter.Create(typeof(string).GetProperty("Length"))))),
                Is.False);

            Assert.That(
                _mixinIntroducedPropertyInformation.Equals(new MixinIntroducedPropertyInformation(_interfaceImplementationPropertyInformation)), Is.True);
        }
Exemplo n.º 20
0
        public void SetUp()
        {
            _property = typeof(ClassWithReferenceType <SimpleReferenceType>).GetProperty("NotVisibleAttributeScalar");
            _adapter  = PropertyInfoAdapter.Create(_property);

            _explicitInterfaceImplementationProperty = typeof(ClassWithReferenceType <SimpleReferenceType>).GetProperty(
                "Remotion.Reflection.UnitTests.TestDomain.MemberInfoAdapter.IInterfaceWithReferenceType<T>.ExplicitInterfaceScalar",
                BindingFlags.NonPublic | BindingFlags.Instance);
            _explicitInterfaceAdapter = PropertyInfoAdapter.Create(_explicitInterfaceImplementationProperty);

            _implicitInterfaceImplementationProperty = typeof(ClassWithReferenceType <SimpleReferenceType>).GetProperty(
                "ImplicitInterfaceScalar",
                BindingFlags.Public | BindingFlags.Instance);
            _implicitInterfaceAdapter = PropertyInfoAdapter.Create(_implicitInterfaceImplementationProperty);
        }
Exemplo n.º 21
0
        public void NoCollectionProperty_ContainsForeignKeyIsTrue()
        {
            var endPointDefinition = new VirtualRelationEndPointDefinition(
                _classDefinition,
                "NoCollectionProperty_ContainsForeignKey",
                false,
                CardinalityType.One,
                null,
                PropertyInfoAdapter.Create(typeof(ForeignKeyIsSupportedClass).GetProperty("NoCollectionProperty_ContainsForeignKey")));
            var relationDefinition = new RelationDefinition("Test", endPointDefinition, endPointDefinition);

            var validationResult = _validationRule.Validate(relationDefinition);

            AssertMappingValidationResult(validationResult, true, null);
        }
Exemplo n.º 22
0
        public void TryGetPropertyDisplayName()
        {
            var service = SafeServiceLocator.Current.GetInstance <IMemberInformationGlobalizationService>();

            string resourceValue;

            Assert.That(
                service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithShortIdentifier")),
                    TypeAdapter.Create(typeof(ClassWithResources)),
                    out resourceValue),
                Is.True);
            Assert.That(resourceValue, Is.EqualTo("Short Property ID"));

            Assert.That(
                service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")),
                    TypeAdapter.Create(typeof(ClassWithResources)),
                    out resourceValue),
                Is.True);
            Assert.That(resourceValue, Is.EqualTo("Long Property ID"));

            Assert.That(
                service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithoutResources")),
                    TypeAdapter.Create(typeof(ClassWithResources)),
                    out resourceValue),
                Is.False);
            Assert.That(resourceValue, Is.Null);

            Assert.That(
                service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")),
                    TypeAdapter.Create(typeof(ClassWithoutMultiLingualResourcesAttributes)),
                    out resourceValue),
                Is.False);
            Assert.That(resourceValue, Is.Null);

            Assert.That(
                () => service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")),
                    TypeAdapter.Create(typeof(ClassWithMissingResources)),
                    out resourceValue),
                Throws.TypeOf <MissingManifestResourceException>()
                .With.Message.EqualTo(
                    "Could not find any resources appropriate for the neutral culture. "
                    + "Make sure 'MissingResources.resources' was correctly embedded into assembly 'Remotion.Globalization.UnitTests' at compile time."));
        }
        public void TryGetPropertyDisplayName_WithMultiLingualNameAttributeAppliedToOverride_ThrowsInvalidOperationException()
        {
            var service = SafeServiceLocator.Current.GetInstance <IMemberInformationGlobalizationService>();

            string resourceValue;

            Assert.That(
                () =>
                service.TryGetPropertyDisplayName(
                    PropertyInfoAdapter.Create(
                        typeof(DerivedClassWithMultiLingualNameAttribute)
                        .GetProperty("PropertyWithMultiLingualNameAttributeOnOverride")),
                    TypeAdapter.Create(typeof(ClassWithoutMultiLingualResourcesAttributes)),
                    out resourceValue),
                Throws.InvalidOperationException);
        }
        public void EqualsTest()
        {
            Assert.That(_interfaceImplementationPropertyInformation.Equals(null), Is.False);
            Assert.That(_interfaceImplementationPropertyInformation.Equals("Test"), Is.False);
            Assert.That(
                _interfaceImplementationPropertyInformation.Equals(
                    new InterfaceImplementationPropertyInformation(
                        PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")),
                        PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")))),
                Is.False);

            Assert.That(
                _interfaceImplementationPropertyInformation.Equals(
                    new InterfaceImplementationPropertyInformation(_implementationPropertyInformationStub, _declarationPropertyInformationStub)),
                Is.True);
        }
Exemplo n.º 25
0
        public void TryGetPropertyDisplayName()
        {
            var service = SafeServiceLocator.Current.GetInstance <IMemberInformationGlobalizationService>();

            using (new CultureScope("it", "de-AT"))
            {
                string resourceValue;
                Assert.That(
                    service.TryGetPropertyDisplayName(
                        PropertyInfoAdapter.Create(typeof(ClassWithMultiLingualNameAttribute).GetProperty("PropertyWithMultiLingualNameAttribute")),
                        TypeAdapter.Create(typeof(ClassWithResources)),
                        out resourceValue),
                    Is.True);
                Assert.That(resourceValue, Is.EqualTo("Resource-based Property ID"));
            }
        }
Exemplo n.º 26
0
        public void SetValue_WithIndexerProperty_WithThreeParameters()
        {
            SimpleReferenceType scalar = new SimpleReferenceType();
            IInterfaceWithReferenceType <SimpleReferenceType> instanceMock = MockRepository.GenerateMock <IInterfaceWithReferenceType <SimpleReferenceType> >();

            instanceMock.Expect(mock => mock[10, new DateTime(2000, 1, 1), "foo"] = scalar);
            instanceMock.Replay();

            var interfaceDeclarationProperty = typeof(IInterfaceWithReferenceType <SimpleReferenceType>)
                                               .GetProperty("Item", new[] { typeof(int), typeof(DateTime), typeof(string) });

            _implicitInterfaceAdapter = PropertyInfoAdapter.Create(interfaceDeclarationProperty);

            _implicitInterfaceAdapter.SetValue(instanceMock, scalar, new object[] { 10, new DateTime(2000, 1, 1), "foo" });
            instanceMock.VerifyAllExpectations();
        }
Exemplo n.º 27
0
        public void FindInterfaceDeclarations_ExplicitInterfaceImplementation_ReadOnlyProperty()
        {
            var adapter = PropertyInfoAdapter.Create(typeof(ClassWithReferenceType <object>).GetProperty(
                                                         "Remotion.Reflection.UnitTests.TestDomain.MemberInfoAdapter.IInterfaceWithReferenceType<T>.ExplicitInterfaceReadOnlyScalar",
                                                         BindingFlags.Instance | BindingFlags.NonPublic));

            var result = adapter.FindInterfaceDeclarations();

            var expectedPropertyInfos =
                new[]
            {
                MemberInfoFromExpressionUtility.GetProperty((IInterfaceWithReferenceType <object> obj) => obj.ExplicitInterfaceReadOnlyScalar)
            };

            CheckUnorderedPropertyInfos(expectedPropertyInfos, result.Cast <PropertyInfoAdapter> ());
        }
Exemplo n.º 28
0
        public void FindInterfaceDeclarations_MultipleDeclarations()
        {
            var propertyInfo = MemberInfoFromExpressionUtility.GetProperty((DomainType obj) => obj.PropertyDeclaredByMultipleInterfaces);
            var adapter      = PropertyInfoAdapter.Create(propertyInfo);

            var result = adapter.FindInterfaceDeclarations();

            var expectedPropertyInfos =
                new[]
            {
                MemberInfoFromExpressionUtility.GetProperty((IInterface1 obj) => obj.PropertyDeclaredByMultipleInterfaces),
                MemberInfoFromExpressionUtility.GetProperty((IInterface2 obj) => obj.PropertyDeclaredByMultipleInterfaces)
            };

            CheckUnorderedPropertyInfos(expectedPropertyInfos, result.Cast <PropertyInfoAdapter>());
        }
        public void ResolveDefinition_ExplicitMixinProperty_FromInterfaceProperty()
        {
            var property = PropertyInfoAdapter.Create(typeof(IInterfaceWithProperty).GetProperty("Property"));

            var classDefinition = GetTypeDefinition(typeof(ClassWithMixinWithPersistentPropertyExplicitImplementation));
            var result          = ReflectionBasedPropertyResolver.ResolveDefinition(property, classDefinition, classDefinition.GetPropertyDefinition);

            var implementationPropertyName = property.DeclaringType.FullName + "." + property.Name;
            var expected = GetPropertyDefinition(
                typeof(ClassWithMixinWithPersistentPropertyExplicitImplementation),
                typeof(MixinWithPersistentPropertyExplicitImplementation),
                implementationPropertyName);

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.SameAs(expected));
        }
Exemplo n.º 30
0
        public void GetAccessors_NonPublicSetter_NonPublicTrue()
        {
            var propertyInfo = typeof(ClassWithReferenceType <object>).GetProperty("PropertyWithPrivateSetter");
            var adapter      = PropertyInfoAdapter.Create(propertyInfo);

            var result = adapter.GetAccessors(true);

            Assert.That(result.Length, Is.EqualTo(2));

            var expectedMethodInfo0 = typeof(ClassWithReferenceType <object>).GetMethod("get_PropertyWithPrivateSetter");
            var expectedMethodInfo1 = typeof(ClassWithReferenceType <object>).GetMethod(
                "set_PropertyWithPrivateSetter", BindingFlags.Instance | BindingFlags.NonPublic);

            CheckMethodInfo(expectedMethodInfo0, (MethodInfoAdapter)result[0]);
            CheckMethodInfo(expectedMethodInfo1, (MethodInfoAdapter)result[1]);
        }