public void GenericRelayCommandNotObservingPropertiesShouldNotRaiseOnEmptyPropertyName() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); var command = new RelayCommand <object>(o => { }); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; commandTestObject.RaisePropertyChanged(null); Assert.False(canExecuteChangedRaised); }
public void GenericAsyncRelayCommandNotObservingPropertiesShouldNotRaiseOnEmptyPropertyName() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); var command = new global::Anori.WinUI.Commands.AsyncRelayCommand <object>(async o => await Task.Yield()); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; commandTestObject.RaisePropertyChanged(null); Assert.False(canExecuteChangedRaised); }
public void GenericObservableCommandOfObjectObservingPropertyShouldRaiseOnNullPropertyName() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); var observer = new PropertyObserverFactory().ObservesProperty(commandTestObject.IntPropertyExpression); var command = new ActivatableCanExecuteObserverCommand <object>(o => { }, observer).Activate(); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; commandTestObject.RaisePropertyChanged(null); Assert.True(canExecuteChangedRaised); }
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); }); }
public void GenericDelegateCommandOfObjectShouldObserveOneProperty() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); var command = new ActivatablePropertyObserverCommand <object>(o => { }).ObservesProperty(commandTestObject.IntPropertyExpression); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; commandTestObject.IntProperty = 10; Assert.True(canExecuteChangedRaised); }
public void GenericDelegateCommandOfNullableIntWithNullableParameterShouldObserveCanExecute() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); ICommand command = new ActivatablePropertyObserverCommand <int?>(o => { }).ObservesCanExecute(commandTestObject.BoolPropertyExpression); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; Assert.False(canExecuteChangedRaised); Assert.False(command.CanExecute(null)); commandTestObject.BoolProperty = true; Assert.True(canExecuteChangedRaised); Assert.True(command.CanExecute(null)); }
public void GenericDelegateCommandOfObjectShouldObserveWithOwnerCanExecute() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); ICommand command = new ActivatablePropertyObserverCommand <object>(o1 => { }).ObservesCanExecute(commandTestObject, o2 => o2.BoolProperty); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; Assert.False(canExecuteChangedRaised); Assert.False(command.CanExecute(null)); commandTestObject.BoolProperty = true; Assert.True(canExecuteChangedRaised); Assert.True(command.CanExecute(null)); }
public void GenericObservableCommandOfObjectShouldObserveWithOwnerCanExecute() { var canExecuteChangedRaised = false; var commandTestObject = new CommandTestObject(); var factory = new PropertyObserverFactory(); var canExecuteObserver = factory.ObservesCanExecute(commandTestObject, o => o.BoolProperty); ICommand command = new ActivatableCanExecuteObserverCommand <object>(o => { }, canExecuteObserver).Activate(); command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; }; Assert.False(canExecuteChangedRaised); Assert.False(command.CanExecute(null)); commandTestObject.BoolProperty = true; Assert.True(canExecuteChangedRaised); Assert.True(command.CanExecute(null)); }
public void GenericDelegateCommandOfObjectShouldObserveComplexPropertyWhenParentPropertyIsNull() { var canExecuteChangedRaise = false; var commandTestObject = new CommandTestObject { ComplexProperty = new ComplexType() }; var command = new ActivatablePropertyObserverCommand <object>(o => { }).ObservesProperty( commandTestObject.ComplexPropertyInnerComplexPropertyIntPropertyExpression); command.CanExecuteChanged += delegate { canExecuteChangedRaise = true; }; var newComplexObject = new ComplexType { InnerComplexProperty = new ComplexType { IntProperty = 10 } }; commandTestObject.ComplexProperty.InnerComplexProperty = newComplexObject; Assert.True(canExecuteChangedRaise); }
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); }
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); }
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()); }
public void GenericDelegateCommandOfObjectPropertyObserverUnsubscribeUnusedListeners() { var canExecuteChangedRaiseCount = 0; var commandTestObject = new CommandTestObject { ComplexProperty = new ComplexType { IntProperty = 1, InnerComplexProperty = new ComplexType { IntProperty = 1, InnerComplexProperty = new ComplexType { IntProperty = 1 } } } }; var command = new ActivatablePropertyObserverCommand <object>(o => { }) .ObservesProperty(commandTestObject.ComplexPropertyIntPropertyExpression) .ObservesProperty( commandTestObject.ComplexPropertyInnerComplexPropertyInnerComplexPropertyIntPropertyExpression) .ObservesProperty(commandTestObject.ComplexPropertyInnerComplexPropertyIntPropertyExpression); 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()); }