Example #1
0
        public void TestValidate()
        {
            var strat = new ImmediateValidation();
            var vm    = new TestViewModel();

            int callCount = 0;

            vm.AllRules.Add(new KeyValuePair <string, IValidationRule>(
                                nameof(TestViewModel.TestProperty),
                                new DelegateValidationRule <int>(x =>
            {
                callCount++;
                return(new ValidationRuleResult(true, "error"));
            })
                                ));


            ValidationRuleResult[] r1 = strat.Validate(vm, nameof(TestViewModel.TestProperty)).ToArray();
            ValidationRuleResult[] r2 = strat.Validate(vm, nameof(TestViewModel.TestProperty)).ToArray();


            // assert that the rule was run once for each call
            Assert.AreEqual(2, callCount);

            // assert that the first run returned the expected results.
            Assert.AreEqual(1, r1.Length);
            Assert.AreEqual(true, r1[0].IsError);
            Assert.AreEqual("error", r1[0].ErrorMessage);

            // assert that the second run returned the expected results.
            Assert.AreEqual(1, r2.Length);
            Assert.AreEqual(true, r2[0].IsError);
            Assert.AreEqual("error", r2[0].ErrorMessage);
        }
Example #2
0
        public void TestInvalidate(string propertyName)
        {
            var strat = new ImmediateValidation();

            // "assert" that this does not throw
            strat.Invalidate(propertyName);
        }