How do ForAllPropertyMaps work inside a Profile?

Viewed 273

I'm trying to make a gRPC API and have stumbled upon a weird bug (or maybe I don't know how it work).

If we want to map all IEnumerables to RepeatedFields, we follow this answer: https://stackoverflow.com/a/46412302/2687506

(The function IsToRepeatedField(PropertyMap pm) can be seen in the above link)

When trying to move ForAllPropertyMaps into a Profile, our tests fail.

public class ToRepeatedFieldProfile : Profile
{
    public ToRepeatedFieldProfile()
    {
        ForAllPropertyMaps(IsToRepeatedField, (propertyMap, opts) => opts.UseDestinationValue());
    }
}

public ProfileTests()
{   
    _mapperConfiguration =
        new MapperConfiguration(cfg =>
        {
            cfg.AddProfile<ToRepeatedFieldProfile>();
        });
    _mapper = _mapperConfiguration.CreateMapper();
}

The above code does not work, while the code here under does work:

public ProfileTests()
{   
    _mapperConfiguration =
            new MapperConfiguration(cfg =>
            {
                cfg.ForAllPropertyMaps(IsToRepeatedField, (propertyMap, opts) => opts.UseDestinationValue());
            });
    _mapper = _mapperConfiguration.CreateMapper();
}

This is the test we're trying to perform:

public void AutoMapper_Map_Success_Response()
{
    var updatedIds = new List<Guid>
    {
         new Guid("53c909f8-9803-406a-921f-965ef2cf6301"),
    };
    var response = new Result { UpdatedIds = updatedIds }
    var reply = _mapper.Map<Reply>(response);
    Assert.Equal(1, reply.UpdatedIds.Count);
}

Do you know where I'm thinking wrong?

PS. Sorry for cluttered code, I was trying to remove everything that wasn't important.

1 Answers

The issue was that I was running on 9.0. With the nightly build of 9.1 the issue was solved.

Related