Beispiel #1
0
        public void TestInvalidDateStringFormats(string dateString)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.Query.Add("date", new StringValues(dateString));

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateDateAttribute attr = new ValidateDateAttribute();

            attr.OnActionExecuting(actExeContext);

            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Beispiel #2
0
        public void TestValidDateStringFormats(string dateString)
        {
            MockWebContext ctx = new MockWebContext();

            // null value would cause sequence contains no elements exception
            // so we use null here to indicate not to include the date parameter
            if (dateString != null)
            {
                ctx.Query.Add("date", new StringValues(dateString));
            }

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateDateAttribute attr = new ValidateDateAttribute();

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be(0);
        }
Beispiel #3
0
        public void CanGenerateValidators()
        {
            Type         type     = Assembly.GetExecutingAssembly().GetType("Debugging.Tests.ClassWithProperties");
            PropertyInfo property = type.GetProperty("PropertyWithValidators");

            ValidateCreditCardAttribute ccAttribute = property.GetCustomAttributes(typeof(ValidateCreditCardAttribute), false)[0] as ValidateCreditCardAttribute;

            Assert.IsNotNull(ccAttribute);

            ValidateEmailAttribute emailAttribute = property.GetCustomAttributes(typeof(ValidateEmailAttribute), false)[0] as ValidateEmailAttribute;

            Assert.IsNotNull(emailAttribute);

            ValidateRegExpAttribute regExpAttribute = property.GetCustomAttributes(typeof(ValidateRegExpAttribute), false)[0] as ValidateRegExpAttribute;

            Assert.IsNotNull(regExpAttribute);

            ValidateLengthAttribute lengthAttribute = property.GetCustomAttributes(typeof(ValidateLengthAttribute), false)[0] as ValidateLengthAttribute;

            Assert.IsNotNull(lengthAttribute);

            ValidateDateAttribute dateAttribute = property.GetCustomAttributes(typeof(ValidateDateAttribute), false)[0] as ValidateDateAttribute;

            Assert.IsNotNull(dateAttribute);

            ValidateDateTimeAttribute dateTimeAttribute = property.GetCustomAttributes(typeof(ValidateDateTimeAttribute), false)[0] as ValidateDateTimeAttribute;

            Assert.IsNotNull(dateTimeAttribute);

            ValidateDecimalAttribute decimalAttribute = property.GetCustomAttributes(typeof(ValidateDecimalAttribute), false)[0] as ValidateDecimalAttribute;

            Assert.IsNotNull(decimalAttribute);

            ValidateDoubleAttribute doubleAttribute = property.GetCustomAttributes(typeof(ValidateDoubleAttribute), false)[0] as ValidateDoubleAttribute;

            Assert.IsNotNull(doubleAttribute);

            ValidateIntegerAttribute integerAttribute = property.GetCustomAttributes(typeof(ValidateIntegerAttribute), false)[0] as ValidateIntegerAttribute;

            Assert.IsNotNull(integerAttribute);

            ValidateNonEmptyAttribute nonEmptyAttribute = property.GetCustomAttributes(typeof(ValidateNonEmptyAttribute), false)[0] as ValidateNonEmptyAttribute;

            Assert.IsNotNull(nonEmptyAttribute);

            ValidateRangeAttribute rangeAttribute = property.GetCustomAttributes(typeof(ValidateRangeAttribute), false)[0] as ValidateRangeAttribute;

            Assert.IsNotNull(rangeAttribute);

            ValidateSameAsAttribute sameAsAttribute = property.GetCustomAttributes(typeof(ValidateSameAsAttribute), false)[0] as ValidateSameAsAttribute;

            Assert.IsNotNull(sameAsAttribute);

            ValidateSetAttribute setAttribute = property.GetCustomAttributes(typeof(ValidateSetAttribute), false)[0] as ValidateSetAttribute;

            Assert.IsNotNull(setAttribute);

            ValidateSingleAttribute singleAttribute = property.GetCustomAttributes(typeof(ValidateSingleAttribute), false)[0] as ValidateSingleAttribute;

            Assert.IsNotNull(singleAttribute);
        }