using System; using System.Collections.Generic; using Util.Validation.Tests.Samples; using Xunit; namespace Util.Validation.Tests; /// /// 验证拦截器测试 /// public class ValidAttributeTest { /// /// 测试服务 /// private readonly ITestService _service; /// /// 测试初始化 /// public ValidAttributeTest( ITestService service ) { _service = service; } /// /// 验证单个对象 /// [Fact] public void TestValidate() { Sample sample = new Sample(); Assert.Throws( () => { _service.Call( sample ); } ); } /// /// 验证单个对象 - 验证通过不会抛出异常 /// [Fact] public void TestValidate_2() { Sample sample = new Sample {RequiredValue = "a"}; _service.Call( sample ); } /// /// 验证集合对象 /// [Fact] public void TestValidateCollection() { List samples = new List {new Sample(), new Sample() }; Assert.Throws( () => { _service.CallCollection( samples ); } ); } /// /// 验证集合对象 - 验证通过不会抛出异常 /// [Fact] public void TestValidateCollection_2() { List samples = new List { new Sample{RequiredValue = "a"}, new Sample{RequiredValue = "b"} }; _service.CallCollection( samples ); } }