I have a method that looks like this:
private async void DoStuff(long idToLookUp) { IOrder order = await orderService.LookUpIdAsync(idToLookUp);
I am trying to execute unit test like this:
[TestMethod] public void TestDoStuff() { //+ Arrange myViewModel.IsSearchShowing = true; // container is my Unity container and it setup in the init method. container.Resolve<IOrderService>().Returns(orderService); orderService = Substitute.For<IOrderService>(); orderService.LookUpIdAsync(Arg.Any<long>()) .Returns(new Task<IOrder>(() => null)); //+ Act myViewModel.DoLookupCommand.Execute(0); //+ Assert myViewModel.IsSearchShowing.Should().BeFalse(); }
My statement is called before I finish with the mocked LookUpIdAsync. In my normal code, this is what I want. But for my unit test, I don't want this.
I am switching to Async / Await using BackgroundWorker. This worked correctly with the background worker, because I could wait for BackgroundWorker to complete.
But there seems to be no way to wait for the async void method ...
How can I unit test use this method?
Vaccano Jan 07 '13 at 22:57 2013-01-07 22:57
source share