public void CanUseCurrentValueWhenRecalculating() { var optionsViewModel = new OptionsViewModel { Options = new ObservableCollection<string> { "Item 1", "Item 2", "Item 3" }, SelectedOption = "Item 1" }; engine .Assign(() => optionsViewModel.SelectedOption) .From(currentValue => UnselectInvalidOption(currentValue, optionsViewModel.Options), ex => { }); // change a paramter of the formula, to check the formula triggers and use correct current value optionsViewModel.Options = new ObservableCollection<string> { "Item 1", "Item 2" }; optionsViewModel.SelectedOption.ShouldBe("Item 1"); // again, change a paramter of the formula, to check the formula triggers and use correct current value optionsViewModel.Options = new ObservableCollection<string> { "Item 2", "Item 3" }; optionsViewModel.SelectedOption.ShouldBe(null); }
public void ChangingTargetPropertyShouldNotTriggerExpressionEvaluation() { var optionsViewModel = new OptionsViewModel(); engine .Assign(() => optionsViewModel.SelectedOption) .From(() => CountHowManyTimesCalled(optionsViewModel.Options), ex => { }); string dotFormat = engine.ToDotFormat("Foo"); Console.WriteLine(dotFormat); // reset count to 0 (because of issue 1) count = 0; // change the target property optionsViewModel.SelectedOption = "Item2"; // check that the formula was not evaluated count.ShouldBe(0); // Note: this seems to be caused by DepdendencyEngine.FindChangedNode returning the wrong node. // this method is super confusing, spent some time on it and just can't understand the logic, I prefer to not touch it }