I'm using AutoMapper to map from IDataReader to a simple DTO.
I'm able to map the properties when I use ForMember, but not when I use ConstructUsing/ConvertUsing. In this case, all my NUnit tests fail, because the AutoMapper returns a DTO with null properties. What's interesting is that this behavior does not occur in MSTest: When running the tests under MSTest, the mapping works.
Here's the code:
public class Dto
{
public string Name { get; set; }
public string Value { get; set; }
}
This passes in NUnit and in MSTest:
Mapper.CreateMap<IDataReader, Dto>()
.ForMember(x => x.Name, map => map.MapFrom(reader => reader["Name"]))
.ForMember(x => x.Value, map => map.MapFrom(reader => reader["Value"]));
This passes only in MSTest and returns Dto with null properties in NUnit:
Mapper.CreateMap<IDataReader, Dto>()
.ConvertUsing(Map); // ConstructUsing doesn't work either
private Dto Map(IDataReader reader)
{
return new Dto
{
Name = (string)reader["Name"],
Value = (string)reader["Value"]
};
}
MyTestMethod is not even called in NUnit.
Is this a bug in AutoMapper? In NUnit? Both?
Should I not use AutoMapper for IDataReader mapping?
Thanks in advance.