public void GetMetadata_WithInvalidOppositePropertyName()
        {
            var type1 = GetClassWithInvalidBidirectionalRelationLeftSide();
            var type2 = GetClassWithInvalidBidirectionalRelationRightSide();

            var classDefinition1 = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(type1);

            classDefinition1.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition1.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var propertyInfo     = EnsurePropertyDefinitionExisitsOnClassDefinition(classDefinition1, type1, "InvalidOppositePropertyNameLeftSide");
            var classDefinition2 = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(type2);

            classDefinition2.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition2.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            EnsurePropertyDefinitionExisitsOnClassDefinition(
                classDefinition2, type2, "InvalidPropertyNameInBidirectionalRelationAttributeOnOppositePropertyRightSide");

            var relationReflector = CreateRelationReflector(classDefinition1, propertyInfo);

            _classDefinitions.Add(classDefinition1.ClassType, classDefinition1);
            _classDefinitions.Add(classDefinition2.ClassType, classDefinition2);

            var result = relationReflector.GetMetadata(_classDefinitions);

            Assert.That(
                result.ID,
                Is.EqualTo(
                    "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Errors.ClassWithInvalidBidirectionalRelationLeftSide:"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Errors.ClassWithInvalidBidirectionalRelationLeftSide."
                    + "InvalidOppositePropertyNameLeftSide->"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Errors.ClassWithInvalidBidirectionalRelationRightSide.Invalid"));
        }
        public void GetMetadata_OppositeClassDefinition_IsDeclaringTypeOfOppositeProperty_NotReturnTypeOfThisProperty()
        {
            var originatingClass = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(Class1));

            originatingClass.SetPropertyDefinitions(new PropertyDefinitionCollection());
            originatingClass.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var originatingProperty =
                EnsurePropertyDefinitionExisitsOnClassDefinition(originatingClass, typeof(Class1), "RelationProperty");

            var classDeclaringOppositeProperty = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(BaseClass2));

            classDeclaringOppositeProperty.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDeclaringOppositeProperty.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var oppositeProperty =
                EnsurePropertyDefinitionExisitsOnClassDefinition(classDeclaringOppositeProperty, typeof(BaseClass2), "RelationPropertyOnBaseClass");
            var derivedOfClassDeclaringOppositeProperty = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedClass2), baseClass: classDeclaringOppositeProperty);

            derivedOfClassDeclaringOppositeProperty.SetPropertyDefinitions(new PropertyDefinitionCollection());
            derivedOfClassDeclaringOppositeProperty.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());

            // This tests the scenario that the relation property's return type is a subclass of the opposite property's declaring type
            Assert.That(originatingProperty.PropertyType, Is.Not.SameAs(classDeclaringOppositeProperty.ClassType));
            Assert.That(originatingProperty.PropertyType.BaseType, Is.SameAs(classDeclaringOppositeProperty.ClassType));

            var classDefinitions = new[] { originatingClass, classDeclaringOppositeProperty, derivedOfClassDeclaringOppositeProperty }
            .ToDictionary(cd => cd.ClassType);

            var relationReflector = CreateRelationReflector(originatingClass, originatingProperty);
            var result            = relationReflector.GetMetadata(classDefinitions);

            Assert.That(result.EndPointDefinitions[0].PropertyInfo, Is.SameAs(originatingProperty));
            Assert.That(result.EndPointDefinitions[0].ClassDefinition, Is.SameAs(originatingClass));
            Assert.That(result.EndPointDefinitions[1].PropertyInfo, Is.SameAs(oppositeProperty));
            Assert.That(result.EndPointDefinitions[1].ClassDefinition, Is.SameAs(classDeclaringOppositeProperty));
        }
        public void PersistenceModelIsLoaded()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);

            classDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition.SetDerivedClasses(new ClassDefinition[0]);

            StubMockMappingLoader(new[] { classDefinition }, new RelationDefinition[0]);

            var persistenceModelLoaderMock = MockRepository.GenerateStrictMock <IPersistenceModelLoader>();

            persistenceModelLoaderMock
            .Expect(mock => mock.ApplyPersistenceModelToHierarchy(classDefinition))
            .WhenCalled(mi => classDefinition.SetStorageEntity(TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition)));
            persistenceModelLoaderMock
            .Expect(mock => mock.CreatePersistenceMappingValidator(classDefinition))
            .Return(new PersistenceMappingValidator());
            persistenceModelLoaderMock.Replay();

            _mockRepository.ReplayAll();

            new MappingConfiguration(_mockMappingLoader, persistenceModelLoaderMock);

            persistenceModelLoaderMock.VerifyAllExpectations();
        }
 public void SetUp()
 {
     _classDefinitions                 = new Dictionary <Type, ClassDefinition>();
     _mappingObjectFactoryMock         = MockRepository.GenerateStrictMock <IMappingObjectFactory>();
     _classDefinitionCollectionFactory = new ClassDefinitionCollectionFactory(_mappingObjectFactoryMock);
     _fakeClassDefinition              = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(Order));
 }
        public void GetMetadata_OppositePropertyIsAlsoDeclaredInBaseClass()
        {
            var originatingClass = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(ClassWithOppositeProperty));

            originatingClass.SetPropertyDefinitions(new PropertyDefinitionCollection());
            originatingClass.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var originatingProperty =
                EnsurePropertyDefinitionExisitsOnClassDefinition(originatingClass, typeof(ClassWithOppositeProperty), "OppositeProperty");

            var oppositeBaseClass = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(OppositeBaseClass));

            oppositeBaseClass.SetPropertyDefinitions(new PropertyDefinitionCollection());
            oppositeBaseClass.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var oppositePropertyFromBaseClass =
                EnsurePropertyDefinitionExisitsOnClassDefinition(oppositeBaseClass, typeof(OppositeBaseClass), "OppositeProperty");

            var oppositeClass = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(OppositeClass));

            oppositeClass.SetPropertyDefinitions(new PropertyDefinitionCollection());
            oppositeClass.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var oppositeProperty =
                EnsurePropertyDefinitionExisitsOnClassDefinition(oppositeClass, typeof(OppositeClass), "OppositeProperty");

            var classDefinitions = new[] { originatingClass, oppositeClass, oppositeBaseClass }.ToDictionary(cd => cd.ClassType);
            var relationReflector = CreateRelationReflector(originatingClass, originatingProperty);
            var result            = relationReflector.GetMetadata(classDefinitions);

            Assert.That(result.EndPointDefinitions[0].PropertyInfo, Is.SameAs(originatingProperty));
            Assert.That(result.EndPointDefinitions[0].ClassDefinition, Is.SameAs(originatingClass));
            Assert.That(result.EndPointDefinitions[1].PropertyInfo, Is.Not.SameAs(oppositePropertyFromBaseClass));
            Assert.That(result.EndPointDefinitions[1].PropertyInfo, Is.SameAs(oppositeProperty));
            Assert.That(result.EndPointDefinitions[1].ClassDefinition, Is.SameAs(oppositeClass));
        }
