Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: Enable mocking of ModelState in ApiController [926]

$
0
0
Include a setter for the ModelState property of ApiController so that it can be mocked easily.
Make ModelStateDictionary methods virtual to enable mocking them.

When trying to test an action that involves an invalid model state, the user needs to use the existing ModelState in ApiController and add an error manually in order to make the ModelState.IsValid property false.
```
controller.ModelState.AddModelError("Name", "The Name property is required");
```
The same logic can be applied to other methods on the class. The inability to mock methods in ModelStateDictionary forces the user to know how this class works in order to write the test when his focus is on the response of the method, not on why the model is invalid.
Comments: This is already sufficiently easy to do without adding virtual methods that would otherwise just complicated the design of the system.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>