-1

How to write Unit Test case for RelayCommand when there is a parameter in Execute method.Person is model class in MVVM application.

Something like this:

DeleteThanksCommand = 
    new RelayCommand<Person>(param => DeleteThanks(param), CanDeleteThanks());

When I tried to write unit Test case like:

ViewModel.DeleteThanksCommand.Execute(null);

Got error at runtime that cannot convert from string to Person.

Please suggest how to write unit test case for this Relay Command.

Thanks in advance for your help.

Ashwin
  • 15
  • 5
  • Thanks for editing the question. – Ashwin Oct 29 '19 at 15:36
  • **why it has upvotes?** there is no information to answer this question ... what is `RelayCommand` (it's not a part framework) ... there is no info on what is `DeleteThanks` nor `CanDeleteThanks` **it seems like Ashwin is using sockpuppet account to upvotes his question** – Selvin Oct 29 '19 at 15:43
  • RelayCommand is a part of WPF which comes under .Net framework. DeleteThanksCommand is a RelayCommand which is binded to the View of class. It's MVVM pattern. – Ashwin Oct 29 '19 at 15:47
  • *RelayCommand is a part of WPF which comes under .Net framework.* [No, it is not](https://learn.microsoft.com/en-us/search/?search=RelayCommand&scope=.NET) ... You need to post [a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Selvin Oct 29 '19 at 15:49
  • https://www.c-sharpcorner.com/UploadFile/20c06b/icommand-and-relaycommand-in-wpf/ This information is sufficient for guy having experience in WPF. – Ashwin Oct 29 '19 at 15:52
  • What happens if you pass empty object of person like new Pearson() or you type cart to null person explicitly like (Person)null? – user1672994 Oct 29 '19 at 16:02
  • Thanks,Will try that for sure. – Ashwin Oct 29 '19 at 16:03

1 Answers1

0

ViewModel.DeleteThanksCommand.Execute(""); This will work and with help of Assert we can validate O/P with respect to I/P

Ashwin
  • 15
  • 5