2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2687506
  • 789
  • 6
  • 21
  • 1
    A similar test works for me. Do you use 9.0? Try the [MyGet](https://docs.automapper.org/en/latest/The-MyGet-build.html) build. – Lucian Bargaoanu May 22 '20 at 14:44
  • @LucianBargaoanu I was using the 9.0 version. Tried the latest nightly build and it did work! Thank you very much for your help! :) – user2687506 May 25 '20 at 09:40

1 Answers1

0

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

user2687506
  • 789
  • 6
  • 21