Exemple #1
0
        public void GetMetadata_ForBaseClass()
        {
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BaseString")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BaseUnidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BasePrivateUnidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "String")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "UnidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "PrivateString")))
            .Return(true);

            ClassIDProviderStub.Stub(stub => stub.GetClassID(typeof(ClassWithDifferentProperties))).Return("ClassWithDifferentProperties");

            var classReflector = CreateClassReflector(typeof(ClassWithDifferentProperties));
            var expected       = CreateClassWithDifferentPropertiesClassDefinition();

            var actual = classReflector.GetMetadata(null);

            Assert.That(actual, Is.Not.Null);
            _classDefinitionChecker.Check(expected, actual);
            _endPointDefinitionChecker.Check(expected.MyRelationEndPointDefinitions, actual.MyRelationEndPointDefinitions, false);
        }
Exemple #2
0
        public void GetMetadata_ForMandatory()
        {
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "NotNullable")))
            .Return(false);

            RdbmsRelationEndPointReflector relationEndPointReflector = CreateRelationEndPointReflector("NotNullable");

            IRelationEndPointDefinition actual = relationEndPointReflector.GetMetadata();

            Assert.IsInstanceOf(typeof(RelationEndPointDefinition), actual);
            Assert.That(actual.IsMandatory, Is.True);
        }
Exemple #3
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();
        }
        public void GetMetadata_NoDomainObjectAndNoValueType_NullableFalse()
        {
            var propertyReflector = CreatePropertyReflector <ClassWithBinaryProperties> ("NoAttribute", DomainModelConstraintProviderStub);

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

            var actual = propertyReflector.GetMetadata();

            Assert.That(actual.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithBinaryProperties.NoAttribute"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(byte[])));
            Assert.That(actual.IsNullable, Is.False);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(new byte[0]));
        }
Exemple #5
0
        public void GetMetadata_WithNotNullableFromAttribute()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithExtensibleEnumProperties> (
                "NotNullable", 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.ClassWithExtensibleEnumProperties.NotNullable"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(TestExtensibleEnum)));
            Assert.That(actual.IsNullable, Is.False);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(TestExtensibleEnum.Values.Value1()));
        }
        public void GetMetadata_WithExtensibleEnumProperty()
        {
            PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithAllDataTypes> (
                "ExtensibleEnumProperty", 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.ClassWithAllDataTypes.ExtensibleEnumProperty"));
            Assert.That(actual.PropertyType, Is.SameAs(typeof(Color)));
            Assert.That(actual.IsNullable, Is.False);
            Assert.That(actual.MaxLength, Is.Null);
            Assert.That(actual.DefaultValue, Is.EqualTo(Color.Values.Blue()));
        }
Exemple #7
0
        public void GetMetadata_BidirectionalOneToOne()
        {
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BidirectionalOneToOne")))
            .Return(true);

            RdbmsRelationEndPointReflector relationEndPointReflector = CreateRelationEndPointReflector("BidirectionalOneToOne");

            IRelationEndPointDefinition actual = relationEndPointReflector.GetMetadata();

            Assert.IsInstanceOf(typeof(RelationEndPointDefinition), actual);
            RelationEndPointDefinition relationEndPointDefinition = (RelationEndPointDefinition)actual;

            Assert.That(relationEndPointDefinition.ClassDefinition, Is.SameAs(_classDefinition));
            Assert.That(relationEndPointDefinition.PropertyDefinition, Is.SameAs(GetPropertyDefinition("BidirectionalOneToOne")));
            Assert.That(relationEndPointDefinition.RelationDefinition, Is.Null);
        }
        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));
        }
Exemple #9
0
        public void GetMetadata_BidirectionalOneToOne()
        {
            var propertyInfo = PropertyInfoAdapter.Create(_classType.GetProperty("BidirectionalOneToOne"));
            var relationEndPointReflector = CreateRelationEndPointReflector(propertyInfo);

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

            IRelationEndPointDefinition actual = relationEndPointReflector.GetMetadata();

            Assert.IsInstanceOf(typeof(VirtualRelationEndPointDefinition), actual);
            VirtualRelationEndPointDefinition relationEndPointDefinition = (VirtualRelationEndPointDefinition)actual;

            Assert.That(relationEndPointDefinition.ClassDefinition, Is.SameAs(_classDefinition));
            Assert.That(relationEndPointDefinition.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithVirtualRelationEndPoints.BidirectionalOneToOne"));
            Assert.That(relationEndPointDefinition.PropertyInfo.PropertyType, Is.SameAs(typeof(ClassWithRealRelationEndPoints)));
            Assert.That(relationEndPointDefinition.Cardinality, Is.EqualTo(CardinalityType.One));
            Assert.That(relationEndPointDefinition.RelationDefinition, Is.Null);
            DomainModelConstraintProviderStub.VerifyAllExpectations();
        }
Exemple #10
0
        public void GetMetadata_ForClassWithVirtualRelationEndPoints()
        {
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BaseBidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BaseBidirectionalOneToMany")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BasePrivateBidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BasePrivateBidirectionalOneToMany")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "NoAttribute")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "NotNullable")))
            .Return(false);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BidirectionalOneToOne")))
            .Return(true);
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BidirectionalOneToMany")))
            .Return(true);

            ClassIDProviderStub.Stub(stub => stub.GetClassID(typeof(ClassWithVirtualRelationEndPoints))).Return("ClassWithVirtualRelationEndPoints");

            var classReflector = CreateClassReflector(typeof(ClassWithVirtualRelationEndPoints));
            var expected       = CreateClassWithVirtualRelationEndPointsClassDefinition();

            expected.SetPropertyDefinitions(new PropertyDefinitionCollection());
            CreateEndPointDefinitionsForClassWithVirtualRelationEndPoints(expected);

            var actual = classReflector.GetMetadata(null);

            Assert.That(actual, Is.Not.Null);
            _classDefinitionChecker.Check(expected, actual);
            _endPointDefinitionChecker.Check(expected.MyRelationEndPointDefinitions, actual.MyRelationEndPointDefinitions, false);
        }
Exemple #11
0
        public void GetMetadata_BidirectionalOneToMany()
        {
            DomainModelConstraintProviderStub
            .Stub(stub => stub.IsNullable(Arg <IPropertyInformation> .Matches(pi => pi.Name == "BaseBidirectionalOneToMany")))
            .Return(true);

            var propertyInfo = PropertyInfoAdapter.Create(_classType.GetProperty("BaseBidirectionalOneToMany"));
            var relationEndPointReflector = CreateRelationEndPointReflector(propertyInfo);

            IRelationEndPointDefinition actual = relationEndPointReflector.GetMetadata();

            Assert.IsInstanceOf(typeof(VirtualRelationEndPointDefinition), actual);
            VirtualRelationEndPointDefinition relationEndPointDefinition = (VirtualRelationEndPointDefinition)actual;

            Assert.That(relationEndPointDefinition.ClassDefinition, Is.SameAs(_classDefinition));
            Assert.That(relationEndPointDefinition.PropertyName, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.ReflectionBasedMappingSample.ClassWithOneSideRelationPropertiesNotInMapping.BaseBidirectionalOneToMany"));
            Assert.That(relationEndPointDefinition.PropertyInfo.PropertyType, Is.SameAs(typeof(ObjectList <ClassWithRealRelationEndPoints>)));
            Assert.That(relationEndPointDefinition.Cardinality, Is.EqualTo(CardinalityType.Many));
            Assert.That(relationEndPointDefinition.RelationDefinition, Is.Null);
            Assert.That(relationEndPointDefinition.SortExpressionText, Is.EqualTo("NoAttribute"));
        }