如何对 DelegateCommand 进行单元测试

发布于 2024-09-01 18:42:47 字数 177 浏览 1 评论 0原文

我正在尝试对我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不气馁 2024-09-08 18:42:47

回答了我自己的问题。我只需要在导致可执行更改的属性中 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文