I am Using Moq package for testing a Controller. HomeController.cs
public class HomeController : Controller
{ readonly IPermitRepository _repository;
public HomeController(IPermitRepository rep)
{ this._repository = rep; }
public ViewResult Index()
{
ViewBag.Message = "Hello World";
PermitModel model = _repository.GetPermitDetails();
return View(model);
}
}
家庭主控测试中 ccs
[TestClass]
Public class HomeControllerTest
{
[TestMethod]
public void Index()
{
var messagingService = new Mock<IPermitRepository>();
var controller = new HomeController(messagingService.Object);
var result = controller.Index() as ViewResult;
Assert.IsInstanceOfType(result.Model, typeof(PermitModel));
}
}
But its giving error. Assert.IsInstanceOfType failed. Expected type:. Actual type:<(null)>.
Can some one provide solution and also some inf about Moq package in MVC3. Thanks in advance