我有 ac# 模型类(Address.cs),它看起来像这样......
namespace myProject.Models
{
[Validator(typeof(AddressValidator))]
public class Address
{
public string AddressLine1 { get; set; }
public string PostCode { get; set; }
}
}
我有一个验证器类(AddressValidator.cs),它看起来像这样......
namespace myProject.Validation
{
public class AddressValidator : AbstractValidator<Address>
{
public AddressValidator()
{
RuleFor(x => x.PostCode).NotEmpty().WithMessage("The Postcode is required");
RuleFor(x => x.AddressLine1).MaximumLength(40).WithMessage("The first line of the address must be {MaxLength} characters or less");
}
}
}
我想知道如何为我的验证器类添加单元测试,以便我可以测试,例如,“地址行 1”最多需要 40 个字符?
HUH函数
慕婉清6462132
相关分类