AutoMapper.Attributes
AutoMapper.Attributes copied to clipboard
IgnoreMapFrom doesn't pass mapping validation
The following test correctly fails:
public class Foo
{
public string Bar { get; set; }
}
[MapsFrom(typeof(Foo))]
public class Qux
{
public string Bar { get; set; }
public string Baz { get; set; }
}
public class IgnoredPropertyTests
{
[Fact]
public void IgnoredPropertyYieldsValidMapping()
{
var config = new MapperConfiguration(cfg =>
{
typeof(Foo).GetTypeInfo().Assembly.MapTypes(cfg);
});
config.AssertConfigurationIsValid();
}
}
To fix the test, I can add [IgnoreMap] to Baz. However, I cannot add [IgnoreMapFrom(typeof(Foo))] - despite that attribute, the mapping validation still fails. Is that the intended behavior, or a bug?
Update: this problem doesn't seem to be only for [IgnoreMap], either. This also fails (both the test and executing the actual mapping):
[MapsFrom(typeof(Foo))]
public class Qux
{
public string Bar { get; set; }
[MapsFromProperty(typeof(Foo), nameof(Foo.Bar))]
public string Baz { get; set; }
}
I'm not able to reproduce the behavior you're seeing for either of those samples - they work as expected for me. Can you send me a VS solution that reproduces the problem?
Sure; here's a solution with a single xUnit test project, which has four tests that specify how I'd expect this to work. Two of them pass - one of which (TypeWithIgnoredMapFrom_CanBeMapped) I think shouldn't, since it relies on a mapping that fails validation in another test (MappingsAreValid; check the output of that test for details).