1

With AutoMapper <= 3.0, this following test passes.

public class AutoMapperTest
{
    static Source source;
    static Destination destination;

    Establish context = () =>
        {
            Mapper.Configuration.AllowNullCollections = false;
            Mapper.CreateMap<Source, Destination>();

            source = new Source { Name = null, Data = null };
        };

    Because of = () => destination = Mapper.Map<Destination>(source);

    It should_map_name_to_null = () => destination.Name.ShouldBeNull();

    It should_map_array_to_empty = () => destination.Data.ShouldNotBeNull();
}

public class Source
{
    public string Name { get; set; }
    public string[] Data { get; set; }
}

public class Destination
{
    public string Name { get; set; }
    public string[] Data { get; set; }
}

As of version 3.1, the should_map_array_to_empty assertion fails because destination.Data is set to null and not an empty array as previously. Is there a way to restore the previous behaviour, preferably globally as opposed to individually per configured map?

The configuration option Mapper.Configuration.AllowNullCollections = false appears to make no difference in this case regardless of the versions of AutoMapper I've tried.

4

0 回答 0