|
Here's the code for the method, that I ' m developing, the unit test for:
Public ActionResult Itemslisting(){ VarItemslist=Itemsrepository.GetItems(True); If (Itemslist.Count() > 0) { VarItemslistvms= Mapper.Map<IEnumerable<item>, Ienumerable<itemslistingviewmodel>> (itemsList< Span class= "pun"); return view ( itemslistvms); } else { return redirecttoaction "Home" }} /span>
Following is the code from the mapping configuration file:
Public Static Class Mappingconfig{ public static void registermaps () { mapper. Initialize (config => { Config. Createmap<item,> (); }} /span>
and I have initialized mapper in the event of the as Application_Start() Global.asax below:
MappingConfig.RegisterMaps();
Below is the simple test method, that I ' m trying to run:
[TestMethod]Public void Itemslisting () { homecontroller< Span class= "PLN" > controller = new homecontroller (); viewresult result = controller itemslisting () as Span class= "Typ" >viewresult;assert. Isnotnullresult /span>
It works fine when I simply run the application. But if I try to run the unit test method, it shows the mentioned error message. Can anyone help me to get through this issue? thanks!
C # ASP.NET-MVC Unit-testing AutoMapper
| shareimprove this question |
edited Aug 15:30 nkosi33.7k9 2864 |
asked aug +" at 14:42 User199060< Span class= "Badge3" >10 |
|