在我的控制器中,我想测试控制器是否正在调用存储库方法。这是控制器中的方法
[HttpGet]
public ActionResult GetModulePropertyName(string moduleTypeValue)
{
var temp = _modulerepository.GetModuleKindPropertyNames(moduleTypeValue);
IList<Property> model = temp
.Select(item => new Property {Name = item})
.ToList();
return PartialView("GetModulePropertyName",model);
}
这是测试方法
[TestMethod]
public void GetModulePropertyName_Action_Calls_GetModuleKindPropertyNames()
{
_mockRepository.Stub(x => x.GetModuleKindPropertyNames(Arg<string>.Is.Anything));
_controller.GetModulePropertyName(Arg<string>.Is.Anything);
_mockRepository.AssertWasCalled(x=>x.GetModuleKindPropertyNames(Arg<string>.Is.Anything));
}
它抛出一个错误说
Test method AdminPortal.Tests.ModuleControllerTests.GetModulePropertyName_Action_Calls_GetModuleKindPropertyNames threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Linq.Queryable.Select(IQueryable`1 source, Expression`1 selector)
at AdminPortal.Areas.Hardware.Controllers.ModuleController.GetModulePropertyName(String moduleTypeValue) in ModuleController.cs: line 83
at AdminPortal.Tests.ModuleControllerTests.GetModulePropertyName_Action_Calls_GetModuleKindPropertyNames() in ModuleControllerTests.cs: line 213
我正在使用RhinoMock作为模拟工具。有人可以帮我解决我犯的错误吗?