1
的命令:Click.Command={Binding OkCommand}
在我的视图(PopupView.xaml
)使用Moq,如何检测按钮点击是否触发了我的viewmodel中的事件?
<Button
Name="OKButton"
Content="{Binding Path=foo.foo, Source={StaticResource LocalResourceWrapper}}"
ToolTipService.ToolTip="{Binding Path=foo.foo, Source={StaticResource LocalResourceWrapper}}"
HorizontalAlignment="Center"
commands:Click.Command="{Binding OkCommand}"
Margin="5,10,5,10"
Click="OK_Click"
TabIndex="1" />
打完在我的视图模型下面的命令:(PopupViewModel.cs)
private ICommand _okCommand;
public ICommand OkCommand
{
get
{
if (_okCommand == null)
{
_okCommand = new DelegateCommand<object>(OnOKCommand);
}
return _okCommand;
}
}
public void OnOKCommand(object someObject)
{
this.ReturnSelectionListsCommand.Execute(this.GetAuditOrderByItemList());
}
public DelegateCommand<List<AuditOrderByItem>> ReturnSelectionListsCommand { get; set; }
基本上我想检测出OKCommand的确当按下按钮时调用。所以,我需要手动调用OKButton的点击事件,并最终检测到ReturnSelectionListsCommand.Execute()
和GetAuditOrderByItemList()
每次都被调用一次以保证我的弹出窗口正常工作。从我的研究中,我发现可以使用ButtonAutomation对等点来触发点击,但在我的测试中,如果使用MVVM,我看不到如何访问OKButton。
在我的单元测试,我试图按照这种线使用的东西:
var mock = new Mock<PopupViewModel>();
至少检测时,方法调用的视图模型。