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 override void SetUp()
        {
            base.SetUp();

            _propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();
            _collection         = new PropertyDefinitionCollection();
        }
Beispiel #3
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 SetStorageProperty()
        {
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_classDefinition);
            var storagePropertyDefinition         = SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Test");

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);

            Assert.That(propertyDefinition.StoragePropertyDefinition, Is.SameAs(storagePropertyDefinition));
        }
        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 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 GetAllPersistent()
        {
            var persistentProperty1    = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("P1", StorageClass.Persistent);
            var persistentProperty2    = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("P2", StorageClass.Persistent);
            var nonPersistentProperty1 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("P3", StorageClass.Transaction);
            var nonPersistentProperty2 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("P4", StorageClass.None);

            _collection.Add(persistentProperty1);
            _collection.Add(persistentProperty2);
            _collection.Add(nonPersistentProperty1);
            _collection.Add(nonPersistentProperty2);

            Assert.That(_collection.GetAllPersistent().ToArray(), Is.EqualTo(new[] { persistentProperty1, persistentProperty2 }));
        }
        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)));
        }
        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 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));
        }
        public void CreateRelationDefinitionCollection()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(OrderItem));
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(classDefinition, typeof(OrderItem), "Order");
            var endPoint           = new RelationEndPointDefinition(propertyDefinition, false);

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

            var result = _factory.CreateRelationDefinitionCollection(new[] { classDefinition }.ToDictionary(cd => cd.ClassType));

            Assert.That(result.Count(), Is.EqualTo(1));
            Assert.That(
                result.First().ID,
                Is.EqualTo(
                    "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.OrderItem:"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.OrderItem.Order->"
                    + "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Order.OrderItems"));
        }
Beispiel #13
0
        private VirtualRelationEndPointDefinition CreateFullVirtualEndPointAndClassDefinition_WithProductProperty(string sortExpressionString)
        {
            var endPoint = VirtualRelationEndPointDefinitionFactory.Create(
                _orderClassDefinition,
                "OrderItems",
                false,
                CardinalityType.Many,
                typeof(ObjectList <OrderItem>),
                sortExpressionString);
            var orderItemClassDefinition = ClassDefinitionObjectMother.CreateClassDefinitionWithMixins(typeof(OrderItem));
            var oppositeProperty         = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(orderItemClassDefinition, "Order");
            var productProperty          = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(orderItemClassDefinition, "Product");

            orderItemClassDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { oppositeProperty, productProperty }, true));
            orderItemClassDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            var oppositeEndPoint   = new RelationEndPointDefinition(oppositeProperty, false);
            var relationDefinition = new RelationDefinition("test", endPoint, oppositeEndPoint);

            orderItemClassDefinition.SetReadOnly();
            endPoint.SetRelationDefinition(relationDefinition);
            return(endPoint);
        }
        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));
        }
        public void PersistenceModelIsLoaded_NoStoragePropertyIsAppliedToTheRootClassProperty()
        {
            var fakeStorageEntityDefinition = _fakeStorageEntityDefinition;
            var classDefinition             = ClassDefinitionObjectMother.CreateClassDefinition("Order", typeof(Order));
            var propertyDefinition          = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "Fake");

            PrivateInvoke.SetNonPublicField(propertyDefinition, "_storagePropertyDefinition", null);

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

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

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

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

            persistenceModelStub.Stub(stub => stub.ApplyPersistenceModelToHierarchy(classDefinition)).WhenCalled(
                mi =>
                classDefinition.SetStorageEntity(fakeStorageEntityDefinition));

            new MappingConfiguration(_mockMappingLoader, persistenceModelStub);
        }
        public new void ToString()
        {
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_classDefinition, "ThePropertyName");

            Assert.That(propertyDefinition.ToString(), Is.EqualTo(typeof(PropertyDefinition).FullName + ": ThePropertyName"));
        }