public void TestValidate() { var strat = new CachedValidation(); 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(1, 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); }
public void TestInvalidateNames(string propertyName) { var strat = new CachedValidation(); // "assert" that this does not throw strat.Invalidate(propertyName); }