In the previous article, we generated the entity code, joined the business and common, the project suddenly became big, now we have a little analysis.
Let's start with this system chart. Let's look at common this DLL, which contains classes, as shown in the following figure.
1, verify the related class (ivalidatable,validater,validateresult,validatefailexception)
These four classes are used primarily at the business level to validate Entity data, and each entity (Entity) validates its own data when it saves data to ensure that illegal data is never saved to the database, and that these four classes serve this feature. The validator (Validater) is the core of these four classes and is responsible for the implementation of the validation. The following test code (located in Dongblog.test\common\validate\validatetest.cs) shows the typical use of this class, that is, through the addcondition Add the validation result (an instance of the Validateresult Class) using the Validate method, adding the condition to be validated (usually an expression) and the error message that is displayed when the validation fails:
1: [TestMethod (), Description ("Validation failed test")]
2:public void Validatefailtest ()
3: {
4:validater Validater = new Validater ()
5:. Addcondition (True, "Error1")
6:. Addcondition (False, "Error2")
7:. Addcondition (False, "Error3");
8:
9:validateresult validateresult = validater. Validate ();
10:assert.isfalse (validateresult.isvalidated);
One:
//validate error message
13:assert.areequal<int> (2, validateResult.ErrorMessage.Length);
14:assert.areequal<string> ("Error2", validateresult.errormessage[0));
15:assert.areequal<string> ("Error3", validateresult.errormessage[1]);
16:}