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.
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.