Exemplo n.º 1
0
        public void EmptyValue_IsValid()
        {
            string value = "", name = "Date";
            var    attr    = new DateRangeAttribute();
            var    context = new ValidationContext(new object(), null, null);

            context.MemberName = name;
            var result = attr.GetValidationResult(value, context);

            Assert.IsNull(result);
        }
Exemplo n.º 2
0
        public void ValidValue_IsValid()
        {
            string value = "2015-01-02T01:00:02", name = "Date";
            var    attr = new DateRangeAttribute();

            attr.Minimum = "2015-01-01T00:00:00";
            attr.Maximum = "2015-01-03T00:00:00";
            var context = new ValidationContext(new object(), null, null);

            context.MemberName = name;
            var result = attr.GetValidationResult(value, context);

            Assert.IsNull(result);
        }
Exemplo n.º 3
0
        public void InvalidValue_IsInvalid()
        {
            string value = "test", name = "Date";
            var    attr = new DateRangeAttribute();

            attr.Minimum = "2015-01-01T00:00:00";
            attr.Maximum = "2015-01-03T00:00:00";
            var context = new ValidationContext(new object(), null, null);

            context.MemberName = name;
            var result = attr.GetValidationResult(value, context);

            Assert.IsNotNull(result);
            Assert.AreEqual("The field Date must be between 2015-01-01 00:00:00 and 2015-01-03 00:00:00.", result.ErrorMessage);
            Assert.AreEqual(1, result.MemberNames.Count());
            Assert.AreEqual(name, result.MemberNames.Single());
        }