public void UnifyWithEquivalentProperties_CombinesProperties() { var valueProperty1Mock = MockRepository.GenerateStrictMock <IRdbmsStoragePropertyDefinition> (); var property1 = new ObjectIDWithoutClassIDStoragePropertyDefinition(valueProperty1Mock, _classDefinition); var valueProperty2Stub = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition> (); var property2 = new ObjectIDWithoutClassIDStoragePropertyDefinition(valueProperty2Stub, _classDefinition); var valueProperty3Stub = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition> (); var property3 = new ObjectIDWithoutClassIDStoragePropertyDefinition(valueProperty3Stub, _classDefinition); var fakeUnifiedValueProperty = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition> (); valueProperty1Mock .Expect( mock => mock.UnifyWithEquivalentProperties( Arg <IEnumerable <IRdbmsStoragePropertyDefinition> > .List.Equal(new[] { valueProperty2Stub, valueProperty3Stub }))) .Return(fakeUnifiedValueProperty); var result = property1.UnifyWithEquivalentProperties(new[] { property2, property3 }); fakeUnifiedValueProperty.VerifyAllExpectations(); Assert.That(result, Is.TypeOf <ObjectIDWithoutClassIDStoragePropertyDefinition> ()); Assert.That(((ObjectIDWithoutClassIDStoragePropertyDefinition)result).ValueProperty, Is.SameAs(fakeUnifiedValueProperty)); Assert.That(((ObjectIDWithoutClassIDStoragePropertyDefinition)result).ClassDefinition, Is.SameAs(_classDefinition)); }
public void UnifyWithEquivalentProperties_ThrowsForDifferentClassDefinitions() { var property2 = new ObjectIDWithoutClassIDStoragePropertyDefinition(_valuePropertyStub, GetTypeDefinition(typeof(OrderItem))); Assert.That( () => _objectIDWithoutClassIDStoragePropertyDefinition.UnifyWithEquivalentProperties(new[] { property2 }), Throws.ArgumentException.With.Message.EqualTo( "Only equivalent properties can be combined, but this property has class definition " + "'Remotion.Data.DomainObjects.Mapping.ClassDefinition: Order', and the given property has " + "class definition 'Remotion.Data.DomainObjects.Mapping.ClassDefinition: OrderItem'.\r\nParameter name: equivalentProperties")); }
public override void SetUp() { base.SetUp(); _classDefinition = DomainObjectIDs.Order1.ClassDefinition; _valueColumnDefinition = ColumnDefinitionObjectMother.CreateColumn(); _valuePropertyStub = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition>(); _objectIDWithoutClassIDStoragePropertyDefinition = new ObjectIDWithoutClassIDStoragePropertyDefinition( _valuePropertyStub, _classDefinition); _columnValueProviderStub = MockRepository.GenerateStub <IColumnValueProvider> (); _dbCommandStub = MockRepository.GenerateStub <IDbCommand>(); _dbDataParameterStub = MockRepository.GenerateStub <IDbDataParameter>(); _dbCommandStub.Stub(stub => stub.CreateParameter()).Return(_dbDataParameterStub).Repeat.Once(); }
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); }