Skip to content

How to test SelectMany() calling an async method? #3643

Answered by anaisbetts
hymstra asked this question in Q&A
Discussion options

You must be logged in to vote

TestScheduler isn't compatible with async/await sadly - if you use TestScheduler, everything has to go through RxApp.MainThreadScheduler and RxApp.TaskPoolScheduler.

That being said, TestScheduler is more appropriate for testing elapsed time, but what you really care about here is ordering - "A" happened then "B", then "C" - we don't care about exactly how much time passes. The easiest way to do this is to start mocking methods that return Task<T> with AsyncSubject and IObservable<T>s with Subject:

public class ViewModel : ReactiveObject
{
    public ViewModel(Foo foo, Func<Foo, val, Task<Unit>> fooSetter = null)
    {
        // NB: There are lots of way better ways to replace methods to…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@hymstra
Comment options

@anaisbetts
Comment options

@hymstra
Comment options

@anaisbetts
Comment options

Answer selected by anaisbetts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants