public void Create_WhenDoubleAndSinglePropertiesAreSpecified_TheAssignmentIsCorrect(double doubleValue, float singleValue) { // arrange var doubleProperty = typeof(PropertyExpressionTestClass).GetProperty(Utils.GetPropertyName<PropertyExpressionTestClass, double>(p => p.PropDouble)); var mergeResultDouble = new MemberMergeResult<PropertyInfo>(doubleProperty); var floatProperty = typeof(PropertyExpressionTestClass).GetProperty(Utils.GetPropertyName<PropertyExpressionTestClass, float>(p => p.PropFloat)); var mergeResultFloat = new MemberMergeResult<PropertyInfo>(floatProperty); var propertyExpressionBuilder = new PropertyExpressionBuilder(this.SourceParameterExpression, this.DestinationParameterExpression); var properties = new[] { mergeResultDouble, mergeResultFloat }; // act var propertyBlockExpressionBuilder = new MemberBlockExpressionBuilder<PropertyInfo>(propertyExpressionBuilder); var blockExpression = propertyBlockExpressionBuilder.Create<PropertyExpressionTestClass, PropertyExpressionTestClass>(properties); // assert var action = Expression.Lambda<Action<PropertyExpressionTestClass, PropertyExpressionTestClass>>(blockExpression, this.SourceParameterExpression, this.DestinationParameterExpression).Compile(); PropertyExpressionTestClass sourceObject = new PropertyExpressionTestClass { PropDouble = doubleValue, PropFloat = singleValue }; var destinationObject = new PropertyExpressionTestClass(); action.Invoke(sourceObject, destinationObject); Assert.Equal(doubleValue, destinationObject.PropDouble); Assert.Equal(singleValue, destinationObject.PropFloat); }
public void Create_WhenDoubleAndSingleFieldsAreSpecified_TheAssignmentIsCorrect(double doubleValue, float singleValue) { // arrange var doubleField = typeof(FieldExpressionTestClass).GetField(Utils.GetFieldName<FieldExpressionTestClass, double>(p => p.FieldDouble)); var mergeResultDouble = new MemberMergeResult<FieldInfo>(doubleField); var floatField = typeof(FieldExpressionTestClass).GetField(Utils.GetFieldName<FieldExpressionTestClass, float>(p => p.FieldFloat)); var mergeResultFloat = new MemberMergeResult<FieldInfo>(floatField); var fieldExpressionBuilder = new FieldExpressionBuilder(this.SourceParameterExpression, this.DestinationParameterExpression); var fields = new[] { mergeResultDouble, mergeResultFloat }; // act var fieldBlockExpressionBuilder = new MemberBlockExpressionBuilder<FieldInfo>(fieldExpressionBuilder); var blockExpression = fieldBlockExpressionBuilder.Create<FieldExpressionTestClass, FieldExpressionTestClass>(fields); // assert var action = Expression.Lambda<Action<FieldExpressionTestClass, FieldExpressionTestClass>>(blockExpression, this.SourceParameterExpression, this.DestinationParameterExpression).Compile(); FieldExpressionTestClass sourceObject = new FieldExpressionTestClass { FieldDouble = doubleValue, FieldFloat = singleValue }; var destinationObject = new FieldExpressionTestClass(); action.Invoke(sourceObject, destinationObject); Assert.Equal(doubleValue, destinationObject.FieldDouble); Assert.Equal(singleValue, destinationObject.FieldFloat); }
public void Create_WhenThePropertiesAreSpecified_TheAssignmentIsCorrect() { // arrange var stringProperty = typeof (PropertyExpressionTestClass).GetProperty(Utils.GetPropertyName<PropertyExpressionTestClass, string>(p => p.PropString)); var mergeResultString = new MemberMergeResult<PropertyInfo>(stringProperty); var intProperty = typeof(PropertyExpressionTestClass).GetProperty(Utils.GetPropertyName<PropertyExpressionTestClass, int>(p => p.PropInt)); var mergeResultInt = new MemberMergeResult<PropertyInfo>(intProperty); var propertyExpressionBuilder = new PropertyExpressionBuilder(this.SourceParameterExpression, this.DestinationParameterExpression); var properties = new[] {mergeResultString, mergeResultInt}; // act var propertyBlockExpressionBuilder = new MemberBlockExpressionBuilder<PropertyInfo>(propertyExpressionBuilder); var blockExpression = propertyBlockExpressionBuilder.Create<PropertyExpressionTestClass, PropertyExpressionTestClass>(properties); // assert string propStringValue = "Odin"; int propIntValue = int.MinValue; var action = Expression.Lambda<Action<PropertyExpressionTestClass, PropertyExpressionTestClass>>(blockExpression, this.SourceParameterExpression, this.DestinationParameterExpression).Compile(); PropertyExpressionTestClass sourceObject = new PropertyExpressionTestClass {PropString = propStringValue, PropInt = propIntValue}; var destinationObject = new PropertyExpressionTestClass(); action.Invoke(sourceObject, destinationObject); Assert.Equal(propStringValue, destinationObject.PropString); Assert.Equal(propIntValue, destinationObject.PropInt); }
public void Create_WhenTheFieldsAreSpecified_TheAssignmentIsCorrect() { // arrange var stringField = typeof(FieldExpressionTestClass).GetField(Utils.GetFieldName<FieldExpressionTestClass, string>(p => p.FieldString)); var mergeResultString = new MemberMergeResult<FieldInfo>(stringField); var intField = typeof(FieldExpressionTestClass).GetField(Utils.GetFieldName<FieldExpressionTestClass, int>(p => p.FieldInt)); var mergeResultInt = new MemberMergeResult<FieldInfo>(intField); var fieldExpressionBuilder = new FieldExpressionBuilder(this.SourceParameterExpression, this.DestinationParameterExpression); var fields = new[] { mergeResultString, mergeResultInt }; // act var fieldBlockExpressionBuilder = new MemberBlockExpressionBuilder<FieldInfo>(fieldExpressionBuilder); var blockExpression = fieldBlockExpressionBuilder.Create<FieldExpressionTestClass, FieldExpressionTestClass>(fields); // assert string fieldStringValue = "Thor"; int fieldIntValue = int.MaxValue; var action = Expression.Lambda<Action<FieldExpressionTestClass, FieldExpressionTestClass>>(blockExpression, this.SourceParameterExpression, this.DestinationParameterExpression).Compile(); FieldExpressionTestClass sourceObject = new FieldExpressionTestClass { FieldString = fieldStringValue, FieldInt = fieldIntValue }; var destinationObject = new FieldExpressionTestClass(); action.Invoke(sourceObject, destinationObject); Assert.Equal(fieldStringValue, destinationObject.FieldString); Assert.Equal(fieldIntValue, destinationObject.FieldInt); }