You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReverseMap creates invalid configuration when Source and Destination support different int values #27
Destination.OnlyInDestination will map to Source.OnlyInSource because of the ReverseMap()
Actual behavior
AssertConfigurationIsValid() throws
Trying to map Destination to Source throws
In both cases the error is:
AutoMapper.AutoMapperMappingException : Value OnlyInDestination of type AutoMapper.Extensions.EnumMapping.Tests.ReverseCustomEnumValueMappingByValue+OnlyInSourceValueIsMappedToOnlyInDestiationValue+Destination not supported
Steps to reproduce
// This slightly altered test from the project's test suite will fail
public class OnlyInSourceValueIsMappedToOnlyInDestinationValue : AutoMapperSpecBase
{
readonly List<Source> _results = new List<Source>();
public enum Source { Default, OnlyInSource = 3 }
public enum Destination { Default, OnlyInDestination = 4}
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(cfg =>
{
cfg.EnableEnumMappingValidation();
cfg.CreateMap<Source, Destination>()
.ConvertUsingEnumMapping(opt => opt.MapByValue()
.MapValue(Source.OnlyInSource, Destination.OnlyInDestination))
.ReverseMap();
});
protected override void Because_of()
{
_results.Add(Mapper.Map<Destination, Source>(Destination.Default));
_results.Add(Mapper.Map<Destination, Source>(Destination.OnlyInDestination));
}
[Fact]
public void Should_map_using_custom_map()
{
_results[0].ShouldBe(Source.Default);
_results[1].ShouldBe(Source.OnlyInSource);
}
}
Activity
lbargaoanu commentedon Dec 19, 2024
A PR is welcome. Features might be useful here.