using System.ComponentModel.DataAnnotations;
using Util.Validation;
namespace Util.Domain.Tests.Samples;
///
/// 验证规则样例 - 名称长度大于3将验证失败
///
public class ValidationRuleSample : IValidationRule {
///
/// 初始化名称长度验证规则
///
/// 聚合根测试样例
public ValidationRuleSample( AggregateRootSample sample ) {
_sample = sample;
}
///
/// 聚合根测试样例
///
private readonly AggregateRootSample _sample;
///
/// 验证
///
public ValidationResult Validate() {
if( _sample.Name.Length > 3 )
return new ValidationResult( "名称长度不能大于3" );
return ValidationResult.Success;
}
}