public static void SetForeignKeyProperty(IDomainObject domainObject, RelationEndPointDefinition endPointDefinition, ObjectID relatedID) { var relatedObject = LifetimeService.GetObjectReference(ClientTransaction.Current, relatedID); var properties = new PropertyIndexer(domainObject); properties[endPointDefinition.PropertyName].SetValue(relatedObject); }
public override IEnumerable <DataContainer> LoadDataContainersByRelatedID( RelationEndPointDefinition relationEndPointDefinition, SortExpressionDefinition sortExpressionDefinition, ObjectID relatedID) { CheckDisposed(); ArgumentUtility.CheckNotNull("relationEndPointDefinition", relationEndPointDefinition); ArgumentUtility.CheckNotNull("relatedID", relatedID); CheckClassDefinition(relationEndPointDefinition.ClassDefinition, "classDefinition"); Connect(); if (relationEndPointDefinition.PropertyDefinition.StorageClass == StorageClass.Transaction) { return(new DataContainerCollection()); } var storageProviderCommand = _storageProviderCommandFactory.CreateForRelationLookup( relationEndPointDefinition, relatedID, sortExpressionDefinition); var dataContainers = storageProviderCommand.Execute(this); var checkedSequence = CheckForNulls(CheckForDuplicates(dataContainers, "relation lookup"), "relation lookup"); return(new DataContainerCollection(checkedSequence, true)); }
protected virtual IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> CreateForIndirectRelationLookup( UnionViewDefinition unionViewDefinition, RelationEndPointDefinition foreignKeyEndPoint, ObjectID foreignKeyValue, SortExpressionDefinition sortExpression) { var selectedColumns = unionViewDefinition.ObjectIDProperty.GetColumns(); var dbCommandBuilder = _dbCommandBuilderFactory.CreateForSelect( unionViewDefinition, selectedColumns, GetComparedColumns(foreignKeyEndPoint, foreignKeyValue), GetOrderedColumns(sortExpression)); var objectIDReader = _objectReaderFactory.CreateObjectIDReader(unionViewDefinition, selectedColumns); var objectIDLoadCommand = new MultiObjectIDLoadCommand(new[] { dbCommandBuilder }, objectIDReader); var indirectDataContainerLoadCommand = new IndirectDataContainerLoadCommand(objectIDLoadCommand, _storageProviderCommandFactory); return(DelegateBasedCommand.Create( indirectDataContainerLoadCommand, lookupResults => lookupResults.Select( result => { Assertion.IsNotNull( result.LocatedObject, "Because ID lookup and DataContainer lookup are executed within the same database transaction, the DataContainer can never be null."); return result.LocatedObject; }))); }
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 void ResolveIDPropertyViaForeignKey_WithFullObjectID_ResolvesToCompound() { var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer"); var objectIDStorageProperty = ObjectIDStoragePropertyDefinitionObjectMother.Create( "CustomerID", "CustomerClassID", StorageTypeInformationObjectMother.CreateUniqueIdentifierStorageTypeInformation(), StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation()); var foreignKeyEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetStoragePropertyDefinition(foreignKeyEndPointDefinition.PropertyDefinition)) .Return(objectIDStorageProperty); var originatingEntity = CreateEntityDefinition(typeof(Order), "o"); var result = _storageSpecificExpressionResolver.ResolveIDPropertyViaForeignKey(originatingEntity, foreignKeyEndPointDefinition); var expected = Expression.New( MemberInfoFromExpressionUtility.GetConstructor(() => new ObjectID("classID", "value")), new[] { new NamedExpression("ClassID", originatingEntity.GetColumn(typeof(string), "CustomerClassID", false)), new NamedExpression("Value", Expression.Convert(originatingEntity.GetColumn(typeof(Guid), "CustomerID", false), typeof(object))) }, new[] { typeof(ObjectID).GetProperty("ClassID"), typeof(ObjectID).GetProperty("Value") }); SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result); }
public void ResolveJoin_LeftSideHoldsNoForeignKey() { var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer"); var leftEndPointDefinition = new AnonymousRelationEndPointDefinition(_classDefinition); var rightEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false); var entityExpression = CreateEntityDefinition(typeof(Customer), "c"); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetEntityDefinition(rightEndPointDefinition.ClassDefinition)) .Return(rightEndPointDefinition.ClassDefinition.StorageEntityDefinition as IRdbmsStorageEntityDefinition); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetStoragePropertyDefinition(rightEndPointDefinition.PropertyDefinition)) .Return(_rdbmsStoragePropertyDefinitionStub); _rdbmsStoragePropertyDefinitionStub .Stub(stub => stub.GetColumnsForComparison()) .Return(new[] { ColumnDefinitionObjectMother.CreateGuidColumn("Customer") }); _rdbmsStoragePropertyDefinitionStub.Stub(stub => stub.PropertyType).Return(typeof(ObjectID)); var result = _storageSpecificExpressionResolver.ResolveJoin(entityExpression, leftEndPointDefinition, rightEndPointDefinition, "o"); SqlExpressionTreeComparer.CheckAreEqualTrees( Expression.Equal( entityExpression.GetIdentityExpression(), // c.ID new SqlColumnDefinitionExpression(typeof(Guid), "o", "Customer", false)), result.JoinCondition); }
public IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> CreateForRelationLookup( RelationEndPointDefinition foreignKeyEndPoint, ObjectID foreignKeyValue, SortExpressionDefinition sortExpressionDefinition) { ArgumentUtility.CheckNotNull("foreignKeyEndPoint", foreignKeyEndPoint); ArgumentUtility.CheckNotNull("foreignKeyValue", foreignKeyValue); return(_relationLookupCommandFactory.CreateForRelationLookup(foreignKeyEndPoint, foreignKeyValue, sortExpressionDefinition)); }
public void RelationDefinitionNull() { var classDefinition = FakeMappingConfiguration.Current.TypeDefinitions[typeof(OrderTicket)]; var propertyDefinition = classDefinition["Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.OrderTicket.Order"]; var definition = new RelationEndPointDefinition(propertyDefinition, true); Assert.That(definition.RelationDefinition, Is.Null); }
public IRdbmsStoragePropertyDefinition CreateStoragePropertyDefinition(RelationEndPointDefinition relationEndPointDefinition) { ArgumentUtility.CheckNotNull("relationEndPointDefinition", relationEndPointDefinition); var oppositeEndPointDefinition = relationEndPointDefinition.GetOppositeEndPointDefinition(); var relationColumnName = _storageNameProvider.GetRelationColumnName(relationEndPointDefinition); var relationClassIDColumnName = _storageNameProvider.GetRelationClassIDColumnName(relationEndPointDefinition); return(CreateStoragePropertyDefinition(oppositeEndPointDefinition.ClassDefinition, relationColumnName, relationClassIDColumnName)); }
public void GetRelationClassIDColumnName() { var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(FileSystemItem), baseClass: null); var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(classDefinition, typeof(FileSystemItem), "ParentFolder"); var relationDefinition = new RelationEndPointDefinition(propertyDefinition, true); var result = _provider.GetRelationClassIDColumnName(relationDefinition); Assert.That(result, Is.EqualTo("ParentFolderIDClassID")); }
public override void SetUp() { base.SetUp(); _relation = FakeMappingConfiguration.Current.RelationDefinitions[ "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Location:Remotion.Data.DomainObjects.UnitTests.Mapping." + "TestDomain.Integration.Location.Client"]; _clientEndPoint = (AnonymousRelationEndPointDefinition)_relation.EndPointDefinitions[0]; _locationEndPoint = (RelationEndPointDefinition)_relation.EndPointDefinitions[1]; }
public override IEnumerable <DataContainer> LoadDataContainersByRelatedID(RelationEndPointDefinition relationEndPointDefinition, SortExpressionDefinition sortExpressionDefinition, ObjectID relatedID) { if (InnerProvider != null) { return(InnerProvider.LoadDataContainersByRelatedID(relationEndPointDefinition, sortExpressionDefinition, relatedID)); } else { return(null); } }
public static ObjectID CreateObjectAndSetRelationInOtherTransaction(RelationEndPointDefinition endPointDefinition, ObjectID relatedID) { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var domainObject = LifetimeService.NewObject(ClientTransaction.Current, endPointDefinition.ClassDefinition.ClassType, ParamList.Empty); SetForeignKeyProperty(domainObject, endPointDefinition, relatedID); ClientTransaction.Current.Commit(); return(domainObject.ID); } }
public void GetRelationColumnName_PropertyWithIStorageSpecificIdentifierAttribute_ReturnsNameFromAttribute() { var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(FileSystemItem), baseClass: null); var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(classDefinition, typeof(FileSystemItem), "ParentFolder2"); var relationDefinition = new RelationEndPointDefinition(propertyDefinition, true); var result = _provider.GetRelationColumnName(relationDefinition); Assert.That(result, Is.EqualTo("ParentFolderRelation")); }
public void SetRelationDefinition() { var propertyDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(Location)) ["Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Location.Client"]; var oppositeEndPoint = new RelationEndPointDefinition(propertyDefinition, true); var relationDefinition = new RelationDefinition("Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Location.Client", _definition, oppositeEndPoint); _definition.SetRelationDefinition(relationDefinition); Assert.That(_definition.RelationDefinition, Is.Not.Null); }
public string GetRelationColumnName(RelationEndPointDefinition relationEndPointDefinition) { var name = GetColumnNameFromAttribute(relationEndPointDefinition.PropertyDefinition); if (name != null) { return(name); } return(relationEndPointDefinition.PropertyInfo.Name + "ID"); }
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 virtual IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> CreateForRelationLookup( RelationEndPointDefinition foreignKeyEndPoint, ObjectID foreignKeyValue, SortExpressionDefinition sortExpressionDefinition) { ArgumentUtility.CheckNotNull("foreignKeyEndPoint", foreignKeyEndPoint); ArgumentUtility.CheckNotNull("foreignKeyValue", foreignKeyValue); return(InlineRdbmsStorageEntityDefinitionVisitor.Visit <IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> > ( _rdbmsPersistenceModelProvider.GetEntityDefinition(foreignKeyEndPoint.ClassDefinition), (table, continuation) => CreateForDirectRelationLookup(table, foreignKeyEndPoint, foreignKeyValue, sortExpressionDefinition), (filterView, continuation) => continuation(filterView.BaseEntity), (unionView, continuation) => CreateForIndirectRelationLookup(unionView, foreignKeyEndPoint, foreignKeyValue, sortExpressionDefinition), (emptyView, continuation) => CreateForEmptyRelationLookup())); }
public override void SetUp() { base.SetUp(); _customerClass = FakeMappingConfiguration.Current.TypeDefinitions[typeof(Customer)]; _customerToOrder = 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"]; _customerEndPoint = (VirtualRelationEndPointDefinition)_customerToOrder.EndPointDefinitions[0]; _orderEndPoint = (RelationEndPointDefinition)_customerToOrder.EndPointDefinitions[1]; }
public void CreateForRelationLookup_EmptyViewDefinition() { var emptyViewDefintion = EmptyViewDefinitionObjectMother.Create(TestDomainStorageProviderDefinition); var classDefinition = CreateClassDefinition(emptyViewDefintion); var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(classDefinition); var relationEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false); var result = _factory.CreateForRelationLookup(relationEndPointDefinition, _foreignKeyValue, null); Assert.That(result, Is.TypeOf(typeof(FixedValueCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext>))); var fixedValueCommand = (FixedValueCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext>)result; Assert.That(fixedValueCommand.Value, Is.EqualTo(Enumerable.Empty <DataContainer>())); }
public void LoadDataContainersByRelatedID_StorageClassTransaction() { var objectID = DomainObjectIDs.Order1; var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(objectID.ClassDefinition, "Test", StorageClass.Transaction); var relationEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, true); _connectionCreatorMock.Expect(mock => mock.CreateConnection()).Return(_connectionStub); _mockRepository.ReplayAll(); var result = _provider.LoadDataContainersByRelatedID(relationEndPointDefinition, null, objectID); _mockRepository.VerifyAll(); Assert.That(result, Is.Empty); }
public override void SetUp() { base.SetUp(); RelationDefinition customerToOrder = 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"]; _customerEndPoint = (VirtualRelationEndPointDefinition)customerToOrder.GetEndPointDefinition( "Customer", "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Customer.Orders"); _orderEndPoint = (RelationEndPointDefinition)customerToOrder.GetEndPointDefinition( "Order", "Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Integration.Order.Customer"); }
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 ResolveIDPropertyViaForeignKey_WithSomeOtherStorageProperty_ReturnsNull() { var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer"); var foreignKeyEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetStoragePropertyDefinition(foreignKeyEndPointDefinition.PropertyDefinition)) .Return(_rdbmsStoragePropertyDefinitionStub); var originatingEntity = CreateEntityDefinition(typeof(Order), "o"); var result = _storageSpecificExpressionResolver.ResolveIDPropertyViaForeignKey(originatingEntity, foreignKeyEndPointDefinition); Assert.That(result, Is.Null); }
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); }
protected virtual IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> CreateForDirectRelationLookup( TableDefinition tableDefinition, RelationEndPointDefinition foreignKeyEndPoint, ObjectID foreignKeyValue, SortExpressionDefinition sortExpression) { var selectedColumns = tableDefinition.GetAllColumns(); var dataContainerReader = _objectReaderFactory.CreateDataContainerReader(tableDefinition, selectedColumns); var dbCommandBuilder = _dbCommandBuilderFactory.CreateForSelect( tableDefinition, selectedColumns, GetComparedColumns(foreignKeyEndPoint, foreignKeyValue), GetOrderedColumns(sortExpression)); return(new MultiObjectLoadCommand <DataContainer> (new[] { Tuple.Create(dbCommandBuilder, dataContainerReader) })); }
public void ResolveJoin_LeftSideHoldsForeignKey() { // Order.Customer var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer"); var columnDefinition = ColumnDefinitionObjectMother.CreateGuidColumn("Customer"); _rdbmsStoragePropertyDefinitionStub.Stub(stub => stub.GetColumnsForComparison()).Return(new[] { columnDefinition }); _rdbmsStoragePropertyDefinitionStub.Stub(stub => stub.PropertyType).Return(typeof(ObjectID)); var leftEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetStoragePropertyDefinition(leftEndPointDefinition.PropertyDefinition)) .Return(_rdbmsStoragePropertyDefinitionStub); // Customer.Order var customerClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Customer)); var customerTableDefinition = TableDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "CustomerTable"), new EntityNameDefinition(null, "CustomerView")); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetEntityDefinition(customerClassDefinition)) .Return(customerTableDefinition); var rightEndPointDefinition = new AnonymousRelationEndPointDefinition(customerClassDefinition); var originatingEntity = CreateEntityDefinition(typeof(Order), "o"); var result = _storageSpecificExpressionResolver.ResolveJoin(originatingEntity, leftEndPointDefinition, rightEndPointDefinition, "c"); Assert.That(result, Is.Not.Null); Assert.That(result.ItemType, Is.EqualTo(typeof(Customer))); Assert.That(result.ForeignTableInfo, Is.TypeOf(typeof(ResolvedSimpleTableInfo))); Assert.That(((ResolvedSimpleTableInfo)result.ForeignTableInfo).TableName, Is.EqualTo("CustomerView")); Assert.That(((ResolvedSimpleTableInfo)result.ForeignTableInfo).TableAlias, Is.EqualTo("c")); var expected = Expression.Equal( new SqlColumnDefinitionExpression(typeof(Guid), "o", "Customer", false), new SqlColumnDefinitionExpression(typeof(Guid), "c", "ID", true)); SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result.JoinCondition); }
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")); }
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)); }