Ejemplo n.º 1
0
 public void FiveElementsWithSixItemsValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         OneElements = new int[] { 1, 2, 3, 4, 5, 6 }
     });
 }
Ejemplo n.º 2
0
 public void ZeroElementsWithNonEmptyIEnumerableValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = Enumerable.Range(0, 1)
     });
 }
Ejemplo n.º 3
0
 public void ZeroElementsWithNonEmptyArrayValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = new int[] { 1 }
     });
 }
Ejemplo n.º 4
0
 public void OneElementsWithSingleItemValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = new int[] { 1 }
     });
 }
Ejemplo n.º 5
0
 public void OneElementsWithEmptyIEnumerableValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = Enumerable.Range(0, 0)
     });
 }
Ejemplo n.º 6
0
 public void FiveElementsWithFiveItemValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         FiveElements = new int[] { 1, 2, 3, 4, 5 }
     });
 }
Ejemplo n.º 7
0
 public void OneElementsWithEmptyArrayValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = new int[] { }
     });
 }
Ejemplo n.º 8
0
 public void OneElementsWithEmptyListValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = (new int[] { }).ToList()
     });
 }
Ejemplo n.º 9
0
 public void OneElementsWithTwoItemsValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         OneElements = new int[] { 1, 2 }
     });
 }
Ejemplo n.º 10
0
 public void ZeroElementsWithNonEmptyListValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = (new int[] { 1, }).ToList()
     });
 }
Ejemplo n.º 11
0
        public void IsNotValidWithNulls()
        {
            var model = new Model()
            {
            };

            Assert.Throws <AggregateValidationException>(() => ExtendedValidator.EnsureIsValid(model));
        }
Ejemplo n.º 12
0
        public void StringIsValid()
        {
            var model = new StringModel()
            {
                Value = "Hello"
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 13
0
        public void BoolNulableIsValid()
        {
            var model = new BoolNulableModel()
            {
                Value = true
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 14
0
        public void GuidIsNotValid()
        {
            var model = new GuidModel()
            {
                Value = default(Guid)
            };

            Assert.Throws <AggregateValidationException>(() => ExtendedValidator.EnsureIsValid(model));
        }
Ejemplo n.º 15
0
        public void ByteNulableIsValid()
        {
            var model = new byteNulableModel()
            {
                Value = byte.MaxValue
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 16
0
        public void IntIsValid()
        {
            var model = new IntModel()
            {
                Value = 5
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 17
0
        public void ShortNulableIsValid()
        {
            var model = new ShortNulableModel()
            {
                Value = (short)5
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 18
0
        public void Expect_Failures_When_Values_Do_Not_Match()
        {
            var obj = new TestClass()
            {
                TrueBoolean = false,
            };

            Assert.Throws <AggregateValidationException>(() => ExtendedValidator.EnsureIsValid(obj));
        }
Ejemplo n.º 19
0
        public void GuidNulableIsValid()
        {
            var model = new GuidNulableModel()
            {
                Value = Guid.NewGuid()
            };

            ExtendedValidator.EnsureIsValid(model);
        }
Ejemplo n.º 20
0
 public void ZeroElementsWithNonEmptyListDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             ZeroElements = (new int[] { 1, }).ToList()
         });
     });
 }
Ejemplo n.º 21
0
 public void FiveElementsWithSixItemsDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             OneElements = new int[] { 1, 2, 3, 4, 5, 6 }
         });
     });
 }
Ejemplo n.º 22
0
 public void FiveElementsWithFourItemDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             FiveElements = new int[] { 1, 2, 3, 4 }
         });
     });
 }
Ejemplo n.º 23
0
 public void OneElementsWithEmptyListDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             OneElements = (new int[] { }).ToList()
         });
     });
 }
Ejemplo n.º 24
0
        public void Ignore_Null_NotRequired_Properties()
        {
            var obj = new TestClass()
            {
                TrueNullableBoolean  = null,
                FalseNullableBoolean = null
            };

            ExtendedValidator.EnsureIsValid(obj);
        }
Ejemplo n.º 25
0
 public void ZeroElementsWithNonEmptyIEnumerableDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             ZeroElements = Enumerable.Range(0, 1)
         });
     });
 }
Ejemplo n.º 26
0
 public void OneElementsWithEmptyIEnumerableDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             OneElements = Enumerable.Range(0, 0)
         });
     });
 }
Ejemplo n.º 27
0
        public void InvalidObjectFailsValidation()
        {
            var dto = BuildDto(false);

            var result = ExtendedValidator.Validate(dto);

            Assert.IsNotNull(result);
            Assert.That(result, Has.Length.EqualTo(3));
            Assert.That(result, Has.Exactly(1).Property("MemberNames").Contains("AString"));
            Assert.That(result, Has.Exactly(1).Property("MemberNames").Contains("Inner.Field"));
            Assert.That(result, Has.Exactly(1).Property("MemberNames").Contains("InnerList[0].Field"));
        }
Ejemplo n.º 28
0
        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            var results = ExtendedValidator.ValidateRecursing(value, context);

            if (results.Count() != 0)
            {
                //_Log.DebugFormat("Validation failed for: {0} | {1} | {2}", validationContext.ObjectType, validationContext.DisplayName, validationContext.MemberName);

                return(AggregateValidationResult.CreateFor(context, results));
            }

            return(ValidationResult.Success);
        }
Ejemplo n.º 29
0
        public void InvalidObjectFailsMaxLengthInnerDto2()
        {
            var dto = BuildDto(true);

            dto.Inner.Field  = "hello";
            dto.Inner.Field2 = "123456789012345";              // Try to fire MaxLengthAttribute..

            var result = ExtendedValidator.Validate(dto);

            Assert.IsNotNull(result);
            Assert.That(result, Has.Length.EqualTo(1));
            Assert.That(result, Has.Exactly(1).Property("MemberNames").Contains("Inner.Field2"));
        }
Ejemplo n.º 30
0
        public void BasicTest()
        {
            var good = new TestDto()
            {
                StringList = new[] { "abcde" }
            };
            var bad = new TestDto()
            {
                StringList = new[] { "a" }
            };

            ExtendedValidator.EnsureIsValid(good);
            Assert.Throws <AggregateValidationException>(() => ExtendedValidator.EnsureIsValid(bad));
        }