I have an application that I am building unit tests for. For certain operations, I use ApplicationCommands
(eg. ApplicationCommands.New
). Is there an easy way to call CanExecute
and Execute
on a routed UI command in the unit test? I thought about implementing a mock IInputElement
, but that seems like a lot of work. Is there a better way?
[TestMethod]
public void NewDocument()
{
Assert.IsTrue(ApplicationCommands.New.CanExecute(null, mockTarget));
ApplicationCommands.New.Execute(null, mockTarget);
Assert.IsTrue(workspace.OpenDocuments.Count == 1);
}
It looks like this is very similar to this question why-does-my-command-canexecute-always-return-false-in-unit-test? Does anyone know of a way to execute the routed ui command without the ui actually being there?
I have the command and command binding, but I don't know how to create the command source and command target.