public void NotifyDataErrorInfo() { var context = GetContext(); var root = new TwoPropertyRules(); int errorsChanged = 0; root.ErrorsChanged += (o, e) => { errorsChanged++; }; root.Value2 = "b"; context.Assert.AreEqual(2, errorsChanged); var indei = root as System.ComponentModel.INotifyDataErrorInfo; context.Assert.IsTrue(indei.HasErrors); int count = 0; foreach (var item in indei.GetErrors("Value2")) { count++; } context.Assert.IsTrue(count > 0); root.Value1 = "a"; context.Assert.AreEqual(4, errorsChanged); context.Assert.Success(); context.Complete(); }
public void TwoRules() { var context = GetContext(); var root = new TwoPropertyRules(); var rule = new TwoProps(TwoPropertyRules.Value1Property, TwoPropertyRules.Value2Property); var ctx = new Csla.Rules.RuleContext(null, rule, root, new Dictionary <Core.IPropertyInfo, object> { { TwoPropertyRules.Value1Property, "a" }, { TwoPropertyRules.Value2Property, "b" } }); ((Csla.Rules.IBusinessRule)rule).Execute(ctx); context.Assert.AreEqual(0, ctx.Results.Count); ctx = new Csla.Rules.RuleContext(null, rule, root, new Dictionary <Core.IPropertyInfo, object> { { TwoPropertyRules.Value1Property, "" }, { TwoPropertyRules.Value2Property, "a" } }); ((Csla.Rules.IBusinessRule)rule).Execute(ctx); context.Assert.AreEqual(1, ctx.Results.Count); context.Assert.Success(); context.Complete(); }
public void AddSuccessResultDoesNotFail() { var root = new TwoPropertyRules(); var rule = new TwoProps(TwoPropertyRules.Value1Property, TwoPropertyRules.Value2Property); var ctx = new Csla.Rules.RuleContext(null, rule, root, new Dictionary <Core.IPropertyInfo, object> { { TwoPropertyRules.Value1Property, "a" }, { TwoPropertyRules.Value2Property, "b" } }); ctx.AddSuccessResult(false); Assert.IsTrue(true, "Must not fail."); }
public void AddInformationResultOnPropertyThrowsErrorWhenMessageIsEmpty() { var root = new TwoPropertyRules(); var rule = new TwoProps(TwoPropertyRules.Value1Property, TwoPropertyRules.Value2Property); var ctx = new Csla.Rules.RuleContext(null, rule, root, new Dictionary <Core.IPropertyInfo, object> { { TwoPropertyRules.Value1Property, "a" }, { TwoPropertyRules.Value2Property, "b" } }); ctx.AddInformationResult(TwoPropertyRules.Value1Property, string.Empty); Assert.Fail("Must throw exception."); }
public void AddInformationResultThrowsErrorWhenMessageIsEmpty() { var root = new TwoPropertyRules(); var rule = new TwoProps(TwoPropertyRules.Value1Property, TwoPropertyRules.Value2Property); var applicationContext = _testDIContext.CreateTestApplicationContext(); var ctx = new Csla.Rules.RuleContext(applicationContext, null, rule, root, new Dictionary <Core.IPropertyInfo, object> { { TwoPropertyRules.Value1Property, "a" }, { TwoPropertyRules.Value2Property, "b" } }); ctx.AddInformationResult(string.Empty, false); Assert.Fail("Must throw exception."); }