This project is read-only.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infancy.Core.Entities;
using Infancy.Core.Validation;

namespace Infancy.Test {
    public class TestEntity : ValidateEntityBase<TestEntity> {
        [RegexValidate(@"[a-zA-Z\d_]{3,16}@[a-zA-Z\d]{3,12}(?:\.[a-zA-Z]{2,4}){1,2}$",
            true,
            Message = "邮箱验证错误")]
        public string Mail { get; set; }

        [NullableValidate]
        public string Info { get; set; }

        [RegexValidate("\\w+", Message = "用户名不能为空且必须为字符.")]
        public string Name { get; set; }
    }
}

测试代码:
        [TestMethod()]
        public void ValidateTest() {
            TestEntity testEntity = new TestEntity() {
                Mail = "fdsfdsfdsfd",
                Name = "aaa"
            };
            ValidatedResult result = testEntity.Validate();
            Assert.IsFalse(result.Result);
            testEntity.Mail = "admin@leven.com.cn";
            Assert.IsTrue(testEntity.Validate().Result);
            testEntity.Mail = null;
            Assert.IsTrue(testEntity.Validate().Result);
            testEntity.Mail = string.Empty;
            Assert.IsTrue(testEntity.Validate().Result);
            testEntity.Info = null;
            Assert.IsTrue(testEntity.Validate().Result);
            testEntity.Info = string.Empty;
            Assert.IsTrue(testEntity.Validate().Result);
            testEntity.Name = null; 
            Assert.IsFalse(testEntity.Validate().Result);
            testEntity.Name = string.Empty;
            Assert.IsFalse(testEntity.Validate().Result);
            testEntity.Name = "aaa43";
            Assert.IsTrue(testEntity.Validate().Result);
        }

Last edited Nov 19, 2008 at 9:09 AM by leven, version 1

Comments

No comments yet.