Here is the code for the method that I am developing unit test for:
public ActionResult ItemsListing() { var itemsList = itemsRepository.GetItems(true); if (itemsList.Count() > 0) { var itemsListVMs = Mapper.Map<IEnumerable<Item>, IEnumerable<itemsListingViewModel>>(itemsList); return View(itemsListVMs); } else { return RedirectToAction("Home"); } }
The following is the code from the mapping configuration file:
public static class MappingConfig { public static void RegisterMaps() { Mapper.Initialize(config => { config.CreateMap<Item, itemsListingViewModel>(); }); } }
And I initialized mapper in the Application_Start() event of Global.asax , as shown below:
MappingConfig.RegisterMaps();
The following is a simple verification method that I am trying to run:
[TestMethod] public void ItemsListing() { HomeController controller = new HomeController(); ViewResult result = controller.ItemsListing() as ViewResult; Assert.IsNotNull(result); }
It works great when I just run the application. But when I try to run the unit test method, it shows the specified error message. Can someone help me solve this problem? Thanks!
source share