I'm developing an application in WPF, with MVVMLight framework.
I'm trying to make unit tests (i'm novice in that). So I try to simulate my view by subscribing to the CanExecuteChanged event on my command and verify that it is correctly called. But when I do that it is never called, even if I call the RaiseCanExecuteChanged method.
Here is a very simple sample:
bool testCanExec = false;
var testCmd = new RelayCommand(
execute: () => { System.Diagnostics.Debug.WriteLine($"Execute call"); },
canExecute: () => { System.Diagnostics.Debug.WriteLine($"CanExecute call"); return testCanExec; }
);
testCmd.CanExecuteChanged += ((sender, args) => { System.Diagnostics.Debug.WriteLine($"CanExecuteChanged call"); });
testCanExec = true;
testCmd.RaiseCanExecuteChanged(); // <= nothing in output
testCmd.Execute(null); // <= output: "CanExecute call", "Execute call"
What I really can't understand is that it seems to work with my button. I don't know how but it enables and disables properly.
Thank's for your help.