EnsureIsValid() public static method

Ensures the object is valid.
Validation failed
public static EnsureIsValid ( object obj ) : void
obj object The object.
return void
Example #1
0
 public void FiveElementsWithSixItemsValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         OneElements = new int[] { 1, 2, 3, 4, 5, 6 }
     });
 }
Example #2
0
 public void ZeroElementsWithNonEmptyIEnumerableValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = Enumerable.Range(0, 1)
     });
 }
Example #3
0
 public void ZeroElementsWithNonEmptyListValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = (new int[] { 1, }).ToList()
     });
 }
Example #4
0
 public void OneElementsWithSingleItemValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = new int[] { 1 }
     });
 }
Example #5
0
 public void OneElementsWithEmptyIEnumerableValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = Enumerable.Range(0, 0)
     });
 }
Example #6
0
 public void FiveElementsWithFiveItemValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         FiveElements = new int[] { 1, 2, 3, 4, 5 }
     });
 }
Example #7
0
 public void OneElementsWithEmptyArrayValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = new int[] { }
     });
 }
Example #8
0
 public void OneElementsWithEmptyListValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestModel
     {
         OneElements = (new int[] { }).ToList()
     });
 }
Example #9
0
 public void OneElementsWithTwoItemsValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         OneElements = new int[] { 1, 2 }
     });
 }
Example #10
0
 public void ZeroElementsWithNonEmptyArrayValidates()
 {
     ExtendedValidator.EnsureIsValid(new TestClass
     {
         ZeroElements = new int[] { 1 }
     });
 }
Example #11
0
        public void IsNotValidWithNulls()
        {
            var model = new Model()
            {
            };

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

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

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

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

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

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

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

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

            ExtendedValidator.EnsureIsValid(model);
        }
        public void Ignore_Null_NotRequired_Properties()
        {
            var obj = new TestClass()
            {
                TrueNullableBoolean  = null,
                FalseNullableBoolean = null
            };

            ExtendedValidator.EnsureIsValid(obj);
        }
Example #21
0
 public void OneElementsWithEmptyListDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             OneElements = (new int[] { }).ToList()
         });
     });
 }
Example #22
0
 public void FiveElementsWithFourItemDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             FiveElements = new int[] { 1, 2, 3, 4 }
         });
     });
 }
Example #23
0
 public void FiveElementsWithSixItemsDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             OneElements = new int[] { 1, 2, 3, 4, 5, 6 }
         });
     });
 }
Example #24
0
 public void OneElementsWithEmptyIEnumerableDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestClass
         {
             OneElements = Enumerable.Range(0, 0)
         });
     });
 }
Example #25
0
 public void ZeroElementsWithNonEmptyIEnumerableDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             ZeroElements = Enumerable.Range(0, 1)
         });
     });
 }
Example #26
0
 public void ZeroElementsWithNonEmptyListDoesNotValidate()
 {
     Assert.Throws <AggregateValidationException>(() =>
     {
         ExtendedValidator.EnsureIsValid(new TestModel
         {
             ZeroElements = (new int[] { 1, }).ToList()
         });
     });
 }
Example #27
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));
        }
        public void EnsuresIsValidReturnsValidationErrors()
        {
            var dto = BuildDto(false);

            var ex = Assert.Throws <AggregateValidationException>(() =>
            {
                ExtendedValidator.EnsureIsValid(dto);
            });

            Assert.That(ex.ValidationExceptions.ToArray(), Has.Length.EqualTo(3));

            Assert.That(ex.ValidationResult, Is.TypeOf <AggregateValidationResult>());

            var result = (ex.ValidationResult as AggregateValidationResult).Results.ToArray();

            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"));
        }
        public void Basic_Tests()
        {
            var obj = new TestClass();

            ExtendedValidator.EnsureIsValid(obj);
        }
Example #30
0
        public void NullElementsTest()
        {
            var obj = new TestModel();

            ExtendedValidator.EnsureIsValid(obj);
        }