I have the following controller action
public ActionResult EditFocus(int id)
{
var Focus = focusService.GetFocus(id);
Mapper.CreateMap<Focus, FocusFormModel>()
FocusFormModel editFocus = Mapper.Map<Focus, FocusFormModel>(Focus);
if (Focus == null)
{
return HttpNotFound();
}
return View("EditFocus", editFocus);
i am using Nunit for testing. And the test is
[Test]
public void Edit_Get_ReturnsView()
{
FocusFormModel group = new FocusFormModel() { FocusId = 1, FocusName = "Test" };
Mapper.CreateMap<Focus, FocusFormModel>().ForAllMembers(opt => opt.Ignore());
Focus focusViewModel = Mapper.Map<Focus, FocusFormModel>(group);
Mapper.AssertConfigurationIsValid();
focusRepository.Setup(x => x.GetById(1)).Returns(focusViewModel);
FocusController controller = new GroupController(focusService);
ViewResult actual = controller.EditFocus(1) as ViewResult;
Assert.IsNotNull(actual, "View Result is null");
}
but the test fails
In the NUnit GUI I get the following error:
Missing Mapping type Configuration& Unsupported Mapping
You are creating the mapping twice. It should only be done once for web and tests.
web: only create your maps once on application start, possibly using profiles.
tests: create maps in TestFixtureSetUp in specific test or in base Test class if you have one.