views:

27

answers:

2

I am writing unit tests to test an MVC application. How can I validate my view models from a unit test?

A: 

If you are using data annotations for validation you could use reflection to test the presence of validation attributes. If you using FluentValidation then it is a bit more elegant.

Darin Dimitrov