Example #6
0
        public void CreatePropertyDefinitions()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);

            var propertyInfo1 = PropertyInfoAdapter.Create(typeof(Order).GetProperty("OrderNumber"));
            var propertyInfo2 = PropertyInfoAdapter.Create(typeof(Order).GetProperty("DeliveryDate"));

            var fakePropertyDefinition1 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "P1");
            var fakePropertyDefinition2 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "P2");

            _mappingObjectFactoryMock
            .Expect(mock => mock.CreatePropertyDefinition(classDefinition, propertyInfo1))
            .Return(fakePropertyDefinition1);
            _mappingObjectFactoryMock
            .Expect(mock => mock.CreatePropertyDefinition(classDefinition, propertyInfo2))
            .Return(fakePropertyDefinition2);
            _mappingObjectFactoryMock.Replay();

            var result = _factory.CreatePropertyDefinitions(classDefinition, new[] { propertyInfo1, propertyInfo2 });

            _mappingObjectFactoryMock.VerifyAllExpectations();
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0], Is.SameAs(fakePropertyDefinition1));
            Assert.That(result[1], Is.SameAs(fakePropertyDefinition2));
        }
        public void CreateRelationEndPointDefinitionCollection()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(OrderTicket));
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(classDefinition);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true));
            var fakeRelationEndPoint = new RelationEndPointDefinition(propertyDefinition, false);

            var expectedPropertyInfo = PropertyInfoAdapter.Create(typeof(OrderTicket).GetProperty("Order"));

            _mappingObjectFactoryMock
            .Expect(
                mock =>
                mock.CreateRelationEndPointDefinition(
                    Arg.Is(classDefinition), Arg.Is(PropertyInfoAdapter.Create(expectedPropertyInfo.PropertyInfo))))
            .Return(fakeRelationEndPoint);
            _mappingObjectFactoryMock.Replay();

            var result = _factory.CreateRelationEndPointDefinitionCollection(classDefinition);

            _mappingObjectFactoryMock.VerifyAllExpectations();
            _memberInformationNameResolverMock.VerifyAllExpectations();
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.SameAs(fakeRelationEndPoint));
        }
        public ClassDefinition[] GetClassDefinitions()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition("Fake", typeof(Company));

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition.SetDerivedClasses(new ClassDefinition[0]);
            return(new[] { classDefinition });
        }
        public void CreatePropertyDefinition()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);
            var propertyInfo    = PropertyInfoAdapter.Create(typeof(Order).GetProperty("OrderItems"));

            var result = _factory.CreatePropertyDefinition(classDefinition, propertyInfo);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.PropertyInfo, Is.SameAs(propertyInfo));
        }
        public override void SetUp()
        {
            base.SetUp();

            _classDefinition         = ClassDefinitionObjectMother.CreateClassDefinition();
            _propertyInformationStub = MockRepository.GenerateStub <IPropertyInformation>();
            _propertyInformationStub.Stub(stub => stub.Name).Return("Test");
            _propertyInformationStub.Stub(stub => stub.DeclaringType).Return(TypeAdapter.Create(typeof(Order)));
            _propertyInformationStub.Stub(stub => stub.GetOriginalDeclaringType()).Return(TypeAdapter.Create(typeof(Order)));
        }
        public void CreateRelationEndPointDefinition()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);
            var propertyInfo    = PropertyInfoAdapter.Create(typeof(Order).GetProperty("OrderItems"));

            var result = _factory.CreateRelationEndPointDefinition(classDefinition, propertyInfo);

            Assert.That(result, Is.TypeOf(typeof(VirtualRelationEndPointDefinition)));
            Assert.That(((VirtualRelationEndPointDefinition)result).PropertyInfo, Is.SameAs(propertyInfo));
        }
        public void ClassDefinitionsAreValidated()
        {
            var type            = typeof(GenericTypeDomainObject <string>);
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(type);

            StubMockMappingLoaderWithValidation(new[] { classDefinition }, new RelationDefinition[0]);
            _mockRepository.ReplayAll();

            new MappingConfiguration(
                _mockMappingLoader, new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)));
        }
