public async void Test_Validate_List() { var builder = _Validation.NewValidatorBuilder <ADStudent>(); builder.RuleSet("A", b => { b.RuleFor(i => i.StudentList).Each().NotNull() .ThenRuleFor(i => i.IntList).Each() .Must(i => i >= 0 && i <= 18) .OverrideError("not student"); }); var v = builder.Build(); var student = new ADStudent() { StudentList = new List <Student>() { new Student() { Age = 13, Name = "v", IntList = new List <int> { 0, 2, 4 } } } }; var context = _Validation.CreateContext(student); var result = await v.ValidateAsync(context); Assert.NotNull(result); Assert.True(result.IsValid); Assert.True(result.Failures.Count == 0); student = student = new ADStudent() { StudentList = new List <Student>() { new Student() { Age = 13, Name = "v", IntList = new List <int> { 0, 2, 4, 23 } } } }; context = _Validation.CreateContext(student); result = await v.ValidateAsync(context); Assert.NotNull(result); Assert.False(result.IsValid); Assert.True(result.Failures.Count == 1); }
public async void Test_Validate_List() { var builder = _Validation.NewValidatorBuilder<ADStudent>(); builder.RuleSet("A", b => { b.RuleFor(i => i.StudentList).Each().NotNull() .ThenRuleFor(i => i.IntList).Each() .Must(i => i >= 0 && i <= 18) .OverrideError("not student"); }); var v = builder.Build(); var student = new ADStudent() { StudentList = new List<Student>() { new Student() { Age = 13, Name = "v", IntList = new List<int> { 0, 2, 4 } } } }; var context = _Validation.CreateContext(student); var result = await v.ValidateAsync(context); Assert.NotNull(result); Assert.True(result.IsValid); Assert.True(result.Failures.Count == 0); student = student = new ADStudent() { StudentList = new List<Student>() { new Student() { Age = 13, Name = "v", IntList = new List<int> { 0, 2, 4,23 } } } }; context = _Validation.CreateContext(student); result = await v.ValidateAsync(context); Assert.NotNull(result); Assert.False(result.IsValid); Assert.True(result.Failures.Count == 1); }
public String getListLessons() { String JSON; try { Response.ContentType = "application/json; charset=UTF-8"; String metodoDeEnvioHTTP = System.Web.HttpContext.Current.Request.HttpMethod; if (metodoDeEnvioHTTP != "POST") { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; Respuesta.estatus = MensajesEstados.ERROR_POST_REQUEST; JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta, null)); } else { string POST; using (Stream receiveStream = Request.InputStream) { using (StreamReader readStream = new StreamReader(receiveStream, Request.ContentEncoding)) { POST = readStream.ReadToEnd(); } } if (POST == null || POST == "") { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; Respuesta.estatus = MensajesEstados.ErrorFatal; JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta, null)); } else { RequestStudentLessons Parametros = JsonConvert.DeserializeObject <RequestStudentLessons>(POST); string Mensaje = ""; if (parametrosValidos(Parametros, ref Mensaje)) { ADStudent coursesAD = new ADStudent(); RespStudentLessons Respuesta = coursesAD.getListLessons(Parametros); JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta.Response, Respuesta.Lessons)); } else { RespStudent Respuesta = new RespStudent(); Respuesta.estatus = Mensaje; Respuesta.code = CodigosRespuesta.codigo.BAD_REQUEST; JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta, null)); } } } } catch (Exception e) { RespStudent Respuesta = new RespStudent(); Respuesta.estatus = MensajesEstados.ErrorFatal + e.Message.ToString(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta, null)); } return(JSON); }