public void ResolveEntity() { var objectIDProperty = ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty; var timestampProperty = SimpleStoragePropertyDefinitionObjectMother.TimestampProperty; var foreignKeyProperty = SimpleStoragePropertyDefinitionObjectMother.CreateGuidStorageProperty("ForeignKey"); var simpleProperty = SimpleStoragePropertyDefinitionObjectMother.CreateStringStorageProperty("Column1"); var tableDefinition = TableDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Test"), null, objectIDProperty, timestampProperty, foreignKeyProperty, simpleProperty); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetEntityDefinition(_classDefinition)) .Return(tableDefinition); var result = _storageSpecificExpressionResolver.ResolveEntity(_classDefinition, "o"); var expectedIdColumn = new SqlColumnDefinitionExpression(typeof(Guid), "o", "ID", true); var expectedClassIdColumn = new SqlColumnDefinitionExpression(typeof(string), "o", "ClassID", false); var expectedTimestampColumn = new SqlColumnDefinitionExpression(typeof(DateTime), "o", "Timestamp", false); var expectedForeignKeyColumn = new SqlColumnDefinitionExpression(typeof(Guid), "o", "ForeignKey", false); var expectedColumn = new SqlColumnDefinitionExpression(typeof(string), "o", "Column1", false); Assert.That(result.Type, Is.SameAs(typeof(Order))); Assert.That(result.TableAlias, Is.EqualTo("o")); Assert.That(result.Name, Is.Null); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedIdColumn, result.GetIdentityExpression()); Assert.That(result.Columns, Has.Count.EqualTo(5)); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedIdColumn, result.Columns[0]); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedClassIdColumn, result.Columns[1]); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedTimestampColumn, result.Columns[2]); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedForeignKeyColumn, result.Columns[3]); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedColumn, result.Columns[4]); }
public void ResolveIDPropertyViaForeignKey_WithObjectIDWithoutClassID_ResolvesToCompoundWithFixedConditionalClassID() { var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer"); var objectIDStorageProperty = new ObjectIDWithoutClassIDStoragePropertyDefinition( SimpleStoragePropertyDefinitionObjectMother.CreateGuidStorageProperty("CustomerID"), GetTypeDefinition(typeof(Customer))); 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 expectedValueColumn = originatingEntity.GetColumn(typeof(Guid), "CustomerID", false); var expected = Expression.New( MemberInfoFromExpressionUtility.GetConstructor(() => new ObjectID("classID", "value")), new Expression[] { new NamedExpression( "ClassID", SqlCaseExpression.CreateIfThenElse( typeof(string), new SqlIsNotNullExpression(expectedValueColumn), new SqlLiteralExpression("Customer"), Expression.Constant(null, typeof(string)))), new NamedExpression("Value", Expression.Convert(expectedValueColumn, typeof(object))) }, new[] { typeof(ObjectID).GetProperty("ClassID"), typeof(ObjectID).GetProperty("Value") }); SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result); }