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 GeneratedImageOptions_DuplicateFree()
 {
     for (var i = 0; i < 100; i++)
     {
         var captcha = new Captcha(10);
         var optionValues = new List<string>();
         foreach (var option in captcha.PossibleImageOptions)
         {
             Assert.IsFalse(optionValues.Contains(option.Key), string.Format("Duplicate option found: {0}", option.Key));
             optionValues.Add(option.Key);
         }
     }
 }
        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);
        }
Esempio n. 5
0
        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));
        }
 private static void GetImageSucceeds(bool isRetina)
 {
     var captcha = new Captcha(10);
     var options = captcha.PossibleImageOptions.ToList();
     for (var i = 0; i < options.Count; i++)
     {
         var bytes = captcha.GetImage(i, isRetina);
         Assert.IsTrue(bytes != null && bytes.Length > 0);
     }
 }
 private static void GetAudioSucceeds(string audioType)
 {
     var captcha = new Captcha(5);
     var bytes = captcha.GetAudio(audioType);
     Assert.IsTrue(bytes != null && bytes.Length > 0);
 }