When working with async you should always return a task. Otherwise, it will be βfire and forgetβ, and you absolutely cannot interact with Task .
Therefore, you must change the signature of SetIdentifier to return Task , for example:
public async Task SetIdentifier(string identifier) { await SetContentAsync(); DoSomething(); }
Then you can wait for the operation to complete in the test:
[Test] public async void Content_WhenModifierIsXXX_ReturnsSomeViewModel() { var viewModel = new EditorViewModel(); await viewModel.SetIdentifier("XXX"); Assert.That(viewModel.Content, Is.InstanceOf<ISomeContentViewModel>()); }
Or, if your test runner does not support async :
[Test] public void Content_WhenModifierIsXXX_ReturnsSomeViewModel() { var viewModel = new EditorViewModel(); viewModel.SetIdentifier("XXX").Wait(); Assert.That(viewModel.Content, Is.InstanceOf<ISomeContentViewModel>()); }
source share