I recently upgraded my ReactiveUI self-packing packages from the latest versions to version (v5.99.4-beta). Some time has passed since I did the update, but many of my tests in ViewModel failed.
The debugger seemed to indicate that my regular Rx sequences were not signed. For instance:
_executeSearch = ReactiveCommand.Create(); var paper = _executeSearch .Where(x => x is string) .SelectMany(x => _searchParser.GetPaperFinders(x as string)) .SelectMany(x => x.FindPaper()); paper .Select(x => x.Item1.Title) .ToProperty(this, x => x.Title, out _TitleOAPH, "");
And my test code looked something like this (short for short):
INavService obj = Mock... ISearchStringParser parser = ... var vm = new AddCDSPaperViewModel(obj, parser); vm.CDSLookupString = "1234"; // trigger the "search" ... (test scheduler is advanced to wait for search results to show up Assert.AreEqual("title", vm.Title, "searched for title"); // vm.Title is unset, though it should be!
I looked at the reactiveui source code on github and found the following for the value property for the ObservableAsPropertyHelper object:
public T Value { get { _inner = _inner ?? _source.Connect(); return _lastValue; } }
The key line has "_source.Connect ()" - in short, the sequence is not signed until someone reaches the value. In my tests, if I put "vm.Title" before running any rx sequences, everything works fine.
This is an amazing behavior (at least for me), in the sense that the ObservableAsPropertyHelper.Value property must be available before it captures any values. Is this expected behavior? Was this done for efficiency (e.g. lazy instance)? If so, what is the correct way to do this in tests?
Or am I really mistaken in how this works ?:-)