how to validate a business object?

Topics: General Discussion Forum
Apr 11, 2007 at 4:09 PM
after I add the attribute to the field of a business object, how to perform the validation action?
do I need to invoke the following codes:

inspector.BeforeCall(AddPayeeOperationName, new object[] { payeeRequest });


Apr 12, 2007 at 3:26 AM
You don't need to do that. The validation interception behavior will do all that stuff for you. BTW, when you say "business object" I assume you are referring to a MessageContact or a DataContact/DataType right?
Apr 12, 2007 at 6:38 AM
it's too exhausted to create a business object and then make a same object with the same properties just for data contract purpose, so in our project we just combine the data contract and business object into one stuff: a business object marked with datacontract attribute.

I have another question, can we perform the validation action on the pure object level without service? for example, when I create a Person object and set the Person's email to an invalid value, can I use some method like Person.Validate() to catch the error?

Apr 12, 2007 at 6:41 AM
so my next question is if the framework can do the validation action automatically for me, then why in the unit test codes in WCF RI you use "inspector.BeforeCall(AddPayeeOperationName, new object[] { payeeRequest });"
to get the error message? should you call the service directly and send an invalid value and then expect a FaultException?
Apr 12, 2007 at 7:37 PM
Let's tackle each question:
  1. You can use the validation framework to do this or just take the Validation block from EntLib V3 and perform the same stuff with a better support for validators. You can find all the documentation in the EntLib docs and several Quickstarts as well.
  2. Regarding the validation in the tests, that is actually an nunit of the validation stuff performed by the behavior, in this case the parameter inspecto. However you can add some functional tests using the service like your suggested approach.