user3504028
user3504028

Reputation: 77

Unit testing ModelState.IsValid

I've been recently dabbling into unit testing and I was wondering if I'm able to unit test one of my controllers in my project, is it possible to add errors or imitate an invalid ModelState?

Any help would be appreciated

Upvotes: 2

Views: 285

Answers (1)

CinnamonBun
CinnamonBun

Reputation: 1150

You can add errors to the ModelState by using

ModelState.AddModelError("key", "exception");

More information can be found on MSDN.

I Hope this helps.

Upvotes: 3

Related Questions