Example #13
0
        public void GetMetadata_PersistentMixinFinder_ForDerivedClass()
        {
            ClassIDProviderStub.Stub(stub => stub.GetClassID(typeof(DerivedClassWithDifferentProperties))).Return("ClassID");

            var classReflector      = CreateClassReflector(typeof(DerivedClassWithDifferentProperties));
            var baseClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition_WithEmptyMembers_AndDerivedClasses();

            var actual = classReflector.GetMetadata(baseClassDefinition);

            Assert.That(actual.PersistentMixinFinder.IncludeInherited, Is.False);
        }
        public void GetOppositePropertyInfo_WithStorageClassNoneOppositeProperty()
        {
            var classType           = typeof(TestDomain.RelationReflector.OppositePropertyHasStorageClassNoneAttribute.ClassWithOppositeProperty);
            var originatingClass    = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(classType);
            var originatingProperty = PropertyInfoAdapter.Create(classType.GetProperty("OppositeProperty"));

            var relationReflector = CreateRelationReflector(originatingClass, originatingProperty);

            var oppositePropertyInfo = (IPropertyInformation)PrivateInvoke.InvokeNonPublicMethod(relationReflector, "GetOppositePropertyInfo");

            Assert.That(oppositePropertyInfo, Is.Null);
        }
        public void CreatePropertyDefinitionCollection()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);
            var propertyInfo1   = PropertyInfoAdapter.Create(typeof(Order).GetProperty("OrderNumber"));
            var propertyInfo2   = PropertyInfoAdapter.Create(typeof(Order).GetProperty("DeliveryDate"));

            var result = _factory.CreatePropertyDefinitionCollection(classDefinition, new[] { propertyInfo1, propertyInfo2 });

            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].PropertyInfo, Is.SameAs(propertyInfo1));
            Assert.That(result[1].PropertyInfo, Is.SameAs(propertyInfo2));
        }
        private static ClassDefinition CreateFileSystemItemDefinition_WithEmptyMembers_AndWithDerivedClasses()
        {
            var fileSystemItemClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition("FileSystemItem", typeof(FileSystemItem));
            var fileClassDefinition           = ClassDefinitionObjectMother.CreateClassDefinition_WithEmptyMembers_AndDerivedClasses("File", typeof(File), fileSystemItemClassDefinition);
            var folderClassDefinition         = ClassDefinitionObjectMother.CreateClassDefinition_WithEmptyMembers_AndDerivedClasses("Folder", typeof(Folder), fileSystemItemClassDefinition);

            fileSystemItemClassDefinition.SetDerivedClasses(new [] { fileClassDefinition, folderClassDefinition });
            fileSystemItemClassDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            fileSystemItemClassDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());

            return(fileSystemItemClassDefinition);
        }
        public void Initialize()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order));
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(classDefinition);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection {
                propertyDefinition
            });
            var endPoint = new RelationEndPointDefinition(propertyDefinition, true);

            Assert.That(endPoint.PropertyInfo, Is.SameAs(propertyDefinition.PropertyInfo));
        }
        public void CreateClassDefinition_WithBaseClass()
        {
            var companyClass = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(Company));

            companyClass.SetPropertyDefinitions(new PropertyDefinitionCollection());
            companyClass.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var result = _factory.CreateClassDefinition(typeof(Customer), companyClass);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.ClassType, Is.SameAs(typeof(Customer)));
            Assert.That(result.InstanceCreator, Is.SameAs(_domainObjectCreator));
            Assert.That(result.BaseClass, Is.SameAs(companyClass));
        }
        public void CreateForAllPropertyDefinitions_ClassDefinitionWithoutBaseClassDefinition_MakeCollectionReadOnlyIsTrue()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition();
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, false));

            var propertyDefinitions = PropertyDefinitionCollection.CreateForAllProperties(classDefinition, true);

            Assert.That(propertyDefinitions.Count, Is.EqualTo(1));
            Assert.That(propertyDefinitions.IsReadOnly, Is.True);
            Assert.That(propertyDefinitions[0], Is.SameAs(propertyDefinition));
        }
        public void CreateRelationEndPointDefinitionCollection()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(OrderTicket), baseClass: null);
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(classDefinition, typeof(OrderTicket), "Order");

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

            var result = _factory.CreateRelationEndPointDefinitionCollection(classDefinition);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(
                ((RelationEndPointDefinition)result[0]).PropertyName,
                Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.OrderTicket.Order"));
        }
        public void GetClassDefinition_ValueFound()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(RelationEndPointPropertyClass));

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition.SetDerivedClasses(Enumerable.Empty <ClassDefinition>());
            StubMockMappingLoader(new[] { classDefinition }, _emptyRelationDefinitions);
            var persistenceModelLoaderStub = CreatePersistenceModelLoaderStub();

            _mockRepository.ReplayAll();
            var configuration = new MappingConfiguration(_mockMappingLoader, persistenceModelLoaderStub);

            Assert.That(configuration.GetClassDefinition(classDefinition.ID), Is.SameAs(classDefinition));
        }
        public void PersistenceModelIsLoaded_NoStorageEntityIsAppliedToTheRootClass()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition("Order", typeof(Order));

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());

            Assert.That(classDefinition.StorageEntityDefinition, Is.Null);

            var persistenceModelStub = MockRepository.GenerateStub <IPersistenceModelLoader>();

            StubMockMappingLoader(new[] { classDefinition }, new RelationDefinition[0]);
            _mockRepository.ReplayAll();

            new MappingConfiguration(_mockMappingLoader, persistenceModelStub);
        }
        public void PropertyDefinitionsAreValidated()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass));
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(
                classDefinition, typeof(DerivedValidationDomainObjectClass), "PropertyWithStorageClassNone");

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

            StubMockMappingLoaderWithValidation(new[] { classDefinition }, new RelationDefinition[0]);
            _mockRepository.ReplayAll();

            new MappingConfiguration(
                _mockMappingLoader,
                new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)));
        }
