i call a controller action in a unit test.
ViewResult result = c.Index(null,null) as ViewResult;
I cast the result to a ViewResult, because that is what i'm returning in the controller:
return View(model);
But how can i access this model variable in my unit test?
// Arrange
var c = new MyController();
//Act
var result = c.Index(null,null);
var model = result.ViewData.Model;
//Assert
Assert("model is what you want");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With