且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

映射器未初始化,我的单元测试Core.Net 2.0错误

更新时间:2023-10-12 10:15:52

您在单元测试中缺少映射器的初始化。下面的代码在 CarsControllerTest 类构造函数中初始化映射器。

You are missing initialization of your mapper in your unit test. The following initializes the mapper in the CarsControllerTest class constructor.

[TestFixture]
public class CarsControllerTest
{
    public CarsControllerTest()
    {
        Mapper.Initialize(cfg =>
        {
            cfg.AddProfile<AutoMapperProfile>();
        });
    }
}