public void TestValidationRulesWithPrivateMember() { //works now because we are calling ValidationRules.CheckRules() in DataPortal_Create UnitTestContext context = GetContext(); Csla.ApplicationContext.GlobalContext.Clear(); HasRulesManager.NewHasRulesManager((o, e) => { HasRulesManager root = e.Object; context.Assert.AreEqual("<new>", root.Name); context.Assert.AreEqual(true, root.IsValid, "should be valid on create"); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); root.BeginEdit(); root.Name = ""; root.CancelEdit(); context.Assert.AreEqual("<new>", root.Name); context.Assert.AreEqual(true, root.IsValid, "should be valid after CancelEdit"); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); root.BeginEdit(); root.Name = ""; root.ApplyEdit(); context.Assert.AreEqual("", root.Name); context.Assert.AreEqual(false, root.IsValid); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description); context.Assert.Success(); }); context.Complete(); }
public void BreakLengthRuleAndClone() { Csla.ApplicationContext.GlobalContext.Clear(); UnitTestContext context = GetContext(); HasRulesManager.NewHasRulesManager((o, e) => { HasRulesManager root = e.Object; root.Name = "12345678901"; context.Assert.AreEqual(false, root.IsValid, "should not be valid before clone"); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); //Assert.AreEqual("Name too long", root.GetBrokenRulesCollection[0].Description; Assert.AreEqual("Name can not exceed 10 characters", root.BrokenRulesCollection[0].Description); root = (HasRulesManager)(root.Clone()); context.Assert.AreEqual(false, root.IsValid, "should not be valid after clone"); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); //Assert.AreEqual("Name too long", root.GetBrokenRulesCollection[0].Description; context.Assert.AreEqual("Name can not exceed 10 characters", root.BrokenRulesCollection[0].Description); root.Name = "1234567890"; context.Assert.AreEqual(true, root.IsValid, "Should be valid"); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); context.Assert.Success(); }); context.Complete(); }
public void BreakRequiredRule() { Csla.ApplicationContext.GlobalContext.Clear(); UnitTestContext context = GetContext(); HasRulesManager.NewHasRulesManager((o, e) => { context.Assert.Try(() => { HasRulesManager root = e.Object; root.Name = ""; context.Assert.AreEqual(false, root.IsValid, "should not be valid"); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description); context.Assert.Success(); }); }); context.Complete(); }
public void TestValidationAfterEditCycle() { //should work since ValidationRules.CheckRules() is called in DataPortal_Create Csla.ApplicationContext.GlobalContext.Clear(); UnitTestContext context = GetContext(); HasRulesManager.NewHasRulesManager((o, e) => { HasRulesManager root = e.Object; context.Assert.AreEqual("<new>", root.Name); context.Assert.AreEqual(true, root.IsValid, "should be valid on create"); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); bool validationComplete = false; root.ValidationComplete += (vo, ve) => { validationComplete = true; }; root.BeginEdit(); root.Name = ""; context.Assert.AreEqual("", root.Name); context.Assert.AreEqual(false, root.IsValid); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description); context.Assert.IsTrue(validationComplete, "ValidationComplete should have run"); root.BeginEdit(); root.Name = "Begin 1"; context.Assert.AreEqual("Begin 1", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); root.BeginEdit(); root.Name = "Begin 2"; context.Assert.AreEqual("Begin 2", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); root.BeginEdit(); root.Name = "Begin 3"; context.Assert.AreEqual("Begin 3", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); HasRulesManager hrmClone = root.Clone(); //Test validation rule cancels for both clone and cloned root.CancelEdit(); context.Assert.AreEqual("Begin 2", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); hrmClone.CancelEdit(); context.Assert.AreEqual("Begin 2", hrmClone.Name); context.Assert.AreEqual(true, hrmClone.IsValid); context.Assert.AreEqual(0, hrmClone.BrokenRulesCollection.Count); root.CancelEdit(); context.Assert.AreEqual("Begin 1", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); hrmClone.CancelEdit(); context.Assert.AreEqual("Begin 1", hrmClone.Name); context.Assert.AreEqual(true, hrmClone.IsValid); context.Assert.AreEqual(0, hrmClone.BrokenRulesCollection.Count); root.CancelEdit(); context.Assert.AreEqual("", root.Name); context.Assert.AreEqual(false, root.IsValid); context.Assert.AreEqual(1, root.BrokenRulesCollection.Count); context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description); hrmClone.CancelEdit(); context.Assert.AreEqual("", hrmClone.Name); context.Assert.AreEqual(false, hrmClone.IsValid); context.Assert.AreEqual(1, hrmClone.BrokenRulesCollection.Count); context.Assert.AreEqual("Name required", hrmClone.BrokenRulesCollection[0].Description); root.CancelEdit(); context.Assert.AreEqual("<new>", root.Name); context.Assert.AreEqual(true, root.IsValid); context.Assert.AreEqual(0, root.BrokenRulesCollection.Count); hrmClone.CancelEdit(); context.Assert.AreEqual("<new>", hrmClone.Name); context.Assert.AreEqual(true, hrmClone.IsValid); context.Assert.AreEqual(0, hrmClone.BrokenRulesCollection.Count); context.Assert.Success(); }); context.Complete(); }