如何对 DelegateCommand 进行单元测试
我正在尝试对我的 ViewModel 和 SaveItem(save, CanSave) 委托命令进行单元测试。我想确保在特定条件下调用 CanSave 并返回正确的值。基本上,我如何从单元测试中调用委托命令,实际上它更多的是集成测试。显然我可以只测试 CanSave 方法的返回值,但我正在尝试严格使用 BDD,即。没有先测试就没有代码。
I am trying to unit test my ViewModel and my SaveItem(save, CanSave) delegate command. I want to ensure that CanSave is called and returns the correct value given certain conditions. Basically, how can I invoke the delegate command from my unit test, actually it's more of an integration test. Obviously I could just test the return value of the CanSave method but I am trying to use BDD to the letter, ie. no code without a test first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了我自己的问题。我只需要在导致可执行更改的属性中 RaiseCanExecuteChanged() (显然),然后断言发生了所需的结果,即当 CanExecute 返回 false 时我的对象没有保存。
Answered my own question. I just needed to RaiseCanExecuteChanged() in the properties that cause can execute to change (obviously), and then assert that the required outcome occurred ie that my object was not saved when CanExecute returned false.