ReactiveUI 6.5 ReactiveList.ItemChanged not firing on UnitTest

I have a ReactiveList with View Models with a "Selected" property. When I try to set this property from a unit test, the Subscription to ReactiveList.ItemChanged is not called. It does work, however, when the application is started and the "Selected" property is run from a checkbox in the user interface. Is there something magic I have to do to make ReactiveList.ItemChanged work in a unit testing environment? By the way, I am using ReactiveUI 6.5.

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);
    });
}

      

+3


source to share





All Articles