Esempio n. 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);
        }
Esempio n. 2
0
        public void TestSetWithStringNoBroadcast()
        {
            Messenger.Reset();

            var       vm                         = new ViewModelStub();
            const int expectedValue              = 1234;
            var       receivedValueChanged       = 0;
            var       receivedValueChanging      = 0;
            var       receivedValueWithMessenger = 0;

            Messenger.Default.Register <PropertyChangedMessage <int> >(this, msg => receivedValueWithMessenger = msg.NewValue);

            vm.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName)
                {
                    receivedValueChanged = vm.PropertyWithStringSetNoBroadcast;
                }
            };

            vm.PropertyChanging += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName)
                {
                    receivedValueChanging = vm.PropertyWithStringSetNoBroadcast;
                }
            };

            vm.PropertyWithStringSetNoBroadcast = expectedValue;
            Assert.AreEqual(expectedValue, receivedValueChanged);
            Assert.AreEqual(-1, receivedValueChanging);
            Assert.AreEqual(0, receivedValueWithMessenger);
        }
Esempio n. 3
0
        public void TestReturnValueWithStringSetNoBroadcast()
        {
            var       vm                   = new ViewModelStub();
            const int firstValue           = 1234;
            var       receivedValueChanged = 0;

#if !PORTABLE && !SL4
            var receivedValueChanging = 0;
#endif

            vm.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName)
                {
                    receivedValueChanged = vm.PropertyWithStringSetNoBroadcast;
                }
            };

#if !PORTABLE && !SL4
            vm.PropertyChanging += (s, e) =>
            {
                if (e.PropertyName == ViewModelStub.PropertyWithStringSetNoBroadcastPropertyName)
                {
                    receivedValueChanging = vm.PropertyWithStringSetNoBroadcast;
                }
            };
#endif

            vm.PropertyWithStringSetNoBroadcast = firstValue;
#if !PORTABLE && !SL4
            Assert.AreEqual(-1, receivedValueChanging);
#endif
            Assert.AreEqual(firstValue, receivedValueChanged);
            Assert.IsTrue(vm.SetRaisedPropertyChangedEvent);

            vm.PropertyWithStringSetNoBroadcast = firstValue;
#if !PORTABLE && !SL4
            Assert.AreEqual(-1, receivedValueChanging);
#endif
            Assert.AreEqual(firstValue, receivedValueChanged);
            Assert.IsFalse(vm.SetRaisedPropertyChangedEvent);

            vm.PropertyWithStringSetNoBroadcast = firstValue + 1;
#if !PORTABLE && !SL4
            Assert.AreEqual(firstValue, receivedValueChanging);
#endif
            Assert.AreEqual(firstValue + 1, receivedValueChanged);
            Assert.IsTrue(vm.SetRaisedPropertyChangedEvent);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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;
                }
            };

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

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

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

            Assert.IsTrue(receivedPropertyChanging);
            Assert.IsFalse(invalidPropertyChangingNameReceived);

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

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

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

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