asp.net mvc - How to get the Model from an ActionResult? -
i'm writing unit test , call action method this
var result = controller.action(123);
result actionresult
, need model somehow, knows how this?
in version of asp.net mvc there no action
method on controller. however, if meant view
method, here's how can unit test result contains correct model.
first of all, if return viewresult particular action, declare method returning viewresult instead of actionresult.
as example, consider index action
public viewresult index() { return this.view(this.userviewmodelservice.getusers()); }
you can model this
var result = sut.index().viewdata.model;
if method signature's return type actionresult instead of viewresult, need cast viewresult first.
Comments
Post a Comment