示例#1
0
        public void TestRaiseValidInvalidPropertyName()
        {
            var vm = new ViewModelStub();

            var receivedPropertyChanged     = false;
            var invalidPropertyNameReceived = false;

            vm.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.RealPropertyPropertyName)
                {
                    receivedPropertyChanged = true;
                }
                else
                {
                    invalidPropertyNameReceived = true;
                }
            };

            vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName);

            Assert.IsTrue(receivedPropertyChanged);
            Assert.IsFalse(invalidPropertyNameReceived);

            vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName + "1");

            Assert.IsTrue(invalidPropertyNameReceived);
        }
示例#2
0
        public void TestRaiseValidInvalidPropertyName()
        {
            var vm = new ViewModelStub();

            var receivedPropertyChanged = false;
            var invalidPropertyChangedNameReceived = false;
            var receivedPropertyChanging = false;
            var invalidPropertyChangingNameReceived = false;
            vm.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.RealPropertyPropertyName)
                {
                    receivedPropertyChanged = true;
                }
                else
                {
                    invalidPropertyChangedNameReceived = true;
                }
            };

#if !WP71
            vm.PropertyChanging += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.RealPropertyPropertyName)
                {
                    receivedPropertyChanging = true;
                }
                else
                {
                    invalidPropertyChangingNameReceived = true;
                }
            };

            vm.RaisePropertyChanging(ViewModelStub.RealPropertyPropertyName);
#endif
            vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName);

            Assert.IsTrue(receivedPropertyChanged);
            Assert.IsFalse(invalidPropertyChangedNameReceived);

#if !WP71
            Assert.IsTrue(receivedPropertyChanging);
            Assert.IsFalse(invalidPropertyChangingNameReceived);
#endif

            try
            {
#if !WP71
                vm.RaisePropertyChanging(ViewModelStub.RealPropertyPropertyName + "1");
#endif

#if DEBUG
                Assert.Fail("ArgumentException was expected");
#else
#if !WP71
                Assert.IsTrue(invalidPropertyChangingNameReceived);
#endif
#endif
            }
            catch (ArgumentException)
            {
            }

            try
            {
                vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName + "1");

#if DEBUG
                Assert.Fail("ArgumentException was expected");
#else
                Assert.IsTrue(invalidPropertyChangedNameReceived);
#endif
            }
            catch (ArgumentException)
            {
            }
        }
        public void TestRaiseValidInvalidPropertyName()
        {
            var vm = new ViewModelStub();

            var receivedPropertyChanged = false;
            var invalidPropertyNameReceived = false;
            vm.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.RealPropertyPropertyName)
                {
                    receivedPropertyChanged = true;
                }
                else
                {
                    invalidPropertyNameReceived = true;
                }
            };

            vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName);

            Assert.IsTrue(receivedPropertyChanged);
            Assert.IsFalse(invalidPropertyNameReceived);

            vm.RaisePropertyChanged(ViewModelStub.RealPropertyPropertyName + "1");

            Assert.IsTrue(invalidPropertyNameReceived);
        }