public void SuspendsChangeNotificationsAndRaisesPropertiesOnResumeWithScopes()
            {
                var model = new SuspendableTestModel();

                // First change without change notifications so IsDirty = true
                model.FirstName = "1";

                var changedProperties = new List<string>();

                model.PropertyChanged += (sender, e) =>
                {
                    changedProperties.Add(e.PropertyName);
                };

                using (model.SuspendChangeNotifications())
                {
                    using (model.SuspendChangeNotifications())
                    {
                        model.FirstName = "A";
                        model.LastName = "B";

                        Assert.AreEqual(0, changedProperties.Count);
                    }

                    // We still haven't released all scopes
                    Assert.AreEqual(0, changedProperties.Count);
                }

                Assert.AreEqual(2, changedProperties.Count);

                Assert.AreEqual("FirstName", changedProperties[0]);
                Assert.AreEqual("LastName", changedProperties[1]);
            }
Пример #2
0
            public void SuspendsChangeNotificationsAndRaisesPropertiesOnResumeWithScopes()
            {
                var model = new SuspendableTestModel();

                using (model.SuspendValidations())
                {
                    using (model.SuspendValidations())
                    {
                        model.Validate(true, true);

                        var innerValidationContext1 = model.GetValidationContext();

                        Assert.IsFalse(innerValidationContext1.HasErrors);
                    }

                    model.Validate(true, true);

                    var innerValidationContext2 = model.GetValidationContext();

                    Assert.IsFalse(innerValidationContext2.HasErrors);
                }

                //model.Validate(true, true);

                var validationContext = model.GetValidationContext();
                var errors            = validationContext.GetErrors();

                Assert.IsTrue(validationContext.HasErrors);
                Assert.AreEqual("FirstName", ((FieldValidationResult)errors[0]).PropertyName);
                Assert.AreEqual("LastName", ((FieldValidationResult)errors[1]).PropertyName);
            }
            public void SuspendsChangeNotificationsAndRaisesPropertiesOnResumeWithScopes()
            {
                var model = new SuspendableTestModel();

                // First change without change notifications so IsDirty = true
                model.FirstName = "1";

                var changedProperties = new List <string>();

                model.PropertyChanged += (sender, e) =>
                {
                    changedProperties.Add(e.PropertyName);
                };

                using (model.SuspendChangeNotifications())
                {
                    using (model.SuspendChangeNotifications())
                    {
                        model.FirstName = "A";
                        model.LastName  = "B";

                        Assert.AreEqual(0, changedProperties.Count);
                    }

                    // We still haven't released all scopes
                    Assert.AreEqual(0, changedProperties.Count);
                }

                Assert.AreEqual(2, changedProperties.Count);

                Assert.AreEqual("FirstName", changedProperties[0]);
                Assert.AreEqual("LastName", changedProperties[1]);
            }
            public void SuspendsCallbacksWithScopes()
            {
                var model = new SuspendableTestModel();

                using (model.SuspendChangeCallbacks())
                {
                    using (model.SuspendChangeCallbacks())
                    {
                        model.FirstName = "A";
                        model.LastName  = "B";

                        Assert.IsFalse(model.IsFirstNameCallbackInvoked);
                        Assert.IsFalse(model.IsLastNameCallbackInvoked);
                    }

                    model.FirstName = "A1";
                    model.LastName  = "B1";

                    Assert.IsFalse(model.IsFirstNameCallbackInvoked);
                    Assert.IsFalse(model.IsLastNameCallbackInvoked);
                }

                model.FirstName = "A2";
                model.LastName  = "B2";

                Assert.IsTrue(model.IsFirstNameCallbackInvoked);
                Assert.IsTrue(model.IsLastNameCallbackInvoked);
            }
            public void CorrectlyInvokesCallbacks()
            {
                var model = new SuspendableTestModel();

                model.FirstName = "A";
                model.LastName  = "B";

                Assert.IsTrue(model.IsFirstNameCallbackInvoked);
                Assert.IsTrue(model.IsLastNameCallbackInvoked);
            }
Пример #6
0
            public void CorrectlyValidates()
            {
                var model = new SuspendableTestModel();

                model.Validate(true, true);

                var validationContext = model.GetValidationContext();
                var errors            = validationContext.GetErrors();

                Assert.IsTrue(validationContext.HasErrors);
                Assert.AreEqual("FirstName", ((FieldValidationResult)errors[0]).PropertyName);
                Assert.AreEqual("LastName", ((FieldValidationResult)errors[1]).PropertyName);
            }
Пример #7
0
            public void SuspendsValidationsAndValidatesOnResume()
            {
                var model = new SuspendableTestModel();

                using (model.SuspendValidations())
                {
                    model.Validate(true, true);

                    var innerValidationContext = model.GetValidationContext();

                    Assert.IsFalse(innerValidationContext.HasErrors);
                }

                var validationContext = model.GetValidationContext();
                var errors            = validationContext.GetErrors();

                Assert.IsTrue(validationContext.HasErrors);
                Assert.AreEqual("FirstName", ((FieldValidationResult)errors[0]).PropertyName);
                Assert.AreEqual("LastName", ((FieldValidationResult)errors[1]).PropertyName);
            }
            public void CorrectlyRaisesChangeNotifications()
            {
                var model = new SuspendableTestModel();

                // First change without change notifications so IsDirty = true
                model.FirstName = "1";

                var changedProperties = new List<string>();

                model.PropertyChanged += (sender, e) =>
                {
                    changedProperties.Add(e.PropertyName);
                };

                model.FirstName = "A";
                model.LastName = "B";

                Assert.AreEqual(2, changedProperties.Count);

                Assert.AreEqual("FirstName", changedProperties[0]);
                Assert.AreEqual("LastName", changedProperties[1]);
            }
            public void CorrectlyRaisesChangeNotifications()
            {
                var model = new SuspendableTestModel();

                // First change without change notifications so IsDirty = true
                model.FirstName = "1";

                var changedProperties = new List <string>();

                model.PropertyChanged += (sender, e) =>
                {
                    changedProperties.Add(e.PropertyName);
                };

                model.FirstName = "A";
                model.LastName  = "B";

                Assert.AreEqual(2, changedProperties.Count);

                Assert.AreEqual("FirstName", changedProperties[0]);
                Assert.AreEqual("LastName", changedProperties[1]);
            }
            public void SuspendsCallbacksWithScopes()
            {
                var model = new SuspendableTestModel();

                using (model.SuspendChangeCallbacks())
                {
                    using (model.SuspendChangeCallbacks())
                    {
                        model.FirstName = "A";
                        model.LastName = "B";

                        Assert.IsFalse(model.IsFirstNameCallbackInvoked);
                        Assert.IsFalse(model.IsLastNameCallbackInvoked);
                    }

                    model.FirstName = "A1";
                    model.LastName = "B1";

                    Assert.IsFalse(model.IsFirstNameCallbackInvoked);
                    Assert.IsFalse(model.IsLastNameCallbackInvoked);
                }

                model.FirstName = "A2";
                model.LastName = "B2";

                Assert.IsTrue(model.IsFirstNameCallbackInvoked);
                Assert.IsTrue(model.IsLastNameCallbackInvoked);
            }
            public void CorrectlyInvokesCallbacks()
            {
                var model = new SuspendableTestModel();

                model.FirstName = "A";
                model.LastName = "B";

                Assert.IsTrue(model.IsFirstNameCallbackInvoked);
                Assert.IsTrue(model.IsLastNameCallbackInvoked);
            }