diff --git a/src/ObservableComputations.Test/ExpressionWatcherTests.cs b/src/ObservableComputations.Test/ExpressionWatcherTests.cs index bc2c94f..2cac920 100644 --- a/src/ObservableComputations.Test/ExpressionWatcherTests.cs +++ b/src/ObservableComputations.Test/ExpressionWatcherTests.cs @@ -53,7 +53,14 @@ public Item GetChild(string num) public void SetChild(string num, Item item) { _children[num] = item; - MethodChanged?.Invoke(this, new MethodChangedEventArgs(nameof(GetChild), args => args[0].Equals(num))); + Func predicate = args => args[0].Equals(num); + string methodName = nameof(GetChild); + RaiseMethodChanged(methodName, predicate); + } + + public void RaiseMethodChanged(string methodName, Func predicate) + { + MethodChanged?.Invoke(this, new MethodChangedEventArgs(methodName, predicate)); } public Item Child @@ -66,6 +73,7 @@ public Item Child } } + #region INotifyPropertyChanged imlementation public event PropertyChangedEventHandler PropertyChanged; @@ -88,6 +96,36 @@ protected bool updatePropertyValue(ref T field, T value, [CallerMemberName] s public event EventHandler MethodChanged; } + public class ItemWithConstantPropertyAndMethod : Item, ICanNotifyPropertyChanged, ICanNotifyMethodChanged + { + public int ConstantProperty => 1; + public int ConstantMethod() => 1; + + public void RaiseConstantsChanged() + { + onPropertyChanged(nameof(ConstantProperty)); + RaiseMethodChanged(nameof(ConstantMethod), objects => true); + } + + #region Implementation of ICanNotifyPropertyChanged + + public bool CanNotifyPropertyChanged(string propertyName, IComputing computing) + { + return propertyName != nameof(ConstantProperty); + } + + #endregion + + #region Implementation of ICanNotifyMethodChanged + + public bool CanNotifyMethodChanged(string methodName, int argumentsCount, IComputing computing) + { + return methodName != nameof(ConstantMethod); + } + + #endregion + } + [Test] public void TestRaiseValueChanged1() { @@ -381,6 +419,23 @@ public void TestRaiseValueChanged13() expressionWatcher.Dispose(); } + [Test] + public void TestItemWithConstantPropertyAndMethod() + { + int raised = 0; + ItemWithConstantPropertyAndMethod item = new ItemWithConstantPropertyAndMethod(); + Expression> expression = () => item.Num + item.ConstantMethod() + item.ConstantProperty; + ExpressionWatcher expressionWatcher = new ExpressionWatcher(null, + ExpressionWatcher.GetExpressionInfo(expression)); + expressionWatcher.ValueChanged = (ew, sender, eventArgs) => { raised++; }; + item.Num = item.Num + 1; + Assert.AreEqual(raised, 1); + raised = 0; + item.RaiseConstantsChanged(); + Assert.AreEqual(raised, 0); + expressionWatcher.Dispose(); + } + //[Test] //public void TestWeakEventHandler() //{