我正在使用AutoMapper将IDataReader映射到简单的DTO。NUnit:Automapper <IDataReader,Dto> .ConvertUsing()返回具有空属性的Dto
我可以在使用ForMember时映射属性,但不能在使用ConstructUsing/ConvertUsing时映射属性。在这种情况下,我的所有NUnit测试都会失败,因为AutoMapper会返回一个具有空属性的DTO。 有趣的是,MSTest中不会出现这种行为:在MSTest下运行测试时,映射将起作用。
下面的代码:
public class Dto
{
public string Name { get; set; }
public string Value { get; set; }
}
这传入的NUnit和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"]));
这只能通过在MSTest的和NUnit的与空的属性,将返回DTO:
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"]
};
}
在NUnit中甚至没有调用MyTestMethod。
这是AutoMapper中的一个错误吗?在NUnit中?都?
我不应该使用AutoMapper进行IDataReader映射吗?
在此先感谢。
什么是MyTestMethod?你能发布完整的单元测试吗? –