DelegateCommand<对象>使用 EventArg 参数 mstest 进行测试对象>
我目前有一个事件触发器触发自定义触发器操作。
该操作将 EventArgs 类型的对象传回视图的视图模型。
当我运行代码时,一切都很好,它工作得很好。然而,当我测试这部分代码时,一切都变得有点垃圾。
如前所述,我们正在使用 MVVM 类型模式,因此我正在视图模型中测试事件触发器的“执行”结束,我想要做的是创建一个“模拟”EventArgs 对象以传递到我的正在测试的命令。然而,它需要一个 RoutedEvent,因为它的 ID 属性如上所述,而且我无权访问它的构造函数!
Cannot Access Internal Constructor for 'RoutedEvent' here.
有人有什么想法吗?测试中的代码收敛比当前的实现更重要,因此如果这被认为是“不可测试的”,那么我可以进行更改。
I currently have an event trigger firing a custom trigger action.
The action passes back a EventArgs type of object to the view's view-model.
This is all well and good when I run the code it works perfectly. However, when I come to test this portion of code it all goes a bit rubbish.
As stated We are using an MVVM type pattern so I'm testing the 'Doing' end of the event trigger in my view-model and what I want to do is create a 'mocked' EventArgs object to pass into the execute method of my command under test. However it requires a RoutedEvent as it's ID property as stated above and I don't have access to it's constructor!
Cannot Access Internal Constructor for 'RoutedEvent' here.
Has anyone got any ideas? The code converage in test is more important than the current implimentation so if this is thought to be 'untestable', then I can make changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经回答了我自己的问题。
转换先前从视图传回的对象意味着我传递给测试方法的对象更容易创建。
这就是我现在所测试的方法。
在我之前,
其中参数是 SelectedItemCollection (以前是 RoutedEventArgs,但现在我在视图中的事件触发器上使用 IvokeCommandAction,传递 SelectedItems)。现在,参数可以更轻松地传递到测试方法中,并且代码也更具描述性。所以这对每个人来说都是好事。
I have answered my own Question I think.
Casting the object passed back from the view at an earlier point means that the object I am passing to the methods under test is more easily created.
This is what I have now for the method under test.
Before I had
Where the param is a SelectedItemCollection (previously a RoutedEventArgs, but now I use the IvokeCommandAction on the event trigger in the view, passign the SelectedItems). The param is now more easily passed into the method for the test and the code it much more descriptive as well. So it's all good for everyone.