Skip to content

Commit d57a2e7

Browse files
committed
Skipping overridden types during validation; fixes #574
1 parent 6873103 commit d57a2e7

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/AutoMapper/ConfigurationStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ where unmappedPropertyNames.Length > 0
539539

540540
private static bool ShouldCheckMap(TypeMap typeMap)
541541
{
542-
return (typeMap.CustomMapper == null && typeMap.CustomProjection == null) && !FeatureDetector.IsIDataRecordType(typeMap.SourceType);
542+
return (typeMap.CustomMapper == null && typeMap.CustomProjection == null && typeMap.DestinationTypeOverride == null) && !FeatureDetector.IsIDataRecordType(typeMap.SourceType);
543543
}
544544

545545
private TypeMap FindTypeMap(object source, object destination, Type sourceType, Type destinationType, string profileName)

src/UnitTests/ConfigurationValidation.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,41 @@ public void Should_fail_a_configuration_check()
457457
{
458458
typeof(AutoMapperConfigurationException).ShouldBeThrownBy(Mapper.AssertConfigurationIsValid);
459459
}
460-
}
460+
}
461+
462+
public class When_redirecting_types : NonValidatingSpecBase
463+
{
464+
protected override void Establish_context()
465+
{
466+
Mapper.Initialize(cfg =>
467+
{
468+
cfg.CreateMap<ConcreteSource, ConcreteDest>()
469+
.ForMember(d => d.DifferentName, opt => opt.MapFrom(s => s.Name));
470+
cfg.CreateMap<ConcreteSource, IAbstractDest>().As<ConcreteDest>();
471+
});
472+
}
473+
474+
[Fact]
475+
public void Should_pass_configuration_check()
476+
{
477+
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(Mapper.AssertConfigurationIsValid);
478+
}
479+
480+
class ConcreteSource
481+
{
482+
public string Name { get; set; }
483+
}
484+
485+
class ConcreteDest : IAbstractDest
486+
{
487+
public string DifferentName { get; set; }
488+
}
489+
490+
interface IAbstractDest
491+
{
492+
string DifferentName { get; set; }
493+
}
494+
}
461495
}
462496

463497
}

0 commit comments

Comments
 (0)