1

我有以下控制器动作

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);

我正在使用 Nunit 进行测试。测试是

 [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");

}

但测试失败在 NUnit GUI 中出现以下错误:

Missing Mapping type Configuration& Unsupported Mapping
4

1 回答 1

1

您正在创建两次映射。对于web测试,它应该只执行一次。

web:仅在应用程序启动时创建一次地图,可能使用配置文件

测试:在特定测试中的 TestFixtureSetUp 中创建地图,如果有的话,可以在基础测试类中创建地图。

于 2012-11-21T11:44:57.440 回答