【发布时间】:2017-12-18 13:30:59
【问题描述】:
我正在使用导航服务在 ViewModel 之间执行导航,现在我必须为我的 ViewModel 创建一些单元测试。我可以使用 Moq 模拟创建注入对象的 ViewModel,但我正在努力模拟 NavigationService,然后创建断言,而不是导航到下一个 ViewModel。
我找到了几年前的一些文档,所以导航服务不存在,我在 MvvmCross 官方文档中找不到任何关于这个问题的信息,所以现在我陷入了死胡同。
我正在使用 MvvmCross 5.5.0。
[Test]
public void CheckStatus()
{
Mock<IStatusService> _mockStatusService = new Mock<IStatusService>();
_mockStatusService.Setup(x => x.Check(It.IsAny<StatusRequest>())).Returns(() => new StatusRequest { Ok = true });
//Here I need to pass the NavigationService to the constructor
var _viewModel = new StatusViewModel(_mockStatusService.Object, navigationService);
_viewModel.Start();
//Here I guess I should perform the navigation assertion.
}
【问题讨论】: