public void ValidImageOption_Succeeds() { for (var i = 0; i < 100; i++) { var captcha = new Captcha(5); var data = captcha.GetFrontEndData(); Assert.IsTrue( captcha.ValidateAnswer(data.Values.FirstOrDefault(v => v == captcha.ValidImageOption.Value))); } }
public void InvalidImageOptions_Fail() { for (var i = 0; i < 100; i++) { var captcha = new Captcha(5); var data = captcha.GetFrontEndData(); foreach (var option in data.Values.Where(option => option != captcha.ValidImageOption.Value)) { Assert.IsFalse(captcha.ValidateAnswer(option)); } } }
public JsonResult Start(int numberOfImages) { var captcha = new Captcha(numberOfImages); Session[SessionKey] = captcha; var frontEndData = captcha.GetFrontEndData(); // Client side library requires lowercase property names return Json(new { values = frontEndData.Values, imageName = frontEndData.ImageName, imageFieldName = frontEndData.ImageFieldName, audioFieldName = frontEndData.AudioFieldName }, JsonRequestBehavior.AllowGet); }
public void ProcessRequest(HttpContext context) { int numberOfImages = int.Parse(context.Request.RawUrl.Split('/')[3].Split('?')[0].ToString()); var captcha = new Captcha(numberOfImages); context.Session[SessionKey] = captcha; var frontEndData = captcha.GetFrontEndData(); Json json = new Json() { values = frontEndData.Values, imageName = frontEndData.ImageName, imageFieldName = frontEndData.ImageFieldName, audioFieldName = frontEndData.AudioFieldName }; context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonConvert.SerializeObject(json)); }