Skip to content

Commit

Permalink
Allowing source-rooted maps to include MapFrom when validating
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Dec 8, 2011
1 parent 4a4ed49 commit 3f42da3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/AutoMapper/TypeMap.cs
Expand Up @@ -127,10 +127,19 @@ public string[] GetUnmappedPropertyNames()
.Except(autoMappedProperties)
.Except(inheritedProperties);
else
{
var redirectedSourceMembers = _propertyMaps
.Where(pm => pm.IsMapped())
.Where(pm => pm.CustomExpression != null)
.Select(pm => pm.SourceMember.Name);

properties = _sourceType.GetPublicReadAccessors()
.Select(p => p.Name)
.Except(autoMappedProperties)
.Except(inheritedProperties);
.Except(inheritedProperties)
.Except(redirectedSourceMembers)
;
}

return properties.Where(memberName => !IgnorePropertiesStartingWith.Any(memberName.StartsWith)).ToArray();
}
Expand Down
29 changes: 29 additions & 0 deletions src/UnitTests/ReverseMapping.cs
Expand Up @@ -106,5 +106,34 @@ public void Should_throw_a_configuration_validation_error()
}
}

public class When_validating_only_against_source_members_and_unmatching_source_members_are_manually_mapped : NonValidatingSpecBase
{
public class Source
{
public int Value { get; set; }
public int Value2 { get; set; }
}
public class Destination
{
public int Value { get; set; }
public int Value3 { get; set; }
}

protected override void Establish_context()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Source, Destination>(MemberList.Source)
.ForMember(dest => dest.Value3, opt => opt.MapFrom(src => src.Value2));
});
}

[Test]
public void Should_not_throw_a_configuration_validation_error()
{
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(Mapper.AssertConfigurationIsValid);
}
}

}
}

0 comments on commit 3f42da3

Please sign in to comment.