C# 故障单元测试反应命令CanExecute
我在测试一个反应命令时遇到了很多麻烦。我遵循这里描述的描述。应用程序工作正常-根据列表内容启用或禁用按钮 我的单元测试没有按预期工作。我有一份报告如下:C# 故障单元测试反应命令CanExecute,c#,reactiveui,C#,Reactiveui,我在测试一个反应命令时遇到了很多麻烦。我遵循这里描述的描述。应用程序工作正常-根据列表内容启用或禁用按钮 我的单元测试没有按预期工作。我有一份报告如下: public void myTest() { var vm = new MyViewModel(); Assert.IsTrue(vm.Ok.CanExecute(null)) //Do something that will invalidate the button Assert.IsFalse(vm.Ok
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;
}
我是个白痴
RxApp.MainThreadScheduler = Scheduler.CurrentThread;
过了一会儿,一切看起来都一样了