Mapper not initialized. Call Initialize with appropriate configuration.
知识就是力量,时间就是生命。这篇文章主要讲述Mapper not initialized. Call Initialize with appropriate configuration.相关的知识,希望能为你提供帮助。
System.InvalidOperationException:“
Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you‘re using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.”
【Mapper not initialized. Call Initialize with appropriate configuration.】
Here is the code for the method that I‘m developing the unit test for:
Following is the code from the mapping configuration file:
And I have initialized mapper in the Application_Start()
event of the
Global.asax
as below:
Below is the simple test method that I‘m trying to run:
It works fine when I simply run the application. But when I try to run the unit test method, it shows the mentioned error message. Can anyone help me to get over this issue? Thanks! c# asp.net-mvc unit-testing automapper
|
|||||||||||||
|
up vote3down voteaccepted | You need to create/register the mappings for your unit tests as well as the
Application_Start()
is not executed. It is associated with IIS, which is not running during unit tests. You have to manually call the mapping configurations.
In the above test the mapping configuration is done in a method decorated with [ClassInitialize] attribute whichClassInitializeAttribute Class Identifies a method that contains code that must be used before any of the tests in the test class have run and to allocate resources to be used by the test class. |
推荐阅读
- ionic App 解决android端在真机上 tab处于顶部的Bug
- ORM轻量级框架---ActiveAndroid
- 适配器未连接,图文详细说明无线网络适配器显示未连接如何处理
- 键盘控制鼠标,图文详细说明如何运用键盘来控制鼠标
- 电脑打开慢,图文详细说明怎样处理电脑打开慢
- qq闪退怎样回事,图文详细说明电脑qq闪退怎样回事
- 电脑还原系统,图文详细说明电脑如何还原系统
- win10 ghost,图文详细说明ghost版Win10怎样安装
- 笔记本搜不到无线网络,图文详细说明笔记本搜不到无线网络怎样办