0

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.


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.

public void DoItemsChanged(IList param)

Before I had

public void DoItemsChanged(object param)

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.

4

1 回答 1

0

我认为我已经回答了我自己的问题。

在较早的点投射从视图传回的对象意味着我传递给被测方法的对象更容易创建。

这就是我现在所测试的方法所拥有的。

public void DoItemsChanged(IList param)

在我有之前

public void DoItemsChanged(object param)

其中参数是 SelectedItemCollection(以前是 RoutedEventArgs,但现在我在视图中的事件触发器上使用 IvokeCommandAction,传递 SelectedItems)。参数现在更容易传递到测试方法中,并且代码也更具描述性。所以这对每个人都有好处。

于 2011-06-30T08:37:25.333 回答