Пример #1
0
        public void NumValidationException()
        {
            var message = "Input is invalid.";

            try
            {
                var success = AntiXssValidation.IsNumeric("aa", 2, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            try
            {
                var success = AntiXssValidation.IsNumeric(null, 2, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }
            Assert.IsTrue(AntiXssValidation.IsNumeric("11", 2, false, false));
            Assert.IsTrue(AntiXssValidation.IsNumeric(null, 2, true, false));
            Assert.IsFalse(AntiXssValidation.IsNumeric("1a", 2, false, true));
            Assert.IsFalse(AntiXssValidation.IsNumeric(null, 2, false, true));
        }
Пример #2
0
 public void NumValidationLengthRange()
 {
     Assert.IsFalse(AntiXssValidation.IsNumeric("1", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsNumeric("11", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsNumeric("111", 2, 3, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("1111", 2, 3, false));
 }
Пример #3
0
 public void NumValidationWithNullInput()
 {
     Assert.IsTrue(AntiXssValidation.IsNumeric(null, 1, true));
     Assert.IsTrue(AntiXssValidation.IsNumeric(null, 1, 2, true));
     Assert.IsFalse(AntiXssValidation.IsNumeric(null, 1, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric(null, 1, 2, false));
 }
Пример #4
0
 public void NumValidationSpecificLength()
 {
     Assert.IsTrue(AntiXssValidation.IsNumeric("111", 3, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("11", 3, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("", 3, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric(" ", 3, false));
 }
Пример #5
0
 public void AlphaNumValidationLengthRange()
 {
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("a", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("a1", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("a11", 2, 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("a111", 2, 3, false));
 }
Пример #6
0
        public void AlphaValidationLengthRangeException()
        {
            var message = "Input is invalid.";

            try
            {
                var success = AntiXssValidation.IsAlphabetic("!aa", 2, 4, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            try
            {
                var success = AntiXssValidation.IsAlphabetic(null, 2, 4, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }
            Assert.IsTrue(AntiXssValidation.IsAlphabetic("aaa", 2, 4, false, false));
            Assert.IsTrue(AntiXssValidation.IsAlphabetic(null, 2, 4, true, false));
            Assert.IsFalse(AntiXssValidation.IsAlphabetic("!a", 2, 4, false, true));
            Assert.IsFalse(AntiXssValidation.IsAlphabetic(null, 2, 4, false, true));
        }
Пример #7
0
 public void AlphaValidationWithNullInput()
 {
     Assert.IsTrue(AntiXssValidation.IsAlphabetic(null, 1, true));
     Assert.IsTrue(AntiXssValidation.IsAlphabetic(null, 1, 2, true));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic(null, 1, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic(null, 1, 2, false));
 }
Пример #8
0
 public void AlphaValidationSpecificLength()
 {
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("aaa", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("aa", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic(" ", 3, false));
 }
Пример #9
0
        public void CustomValidationException()
        {
            var message = "Input is invalid.";

            try
            {
                var success = AntiXssValidation.IsValid("a", "^[a-z]{2}$", false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            try
            {
                var success = AntiXssValidation.IsValid(null, "^[a-z]{2}$", false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            Assert.IsTrue(AntiXssValidation.IsValid("aa", "^[a-z]{2}$", false, false));
            Assert.IsFalse(AntiXssValidation.IsValid("aaa", "^[a-z]{2}$", false, true));
            Assert.IsTrue(AntiXssValidation.IsValid(null, "^[a-z]{2}$", true, false));
            Assert.IsFalse(AntiXssValidation.IsValid(null, "^[a-z]{2}$", false, true));
        }
Пример #10
0
        public void AlphaNumValidationMethodException()
        {
            var message = "Input is invalid.";

            try
            {
                var success = AntiXssValidation.IsValidAlphanumeric("aa123", 2, 3, false, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            try
            {
                var success = AntiXssValidation.IsValidAlphanumeric(null, 2, 3, false, false, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(message, e.Message);
            }

            Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric("aa123", 2, 3, true, false, false));
            Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric(null, 2, 3, true, true, false));
            Assert.IsFalse(AntiXssValidation.IsValidAlphanumeric("aa123", 2, 3, false, false, true));
            Assert.IsFalse(AntiXssValidation.IsValidAlphanumeric(null, 2, 3, false, false, true));
        }
Пример #11
0
 public void AlphaValidationLengthRange()
 {
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("a", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("aa", 2, 3, false));
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("aaa", 2, 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("aaaa", 2, 3, false));
 }
Пример #12
0
 public void AlphaNumValidationSpecificLength()
 {
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("1aa", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("1a", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("", 3, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric(" ", 3, false));
 }
Пример #13
0
 public void CustomValidation()
 {
     //Assert
     Assert.IsTrue(AntiXssValidation.IsValid("aa", "^[a-z]{2}$", false));
     Assert.IsFalse(AntiXssValidation.IsValid("aaa", "^[a-z]{2}$", false));
     Assert.IsTrue(AntiXssValidation.IsValid(null, "^[a-z]{2}$", true));
     Assert.IsFalse(AntiXssValidation.IsValid(null, "^[a-z]{2}$", false));
 }
Пример #14
0
 public void AlphaNumValidationMethod()
 {
     Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric("aa123", 2, 3, true, false));
     Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric("bb123", 2, 3, true, false));
     Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric("111aa", 2, 3, false, false));
     Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric(null, 2, 3, false, true));
     Assert.IsFalse(AntiXssValidation.IsValidAlphanumeric(null, 2, 3, false, false));
 }
Пример #15
0
 public void AlphaValidationAnyLength()
 {
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("aaAAjj", 0, false));
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("aaAAjjrr", 0, false));
     Assert.IsTrue(AntiXssValidation.IsAlphabetic("this string".Replace(" ", ""), 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("this string", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("aa1AAjjrr", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic("", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphabetic(" ", 0, false));
 }
Пример #16
0
 public void NumValidationAnyLength()
 {
     Assert.IsTrue(AntiXssValidation.IsNumeric("112233", 0, false));
     Assert.IsTrue(AntiXssValidation.IsNumeric("1122", 0, false));
     Assert.IsTrue(AntiXssValidation.IsNumeric("111 222".Replace(" ", ""), 0, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("111 222", 0, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("12a32", 0, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric("", 0, false));
     Assert.IsFalse(AntiXssValidation.IsNumeric(" ", 0, false));
 }
Пример #17
0
 public void AlphaNumValidationAnyLength()
 {
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("aa1A1j", 0, false));
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("aaAA1j1r", 0, false));
     Assert.IsTrue(AntiXssValidation.IsAlphaNumeric("this str1ng".Replace(" ", ""), 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("this str1ng", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("aa$AA1jrr", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric("", 0, false));
     Assert.IsFalse(AntiXssValidation.IsAlphaNumeric(" ", 0, false));
 }
Пример #18
0
        public void AlphaNumValidationMethodWithInvalidInput()
        {
            // Arrange
            var  invalidInput = new string[] { "", " ", "a", "aa", "a1", "11", "a123", "aa12a", "11aaa" };
            bool result       = true;

            // Act
            foreach (string input in invalidInput)
            {
                if (AntiXssValidation.IsValidAlphanumeric(input.Trim(), 2, 3, true, false))
                {
                    result = false;
                }
            }

            // Assert
            Assert.AreEqual(true, result);
        }
Пример #19
0
 public void AlphaNumValidationMethodWithNullInput()
 {
     //Assert
     Assert.IsTrue(AntiXssValidation.IsValidAlphanumeric(null, 1, 2, true, true));
     Assert.IsFalse(AntiXssValidation.IsValidAlphanumeric(null, 1, 2, true, false));
 }