Esempio n. 1
0
        public void GenericObservableCommandOfObjectShouldNotObserveDuplicateProperties()
        {
            var commandTestObject = new CommandTestObject();
            var factory           = new PropertyObserverFactory();
            var observer1         = factory.ObservesProperty(commandTestObject.IntPropertyExpression);
            var observer2         = factory.ObservesProperty(commandTestObject.IntPropertyExpression);

            Assert.Throws <ArgumentException>(
                () =>
            {
                var command = new ActivatableCanExecuteObserverCommand <object>(o => { }, observer1, observer2);
            });
        }
Esempio n. 2
0
        public void GenericObservableCommandOfObjectShouldObserveCanExecuteAndObserveOtherProperties()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();
            var factory            = new PropertyObserverFactory();
            var canExecuteObserver = factory.ObservesCanExecute(commandTestObject, o => o.BoolProperty);
            var observer1          = factory.ObservesProperty(commandTestObject, o => o.IntProperty);

            ICommand command =
                new ActivatableCanExecuteObserverCommand <object>(o => { }, canExecuteObserver, observer1).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.False(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            commandTestObject.IntProperty = 10;

            Assert.True(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            canExecuteChangedRaised = false;
            Assert.False(canExecuteChangedRaised);

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }
Esempio n. 3
0
        public void GenericObservableCommandOfObjectShouldObserveMultipleProperties()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();
            var factory   = new PropertyObserverFactory();
            var observer1 = factory.ObservesProperty(commandTestObject.IntPropertyExpression);
            var observer2 = factory.ObservesProperty(commandTestObject.BoolPropertyExpression);

            var command = new ActivatableCanExecuteObserverCommand <object>(o => { }, observer1, observer2).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            commandTestObject.IntProperty = 10;

            Assert.True(canExecuteChangedRaised);

            canExecuteChangedRaised = false;

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
        }
Esempio n. 4
0
        public void GenericObservableCommandOfObjectShouldObserveComplexPropertyWhenRootPropertyIsNull()
        {
            var canExecuteChangedRaise = false;
            var commandTestObject      = new CommandTestObject {
                ComplexProperty = null
            };
            var factory   = new PropertyObserverFactory();
            var observer1 = factory.ObservesProperty(
                commandTestObject.ComplexPropertyInnerComplexPropertyIntPropertyExpression);

            var command = new ActivatableCanExecuteObserverCommand <object>(o => { }, observer1).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaise = true; };

            var newComplexObject = new ComplexType {
                InnerComplexProperty = new ComplexType {
                    IntProperty = 10
                }
            };

            commandTestObject.ComplexProperty = newComplexObject;

            Assert.True(canExecuteChangedRaise);
        }
Esempio n. 5
0
        public void GenericObservableCommandOfObjectPropertyObserverWithOwnerUnsubscribeUnusedListeners()
        {
            var canExecuteChangedRaiseCount = 0;
            var commandTestObject           = new CommandTestObject
            {
                ComplexProperty = new ComplexType
                {
                    IntProperty          = 1,
                    InnerComplexProperty = new ComplexType
                    {
                        IntProperty          = 1,
                        InnerComplexProperty =
                            new ComplexType
                        {
                            IntProperty = 1
                        }
                    }
                }
            };

            var factory   = new PropertyObserverFactory();
            var observer1 = factory.ObservesProperty(commandTestObject, o => o.ComplexProperty.IntProperty);
            var observer2 = factory.ObservesProperty(
                commandTestObject,
                o => o.ComplexProperty.InnerComplexProperty.IntProperty);
            var observer3 = factory.ObservesProperty(
                commandTestObject,
                o => o.ComplexProperty.InnerComplexProperty.InnerComplexProperty.IntProperty);
            var command = new ActivatableCanExecuteObserverCommand <object>(o => { }, observer1, observer2, observer3).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaiseCount++; };

            commandTestObject.ComplexProperty.IntProperty = 2;
            commandTestObject.ComplexProperty.InnerComplexProperty.InnerComplexProperty.IntProperty = 2;
            commandTestObject.ComplexProperty.InnerComplexProperty.IntProperty = 2;

            Assert.AreEqual(3, canExecuteChangedRaiseCount);

            var innerInnerComplexProp = commandTestObject.ComplexProperty.InnerComplexProperty.InnerComplexProperty;
            var innerComplexProp      = commandTestObject.ComplexProperty.InnerComplexProperty;
            var complexProp           = commandTestObject.ComplexProperty;

            commandTestObject.ComplexProperty = new ComplexType
            {
                InnerComplexProperty = new ComplexType
                {
                    InnerComplexProperty =
                        new ComplexType()
                }
            };

            Assert.AreEqual(0, innerInnerComplexProp.GetPropertyChangedSubscribedLength());
            Assert.AreEqual(0, innerComplexProp.GetPropertyChangedSubscribedLength());
            Assert.AreEqual(0, complexProp.GetPropertyChangedSubscribedLength());

            innerInnerComplexProp = commandTestObject.ComplexProperty.InnerComplexProperty.InnerComplexProperty;
            innerComplexProp      = commandTestObject.ComplexProperty.InnerComplexProperty;
            complexProp           = commandTestObject.ComplexProperty;

            commandTestObject.ComplexProperty = null;

            Assert.AreEqual(0, innerInnerComplexProp.GetPropertyChangedSubscribedLength());
            Assert.AreEqual(0, innerComplexProp.GetPropertyChangedSubscribedLength());
            Assert.AreEqual(0, complexProp.GetPropertyChangedSubscribedLength());
        }