ForAllPropertyMaps如何在配置文件中工作?

问题描述 投票:1回答:1

我正在尝试制作gRPC API,偶然发现了一个奇怪的错误(或者也许我不知道它是如何工作的。)>

如果要映射所有IEnumberables或RepeatedFields,我们将遵循以下答案:https://stackoverflow.com/a/46412302/2687506

(在上面的链接中可以看到功能IsToRepeatedField(PropertyMap pm))>>

[当尝试将ForAllPropertyMaps移到Profile中时,我们的测试失败。

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

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



上面的代码不起作用,而下面的代码起作用:

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

这是我们正在尝试执行的测试:

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

你知道我在想哪里错吗?

PS。抱歉,代码混乱,我正在尝试删除所有不重要的内容。

我正在尝试制作gRPC API并偶然发现了一个奇怪的错误(或者我可能不知道它是如何工作的)。如果我们要映射所有IEnumberables或RepeatedFields,请遵循以下答案:https:// ...

.net-core protocol-buffers automapper grpc .net-core-3.1
1个回答
0
投票

问题是我在9.0上运行。对于9.1的每晚构建,此问题已解决。

© www.soinside.com 2019 - 2024. All rights reserved.