AutoMapper.Attributes icon indicating copy to clipboard operation
AutoMapper.Attributes copied to clipboard

IgnoreMapFrom doesn't pass mapping validation

Open tomasaschan opened this issue 8 years ago • 3 comments

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?

tomasaschan avatar Jul 31 '17 15:07 tomasaschan

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; }
}

tomasaschan avatar Aug 01 '17 08:08 tomasaschan

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?

schneidenbach avatar Aug 01 '17 13:08 schneidenbach

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).

MWE.zip

tomasaschan avatar Aug 01 '17 19:08 tomasaschan