3

I have a ReactiveList with view models with a 'Selected' property. When I try to set this property from a unit-test, the subscription on ReactiveList.ItemChanged is not invoked. It works, however, when running the application and triggering the 'Selected' property from a check-box in the UI. Is there anything magic I have to do to make ReactiveList.ItemChanged work in a unit-test environment? I am using ReactiveUI 6.5 by the way.

WellsViewModels = new ReactiveList<WellViewModel> { ChangeTrackingEnabled = true };

var selectedWellsObservable =
    Observable.Merge(
        this.WhenAnyValue(vm => vm.WellSamplesFunc)
            .Select(_ => Enumerable.Empty<IPropertyModelingWell>()),
        WellsViewModels
            .ItemChanged
            .Where(x => x.PropertyName == nameof(WellViewModel.Selected))
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Select(_ => WellsViewModels.Where(vm => vm.Selected)
                                        .Select(vm => vm.Well).ToList())
    )
    .Publish()
    .RefCount();

selectedWellsObservable
    .Select(_ => ComputeAllCheckedState(WellsViewModels))
    .Subscribe(b => CheckAllWells = b) // <--- This is never invoked when unit-testing!?!

[Test]
public void CheckAllWells_UpdatedWhenWellsViewModelsSelectionChanges()
{
    new TestScheduler().With(scheduler =>
    {
        // Arrange
        ...
        ...

        // Act
        _viewModel.WellsViewModels[0].Selected = true;
        scheduler.AdvanceBy(TimeSpan.FromMilliseconds(200).Ticks);

        // Assert
        Assert.IsFalse(_viewModel.CheckAllWells.HasValue);
    });
}
atlemann
  • 173
  • 1
  • 7
  • Did you set ChangeTrackingEnabled to true? https://docs.reactiveui.net/en/user-guide/lists/#using-change-tracking – ds-b May 29 '17 at 12:59
  • @ds-b Yes I have. Everything works when running the WPF application, but when unit-testing it is not triggering. – atlemann May 31 '17 at 06:39

0 Answers0