【问题标题】:Trouble unit testing ReactiveCommand CanExecute故障单元测试 ReactiveCommand CanExecute
【发布时间】: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


    【解决方案1】:

    我是个白痴……

    RxApp.MainThreadScheduler = Scheduler.CurrentThread;
    

    一段时间后一切都开始看起来一样......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2017-02-16
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多