Example #1
0
        public void BasicValueValidationRuleTest()
        {
            var bizObj = new TestBizRules();
            var record = new TestRecord();
            FieldValidationResults res;

            res = bizObj.ValidateValue(record, "Test1", "Hello");
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test1", "");
            AssertEx.NoError(res);
            Assert.IsNull(res.ProposedValue);

            try
            {
                res = bizObj.ValidateValue(record, "Test4", "Hello");
                Assert.Fail("Expected FieldReadOnlyException to be thrown.");
            }
            catch (FieldReadOnlyException)
            {
                // Expected.
            }
        }
Example #2
0
        public void ValueInSetValidationRuleTest()
        {
            var bizObj = new TestBizRules();

            var rule = new ValueInSetValidationRule <string>();

            rule.ValidValues = new List <string>()
            {
                "TestA", "TestB"
            };
            bizObj["Test1"].Rules.Add(rule);
            var record = new TestRecord();

            var res = bizObj.ValidateValue(record, "Test1", "TestA");

            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test1", "TestB");
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test1", "TestC");
            AssertEx.HasError(res, ValueInSetValidationRule <string> .MSG.ValueNotInSet);
        }
Example #3
0
        public void ValueInRangeValidationRuleTest()
        {
            var bizObj = new TestBizRules();
            var record = new TestRecord();
            FieldValidationResults res;

            res = bizObj.ValidateValue(record, "Test2", 5);
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test2", 0);
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test2", 10);
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test2", -1);
            AssertEx.HasError(res, ValueInRangeValidationRule <int> .MSG.ValueTooSmall);

            res = bizObj.ValidateValue(record, "Test2", 11);
            AssertEx.HasError(res, ValueInRangeValidationRule <int> .MSG.ValueTooGreat);

            res = bizObj.ValidateValue(record, "Test3", new DateTime(2000, 6, 1));
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test3", new DateTime(2000, 1, 1));
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test3", new DateTime(2000, 12, 31));
            AssertEx.NoError(res);

            res = bizObj.ValidateValue(record, "Test3", new DateTime(1999, 12, 31));
            AssertEx.HasError(res, ValueInRangeValidationRule <DateTime> .MSG.ValueTooSmall);

            res = bizObj.ValidateValue(record, "Test3", new DateTime(2001, 1, 1));
            AssertEx.HasError(res, ValueInRangeValidationRule <DateTime> .MSG.ValueTooGreat);
        }