【发布时间】:2014-11-20 13:36:11
【问题描述】:
我在对 ReactiveCommand 进行单元测试时遇到了麻烦。我按照这里描述的描述 ReactiveCommand CanExecute reacting to changes in a collection 。该应用程序运行良好 - 根据列表的内容启用或禁用按钮。
我的单元测试没有按预期工作。我有一个如下:
public void myTest()
{
var vm = new MyViewModel();
Assert.IsTrue(vm.Ok.CanExecute(null))
//Do something that will invalidate the button
Assert.IsFalse(vm.Ok.CanExecute(null))
}
此测试将立即失败。但是,如果我订阅 CanExecuteObservable,测试会按预期运行:
public void myTest()
{
var vm = new MyViewModel();
vm.Ok.CanExecuteObservable.Subscribe(x => {});
Assert.IsTrue(vm.Ok.CanExecute(null))
//Do something that will invalidate the button
Assert.IsFalse(vm.Ok.CanExecute(null))
}
这是预期的行为吗?我正在使用 ReactiveUI 6.2。
此外,我的单元测试显示很多“当前线程没有与之关联的调度程序”,尽管我的设置中有以下内容:
[TestInitialize]
public void Init()
{
//This line throws ...
RxApp.TaskpoolScheduler = Scheduler.CurrentThread;
}
【问题讨论】:
标签: c# reactiveui