예제 #1
0
        public void VerifyUndoableStateStackOnClone()
        {
            Csla.ApplicationContext.GlobalContext.Clear();
            using (UnitTestContext context = GetContext())
            {
                HasRulesManager2.NewHasRulesManager2((o, e) =>
                {
                    context.Assert.IsNull(e.Error);
                    HasRulesManager2 root = e.Object;

                    string expected = root.Name;
                    root.BeginEdit();
                    root.Name = "";
                    HasRulesManager2 rootClone = root.Clone();
                    rootClone.CancelEdit();

                    string actual = rootClone.Name;
                    context.Assert.AreEqual(expected, actual);
                    context.Assert.Try(rootClone.ApplyEdit);

                    context.Assert.Success();
                });
                context.Complete();
            }
        }
예제 #2
0
        public void TestValidationRulesAfterClone()
        {
            //this test uses HasRulesManager2, which assigns criteria._name to its public
            //property in DataPortal_Create.  If it used HasRulesManager, it would fail
            //the first assert, but pass the others
            Csla.ApplicationContext.GlobalContext.Clear();
            UnitTestContext context = GetContext();

            HasRulesManager2.NewHasRulesManager2((o, e) =>
            {
                context.Assert.Try(() =>
                {
                    HasRulesManager2 root = e.Object;
                    context.Assert.AreEqual(true, root.IsValid);
                    root.BeginEdit();
                    root.Name = "";
                    root.ApplyEdit();

                    context.Assert.AreEqual(false, root.IsValid);
                    HasRulesManager2 rootClone = root.Clone();
                    context.Assert.AreEqual(false, rootClone.IsValid);

                    rootClone.Name = "something";
                    context.Assert.AreEqual(true, rootClone.IsValid);
                    context.Assert.Success();
                });
            });
            context.Complete();
        }
예제 #3
0
        public void TestValidationRulesWithPublicProperty()
        {
            UnitTestContext context = GetContext();

            //should work since ValidationRules.CheckRules() is called in DataPortal_Create
            Csla.ApplicationContext.GlobalContext.Clear();
            HasRulesManager2.NewHasRulesManager2((o, e) =>
            {
                HasRulesManager2 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.AreEqual("Name required", root.BrokenRulesCollection.GetFirstMessage(HasRulesManager2.NameProperty).Description);
                context.Assert.AreEqual("Name required", root.BrokenRulesCollection.GetFirstBrokenRule(HasRulesManager2.NameProperty).Description);
                context.Assert.Success();
            });

            context.Complete();
        }