示例#1
0
        public void SuppressNotificationsInside()
        {
            var counter = 0;
            var vm      = new TestVM();

            vm.PropertyChanged += (s, a) => counter++;

            // initial value
            vm.MyProperty = 0;
            counter       = 0;

            vm.SuppressNotificationsInside(() => vm.MyProperty, () =>
            {
                vm.MyProperty = 42;
                vm.MyProperty = 21;
                vm.MyProperty = 0;

                // last value is different than initial value, to PropertyChanged should call
                vm.MyProperty = 42;
            });

            Assert.AreEqual(42, vm.MyProperty);

            Assert.AreEqual(1, counter, "PropertyChanged was raised more or less than once.");
        }