I am writing tests using SpecFlow and ASP.NET MVC and the code steps are perfectly fine. However, I wanted to write tests based on the validation on the model.
In my HomeController (for a login screen), the Index() method is implemented twice, both with different method signatures:
// When the page is initially loaded, the value of null is passed to
// the parameter. This would prompt the view to load the login-screen.
public ActionResult Index(string u) {
// some declaration
return View(model);
}
[HttpPost, ValidateInput(false)]
public ActionResult Index(myobject o) {
// some declaration
return View(model);
}
// No default implementation for Index()
public string SomeSampleFunction() {
return "This is a test string";
}
When I write my tests, every reference to the Index() method retuns null. I tried doing such as:
var _controller = new HomeController();
var _result = _controller.Index("") as ViewResult;
// The succeeding line also returns null
// var _result = _controller.Index(string.empty) as ViewResult;
Assert.IsInstanceOf<ViewResult>(_result);
Assert.IsEmpty(((ViewResult)_result).ViewName);
Assert.AreEqual("Log In", homeController.ViewData["Title"], "Page title is wrong");
Am I missing something on this one? The references to the Index() method is always null but if I call an ordinary method such as "SomeSampleFunction", it works just fine. Any help?
Aucun commentaire:
Enregistrer un commentaire