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