Exemple #1
0
        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();
        }
Exemple #2
0
        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();
        }