0

I'm doing an ASP.Net MVC2 project and developing some unit test cases on it. In one of my controllers,

String AllowedActions = "";
AllowedActions = entities.sp_IsAuthorized(GetLoggedUserId(), 1, item.SubCategoryId, "CreateMeeting_HTML").FirstOrDefault();

I was unable to mock this sp_IsAuthorized() method ,

    public ObjectResult<global::System.String> sp_IsAuthorized(.....){

}

I tried to mock it in this way,

var entity = new Mock<TestMVCProductEntities>();
entity.Setup(x => x.sp_IsAuthorized(...)).Return(???);

but I have no clue how to return

ObjectResult

this type of object. Help me.

4

1 回答 1

0

您不能创建 ObjectResult 的新实例,也不能模拟它,因为它被标记为密封。我建议您将数据上下文的使用包装到工作单元或类似模式中,使其在单元测试中可测试。

于 2012-07-13T14:59:50.003 回答