Example #24
0
        public override void SetUp()
        {
            base.SetUp();

            _customerClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Customer));
            _customerOrdersEndPoint  = VirtualRelationEndPointDefinitionFactory.Create(
                _customerClassDefinition,
                "Orders",
                false,
                CardinalityType.Many,
                typeof(OrderCollection),
                "OrderNumber desc");

            _orderClassDefinition = CreateOrderDefinition_WithEmptyMembers_AndDerivedClasses();
        }
        public void GetMetadata_Mixed_PropertyAboveInheritanceRoot()
        {
            var classAboveInheritanceRoot = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(RelationTargetForPersistentMixinAboveInheritanceRoot));

            CreateRelationReflectorForProperty(
                classAboveInheritanceRoot, typeof(RelationTargetForPersistentMixinAboveInheritanceRoot), "RelationProperty1");
            var relationReflector = CreateRelationReflectorForProperty(
                _inheritanceRootInheritingMixinClassDefinition,
                typeof(MixinAddingPersistentPropertiesAboveInheritanceRoot),
                "PersistentRelationProperty");

            _classDefinitions.Add(classAboveInheritanceRoot.ClassType, classAboveInheritanceRoot);

            Assert.That(relationReflector.GetMetadata(_classDefinitions), Is.Not.Null);
        }
        public void GetClassDefinition_ForDerivedClass_WithDerivedClassAlreadyInClassDefinitionCollection()
        {
            var existing = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(Order));

            _classDefinitions.Add(existing.ClassType, existing);

            _mappingObjectFactoryMock.Replay();

            var actual = _classDefinitionCollectionFactory.GetClassDefinition(_classDefinitions, typeof(Order));

            _mappingObjectFactoryMock.VerifyAllExpectations();
            Assert.That(actual, Is.Not.Null);
            Assert.That(_classDefinitions.Count, Is.EqualTo(1));
            Assert.That(_classDefinitions[typeof(Order)], Is.SameAs(actual));
            Assert.That(actual, Is.SameAs(existing));
        }
        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 GetClassDefinition_ForDerivedClass()
        {
            var fakeBaseClassDefinition = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(ClassWithDifferentProperties));

            _mappingObjectFactoryMock
            .Expect(mock => mock.CreateClassDefinition(typeof(ClassWithDifferentProperties), null))
            .Return(fakeBaseClassDefinition);
            _mappingObjectFactoryMock
            .Expect(mock => mock.CreateClassDefinition(typeof(DerivedClassWithDifferentProperties), fakeBaseClassDefinition))
            .Return(_fakeClassDefinition);
            _mappingObjectFactoryMock.Replay();

            var result = _classDefinitionCollectionFactory.GetClassDefinition(_classDefinitions, typeof(DerivedClassWithDifferentProperties));

            _mappingObjectFactoryMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(_fakeClassDefinition));
        }
        public void RelationDefinitionsAreValidated()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(RelationEndPointPropertyClass));

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            var relationDefinition =
                FakeMappingConfiguration.Current.RelationDefinitions[
                    "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Order:"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Order.Customer->"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Customer.Orders"];

            StubMockMappingLoaderWithValidation(new[] { classDefinition }, new[] { relationDefinition });
            _mockRepository.ReplayAll();

            new MappingConfiguration(
                _mockMappingLoader, new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)));
        }
        public void CreateForAllPropertyDefinitions_ClassDefinitionWithBaseClassDefinition()
        {
            var baseClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Company));
            var classDefinition     = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Partner), baseClass: baseClassDefinition);

            var propertyDefinitionInBaseClass    = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(baseClassDefinition, "Property1");
            var propertyDefinitionInDerivedClass = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "Property2");

            baseClassDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinitionInBaseClass }, true));
            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinitionInDerivedClass }, true));

            var propertyDefinitions = PropertyDefinitionCollection.CreateForAllProperties(classDefinition, false);

            Assert.That(propertyDefinitions.Count, Is.EqualTo(2));
            Assert.That(propertyDefinitions[0], Is.SameAs(propertyDefinitionInDerivedClass));
            Assert.That(propertyDefinitions[1], Is.SameAs(propertyDefinitionInBaseClass));
        }