I have a AsyncDelegateCommand
which takes the parameter of Window
, I tried mocking the class but I end with an exception The calling thread must be STA, because many UI components require this.
The DeletegateCommand:
private AsyncDelegateCommand<Window> okCommand;
public AsyncDelegateCommand<Window> OkCommand => this.okCommand ?? (this.okCommand = new AsyncDelegateCommand<Window>(this.OkAsync));
The Method implementaion:
private async Task OkAsync(Window win)
{
//Logic
}
The way I'm mocking it currently is using :
private Mock<Window> mockWindow;
this.mockWindow = new Mock<Window>();
await this.sut.OkCommand.ExecuteAsync(this.mockWindow.Object);
While debugging the object I can see the object value as an exception this.mock Window.Object' threw an exception of type 'System.Reflection.TargetInvocationException
If it's not possible is there an alternative on how to achieve this?