If I have an API Controller that gets am model of type “product” which is checked for valid name via fluentValidation ( nameNotNull, nameNotEmpty) how do I write a unit test for the controller?
What I have read is to mock away all constructor parameters (which in my case also includes fluentValidation)
But what is the point to mock the fluendValidation with either correct or incorrect model validation only to check the model in a unit test to see what’s happening when sending an invalid object to the controller? Such a situation can never happen when the fluentValidation is active.
On the other side it seems also pointless to use fulentValidation to check the mocked object for correctness as it may never fail ( if fluentValidation is made correctly). And also it is not a unit test but an integration test if fluentValidation is used.
I would not even write a unit test in this situation, but our engineers insist to write one.
Whats you opinion?
Manuel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.