Hi
I have written an extension for property mapping that can be used like this:
But I like the proposed syntax more :)
.Where(dto => dto.Product.ManufacturerName).ShouldMapTo(o => o.Product.Manufacturer.Name)
I have written an extension for property mapping that can be used like this:
result.ShouldBeEquivalentTo(expected, opt => opt.Mapping<YType>(x => x.Foo, y => y.Bar));
publicclass EquivalencyAssertionOptions<TSubject> { public EquivalencyAssertionOptions<TSubject> Mapping<TMatch>( Expression<Func<TSubject, object>> propertyFromExpression, Expression<Func<TMatch, object>> propertyToExpression) { this.Using(new MatchByMappingRule(ExpressionExtensions.GetPropertyPath(propertyFromExpression), ExpressionExtensions.GetPropertyPath(propertyToExpression))); returnthis; } } publicclass MatchByMappingRule : IMatchingRule { privatereadonlystring _propertyPathSubject; privatereadonlystring _propertyPathExpectation; public MatchByMappingRule(string propertyPathSubject, string propertyPathExpectation) { _propertyPathSubject = propertyPathSubject; _propertyPathExpectation = propertyPathExpectation; } public PropertyInfo Match(PropertyInfo subjectProperty, object expectation, string propertyPath) { if (subjectProperty.Name.Equals(_propertyPathSubject)) { return expectation.GetType().GetProperty(_propertyPathExpectation); } returnnull; } publicoverridestring ToString() { returnstring.Format("Mapping property {0} to {1}", _propertyPathSubject, _propertyPathExpectation); } }
.Where(dto => dto.Product.ManufacturerName).ShouldMapTo(o => o.Product.Manufacturer.Name)