Example #1
0
 public void Validation_should_succeed_with_a_valid_object()
 {
     Assert.IsTrue(CUT.Validate(new TestViewModel
     {
         NotNull = "blah",
         NotZero = 1
     }).IsValid);
 }
Example #2
0
 public void Validation_should_only_validate_within_a_specified_group()
 {
     Assert.IsTrue(CUT.Validate(new TestViewModel
     {
         NotNull = "blah",
         NotZero = 1
     }).IsValid);
     Assert.IsFalse(CUT.Validate(new TestViewModel
     {
         NotNull = "blah",
         NotZero = 1
     }, "Test").IsValid);
     Assert.IsTrue(CUT.Validate(new TestViewModel
     {
         NotNull   = "blah",
         NotZero   = 1,
         TestGroup = "foo"
     }, "Test").IsValid);
 }
Example #3
0
 public void Validation_should_fail_with_an_empty_object()
 {
     Assert.IsFalse(CUT.Validate(new TestViewModel()).IsValid);
 }
Example #4
0
 public void Validation_validates_using_the_validation_info()
 {
     Assert.IsNotNull(CUT.Validate(new TestViewModel()));
     Assert.AreEqual(2, CUT.Validate(new TestViewModel()).Count);
 }
        public void Validation_should_all_fail_or_true()
        {
            var model0 = new TestViewModel
            {
                NotNull             = "",
                NotZero             = 0,
                TestGroup           = "",
                TestStringLength    = "123456",
                TestShouldBeLong    = "t",
                TestRange           = 1,
                TestRegex           = "1",
                TestCollectionCount = new List <string> {
                    "1"
                },
            };

            model0.TestNCRequired.Value             = "";
            model0.TestNCFieldStringLength.Value    = "123456";
            model0.TestNCFieldShouldBeLong.Value    = "t";
            model0.TestNCFieldRange.Value           = 1;
            model0.TestNCFieldRegex.Value           = "1";
            model0.TestNCFieldCollectionCount.Value = new List <string> {
                "1"
            };

            var val0 = CUT.Validate(model0, "Test");

            Assert.IsFalse(val0.IsValid);

            var val2 = CUT.Validate(new TestViewModel
            {
                NotNull          = null,
                NotZero          = 0,
                TestGroup        = null,
                TestStringLength = null,
                TestShouldBeLong = null,
                TestRange        = 1,
                TestRegex        = null,
            }, "Test");

            Assert.IsTrue(val2.Count == 6);

            var model1 = new TestViewModel
            {
                NotNull          = "dsf",
                NotZero          = 1,
                TestGroup        = "d",
                TestStringLength = "12345",
                TestShouldBeLong = "12",
                TestRange        = 3,
                TestRegex        = "18700000000",
                //TestCollectionCount = new List<string> { "1", "2" },
            };

            model1.TestNCRequired.Value             = "df";
            model1.TestNCFieldStringLength.Value    = "12345";
            model1.TestNCFieldShouldBeLong.Value    = "12";
            model1.TestNCFieldRange.Value           = 3;
            model1.TestNCFieldRegex.Value           = "18700000000";
            model0.TestNCFieldCollectionCount.Value = new List <string> {
                "1", "2"
            };
            var val1 = CUT.Validate(model1, "Test");

            Assert.IsTrue(val1.IsValid);
        }