vendredi 10 juillet 2015

How to test DelegateCommands that accept events in a mvvm windows application

I am developing a windows 10 universal application using mvvm prism. In my unit test project I want to test the commands of the viewmodels, but I cannot create fake events args.

For example I would like to create a test method that tests TxtSearchCommand which accepts a SearchBoxQueryChangedEventArgs object:

SearchBoxQueryChangedEventArgs  args =
         new SearchBoxQueryChangedEventArgs(){e.QueryText = "b"}
 this._clientsOverviewViewModel.TxtSearchCommand.Execute(args);

Of course that is not possible since the costructor of SearchBoxQueryChangedEventArgs is private.

I would also like to test a command that accepts an ItemClickEventArgs, in this case I can not set the ClickedItem property inside the ItemClickEventArgs.

So is there any way to test those commands?

Aucun commentaire:

Enregistrer un commentaire