コード例 #1
0
        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);
        }
        public void CopyConstructor()
        {
            var copiedCollection = new RelationEndPointDefinitionCollection(new[] { _endPoint1 }, false);

            Assert.That(copiedCollection.Count, Is.EqualTo(1));
            Assert.That(copiedCollection[0], Is.SameAs(_endPoint1));
        }
        public void CreateForAllRelationEndPoints_ClassDefinitionWithoutBaseClassDefinition_MakeCollectionReadOnlyIsTrue()
        {
            _classDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection(new[] { _endPoint1, _endPoint2 }, false));

            var endPoints = RelationEndPointDefinitionCollection.CreateForAllRelationEndPoints(_classDefinition, true);

            Assert.That(endPoints.Count, Is.EqualTo(2));
            Assert.That(endPoints.IsReadOnly, Is.True);
            Assert.That(endPoints[0], Is.SameAs(_endPoint1));
            Assert.That(endPoints[1], Is.SameAs(_endPoint2));
        }
コード例 #4
0
        public void Check(
            RelationEndPointDefinitionCollection expectedDefinitions, RelationEndPointDefinitionCollection actualDefinitions, bool checkRelationDefinition)
        {
            Assert.AreEqual(expectedDefinitions.Count, actualDefinitions.Count, "Number of relation end points does not match.");

            foreach (var expectedDefinition in expectedDefinitions)
            {
                var actualDefinition = actualDefinitions[expectedDefinition.PropertyName];
                Assert.IsNotNull(actualDefinition, "Relation end point '{0}' was not found.", expectedDefinition.PropertyName);
                Check(expectedDefinition, actualDefinition, checkRelationDefinition);
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            _classDefinition = ClassDefinitionObjectMother.CreateClassDefinition();
            var propertyDefinition1 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(_classDefinition, "Property1");
            var propertyDefinition2 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(_classDefinition, "Property2");
            var propertyDefinition3 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(_classDefinition, "Property3");
            var propertyDefinition4 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(_classDefinition, "Property4");

            _classDefinition.SetPropertyDefinitions(
                new PropertyDefinitionCollection(new[] { propertyDefinition1, propertyDefinition2, propertyDefinition3, propertyDefinition4 }, true));
            _endPoint1  = new RelationEndPointDefinition(propertyDefinition1, false);
            _endPoint2  = new RelationEndPointDefinition(propertyDefinition2, false);
            _collection = new RelationEndPointDefinitionCollection();
        }
        public void CreateForAllRelationEndPoints_ClassDefinitionWithBaseClassDefinition()
        {
            var baseClassDefinition     = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Company));
            var basedPropertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(baseClassDefinition, "Property1");

            baseClassDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { basedPropertyDefinition }, true));
            var derivedClassDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Partner), baseClass: baseClassDefinition);
            var derivedPropertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(derivedClassDefinition, "Property2");

            derivedClassDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { derivedPropertyDefinition }, true));

            var endPoint1 = new RelationEndPointDefinition(basedPropertyDefinition, false);
            var endPoint2 = new RelationEndPointDefinition(derivedPropertyDefinition, false);

            baseClassDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection(new[] { endPoint1 }, true));
            derivedClassDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection(new[] { endPoint2 }, true));

            var endPoints = RelationEndPointDefinitionCollection.CreateForAllRelationEndPoints(derivedClassDefinition, true);

            Assert.That(endPoints.Count, Is.EqualTo(2));
            Assert.That(endPoints[0], Is.SameAs(endPoint2));
            Assert.That(endPoints[1], Is.SameAs(endPoint1));
        }