【发布时间】:2018-08-14 14:34:13
【问题描述】:
我有一个 c# 模型类 (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 个字符?
【问题讨论】:
标签: c# unit-testing fluentvalidation